Skip to content

Commit

Permalink
fix(workers/pr): wrong links to changelog when master branch doesn't …
Browse files Browse the repository at this point in the history
…exist (#12937)


Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
olegkrivtsov and rarkins committed Dec 12, 2021
1 parent 4ea9ed2 commit b14e9fa
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 52 deletions.
32 changes: 16 additions & 16 deletions lib/workers/pr/changelog/__snapshots__/index.spec.ts.snap
Expand Up @@ -247,7 +247,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/master",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -280,7 +280,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/master",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -313,7 +313,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/master",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -346,7 +346,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/master",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -450,7 +450,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/master",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -483,7 +483,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/master",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -516,7 +516,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/master",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -549,7 +549,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/master",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -653,7 +653,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/master",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -686,7 +686,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/master",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -719,7 +719,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/master",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -752,7 +752,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/master",
"url": "https://github-enterprise.example.com/api/v3/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -916,7 +916,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/master",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -949,7 +949,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/master",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -982,7 +982,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/master",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -1015,7 +1015,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/master",
"url": "https://api.github.com/repos/chalk/chalk/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down
54 changes: 27 additions & 27 deletions lib/workers/pr/changelog/__snapshots__/release-notes.spec.ts.snap
Expand Up @@ -404,8 +404,8 @@ See merge request itentialopensource/adapter-utils!177
***
",
"notesSourceUrl": "https://gitlab.com/itentialopensource/adapter-utils/blob/master/packages/foo/CHANGELOG.md",
"url": "https://gitlab.com/itentialopensource/adapter-utils/blob/master/packages/foo/CHANGELOG.md#4330-05-15-2020",
"notesSourceUrl": "https://gitlab.com/itentialopensource/adapter-utils/blob/HEAD/packages/foo/CHANGELOG.md",
"url": "https://gitlab.com/itentialopensource/adapter-utils/blob/HEAD/packages/foo/CHANGELOG.md#4330-05-15-2020",
}
`;

Expand Down Expand Up @@ -443,8 +443,8 @@ See merge request itentialopensource/adapter-utils!177
***
",
"notesSourceUrl": "https://gitlab.com/itentialopensource/adapter-utils/blob/master/CHANGELOG.md",
"url": "https://gitlab.com/itentialopensource/adapter-utils/blob/master/CHANGELOG.md#4330-05-15-2020",
"notesSourceUrl": "https://gitlab.com/itentialopensource/adapter-utils/blob/HEAD/CHANGELOG.md",
"url": "https://gitlab.com/itentialopensource/adapter-utils/blob/HEAD/CHANGELOG.md#4330-05-15-2020",
}
`;

Expand Down Expand Up @@ -509,8 +509,8 @@ Object {
- **translations:** fix pluralization in error messages. ([#1557](https://www.github.com/yargs/yargs/issues/1557)) ([94fa38c](https://www.github.com/yargs/yargs/commit/94fa38cbab8d86943e87bf41d368ed56dffa6835))
- **yargs:** correct support of bundled electron apps ([#1554](https://www.github.com/yargs/yargs/issues/1554)) ([a0b61ac](https://www.github.com/yargs/yargs/commit/a0b61ac21e2b554aa73dbf1a66d4a7af94047c2f))
",
"notesSourceUrl": "https://github.com/yargs/yargs/blob/master/CHANGELOG.md",
"url": "https://github.com/yargs/yargs/blob/master/CHANGELOG.md#1520-httpswwwgithubcomyargsyargscomparev1510v1520-2020-03-01",
"notesSourceUrl": "https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md",
"url": "https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1520-httpswwwgithubcomyargsyargscomparev1510v1520-2020-03-01",
}
`;
Expand Down Expand Up @@ -560,8 +560,8 @@ Object {
- address ambiguity between nargs of 1 and requiresArg ([#1572](https://www.github.com/yargs/yargs/issues/1572)) ([a5edc32](https://www.github.com/yargs/yargs/commit/a5edc328ecb3f90d1ba09cfe70a0040f68adf50a))
",
"notesSourceUrl": "https://github.com/yargs/yargs/blob/master/CHANGELOG.md",
"url": "https://github.com/yargs/yargs/blob/master/CHANGELOG.md#1530-httpswwwgithubcomyargsyargscomparev1520v1530-2020-03-08",
"notesSourceUrl": "https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md",
"url": "https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1530-httpswwwgithubcomyargsyargscomparev1520v1530-2020-03-08",
}
`;
Expand All @@ -585,7 +585,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/some/repository2/git/trees/master",
"url": "https://api.github.com/repos/some/repository2/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -620,7 +620,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/chalk/git/trees/master",
"url": "https://api.github.com/repos/chalk/git/trees/HEAD",
},
]
`;
Expand All @@ -645,7 +645,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/nodeca/js-yaml/git/trees/master?recursive=1",
"url": "https://api.github.com/repos/nodeca/js-yaml/git/trees/HEAD?recursive=1",
},
Object {
"headers": Object {
Expand All @@ -665,8 +665,8 @@ Object {
"body": "- Fix \`condenseFlow\` output (quote keys for sure, instead of spaces), [#371](https://github.com/nodeca/js-yaml/issues/371), [#370](https://github.com/nodeca/js-yaml/issues/370).
- Dump astrals as codepoints instead of surrogate pair, [#368](https://github.com/nodeca/js-yaml/issues/368).
",
"notesSourceUrl": "https://github.com/nodeca/js-yaml/blob/master/packages/foo/CHANGELOG.md",
"url": "https://github.com/nodeca/js-yaml/blob/master/packages/foo/CHANGELOG.md#3100--2017-09-10",
"notesSourceUrl": "https://github.com/nodeca/js-yaml/blob/HEAD/packages/foo/CHANGELOG.md",
"url": "https://github.com/nodeca/js-yaml/blob/HEAD/packages/foo/CHANGELOG.md#3100--2017-09-10",
}
`;
Expand All @@ -690,7 +690,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/some/repository1/git/trees/master",
"url": "https://api.github.com/repos/some/repository1/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -731,8 +731,8 @@ Object {
[#15085](https://github.com/angular/angular.js/issues/15085),
[#15105](https://github.com/angular/angular.js/issues/15105))
",
"notesSourceUrl": "https://github.com/angular/angular.js/blob/master/CHANGELOG.md",
"url": "https://github.com/angular/angular.js/blob/master/CHANGELOG.md#169-fiery-basilisk-2018-02-02",
"notesSourceUrl": "https://github.com/angular/angular.js/blob/HEAD/CHANGELOG.md",
"url": "https://github.com/angular/angular.js/blob/HEAD/CHANGELOG.md#169-fiery-basilisk-2018-02-02",
}
`;
Expand All @@ -756,7 +756,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/angular/angular.js/git/trees/master",
"url": "https://api.github.com/repos/angular/angular.js/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -807,8 +807,8 @@ Object {
- Update Polish translation, <https://gitlab.com/gitlab-org/gitter/webapp/-/merge_requests/1882>
- Thanks to [@biesiad](https://gitlab.com/biesiad) for the contribution
",
"notesSourceUrl": "https://gitlab.com/gitlab-org/gitter/webapp/blob/master/CHANGELOG.md",
"url": "https://gitlab.com/gitlab-org/gitter/webapp/blob/master/CHANGELOG.md#20260---2020-05-18",
"notesSourceUrl": "https://gitlab.com/gitlab-org/gitter/webapp/blob/HEAD/CHANGELOG.md",
"url": "https://gitlab.com/gitlab-org/gitter/webapp/blob/HEAD/CHANGELOG.md#20260---2020-05-18",
}
`;
Expand All @@ -832,7 +832,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/facebook/jest/git/trees/master",
"url": "https://api.github.com/repos/facebook/jest/git/trees/HEAD",
},
Object {
"headers": Object {
Expand Down Expand Up @@ -1035,8 +1035,8 @@ Object {
- \`[docs]\` Update \`expect.anything()\` sample code
([#5007](https://github.com/facebook/jest/pull/5007))
",
"notesSourceUrl": "https://github.com/facebook/jest/blob/master/CHANGELOG.md",
"url": "https://github.com/facebook/jest/blob/master/CHANGELOG.md#jest-2200",
"notesSourceUrl": "https://github.com/facebook/jest/blob/HEAD/CHANGELOG.md",
"url": "https://github.com/facebook/jest/blob/HEAD/CHANGELOG.md#jest-2200",
}
`;
Expand All @@ -1060,7 +1060,7 @@ Array [
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://api.github.com/repos/nodeca/js-yaml/git/trees/master",
"url": "https://api.github.com/repos/nodeca/js-yaml/git/trees/HEAD",
},
Object {
"headers": Object {
Expand All @@ -1080,8 +1080,8 @@ Object {
"body": "- Fix \`condenseFlow\` output (quote keys for sure, instead of spaces), [#371](https://github.com/nodeca/js-yaml/issues/371), [#370](https://github.com/nodeca/js-yaml/issues/370).
- Dump astrals as codepoints instead of surrogate pair, [#368](https://github.com/nodeca/js-yaml/issues/368).
",
"notesSourceUrl": "https://github.com/nodeca/js-yaml/blob/master/CHANGELOG.md",
"url": "https://github.com/nodeca/js-yaml/blob/master/CHANGELOG.md#3100--2017-09-10",
"notesSourceUrl": "https://github.com/nodeca/js-yaml/blob/HEAD/CHANGELOG.md",
"url": "https://github.com/nodeca/js-yaml/blob/HEAD/CHANGELOG.md#3100--2017-09-10",
}
`;
Expand Down Expand Up @@ -1123,7 +1123,7 @@ Object {
- Update Polish translation, <https://gitlab.com/gitlab-org/gitter/webapp/-/merge_requests/1882>
- Thanks to [@biesiad](https://gitlab.com/biesiad) for the contribution
",
"notesSourceUrl": "https://my.custom.domain/gitlab-org/gitter/webapp/blob/master/CHANGELOG.md",
"url": "https://my.custom.domain/gitlab-org/gitter/webapp/blob/master/CHANGELOG.md#20260---2020-05-18",
"notesSourceUrl": "https://my.custom.domain/gitlab-org/gitter/webapp/blob/HEAD/CHANGELOG.md",
"url": "https://my.custom.domain/gitlab-org/gitter/webapp/blob/HEAD/CHANGELOG.md#20260---2020-05-18",
}
`;
2 changes: 1 addition & 1 deletion lib/workers/pr/changelog/github/index.ts
Expand Up @@ -52,7 +52,7 @@ export async function getReleaseNotesMd(
): Promise<ChangeLogFile> | null {
logger.trace('github.getReleaseNotesMd()');
const apiPrefix = `${ensureTrailingSlash(apiBaseUrl)}repos/${repository}`;
const { default_branch: defaultBranch = 'master' } = (
const { default_branch: defaultBranch = 'HEAD' } = (
await http.getJson<{ default_branch: string }>(apiPrefix)
).body;

Expand Down
14 changes: 7 additions & 7 deletions lib/workers/pr/changelog/release-notes.spec.ts
Expand Up @@ -304,7 +304,7 @@ describe('workers/pr/changelog/release-notes', () => {
.scope('https://api.github.com')
.get('/repos/chalk')
.reply(200)
.get('/repos/chalk/git/trees/master')
.get('/repos/chalk/git/trees/HEAD')
.reply(200, {
tree: [
{ name: 'lib', type: 'tree' },
Expand All @@ -327,7 +327,7 @@ describe('workers/pr/changelog/release-notes', () => {
.scope('https://api.github.com')
.get('/repos/some/repository1')
.reply(200)
.get('/repos/some/repository1/git/trees/master')
.get('/repos/some/repository1/git/trees/HEAD')
.reply(200, githubTreeResponse)
.get('/repos/some/repository1/git/blobs/abcd')
.reply(200, {
Expand All @@ -349,7 +349,7 @@ describe('workers/pr/changelog/release-notes', () => {
.scope('https://api.github.com')
.get('/repos/some/repository2')
.reply(200)
.get('/repos/some/repository2/git/trees/master')
.get('/repos/some/repository2/git/trees/HEAD')
.reply(200, githubTreeResponse)
.get('/repos/some/repository2/git/blobs/abcd')
.reply(200, {
Expand All @@ -371,7 +371,7 @@ describe('workers/pr/changelog/release-notes', () => {
.scope('https://api.github.com')
.get('/repos/angular/angular.js')
.reply(200)
.get('/repos/angular/angular.js/git/trees/master')
.get('/repos/angular/angular.js/git/trees/HEAD')
.reply(200, githubTreeResponse)
.get('/repos/angular/angular.js/git/blobs/abcd')
.reply(200, {
Expand Down Expand Up @@ -445,7 +445,7 @@ describe('workers/pr/changelog/release-notes', () => {
.scope('https://api.github.com')
.get('/repos/facebook/jest')
.reply(200)
.get('/repos/facebook/jest/git/trees/master')
.get('/repos/facebook/jest/git/trees/HEAD')
.reply(200, githubTreeResponse)
.get('/repos/facebook/jest/git/blobs/abcd')
.reply(200, {
Expand Down Expand Up @@ -474,7 +474,7 @@ describe('workers/pr/changelog/release-notes', () => {
.scope('https://api.github.com')
.get('/repos/nodeca/js-yaml')
.reply(200)
.get('/repos/nodeca/js-yaml/git/trees/master?recursive=1')
.get('/repos/nodeca/js-yaml/git/trees/HEAD?recursive=1')
.reply(200, subdirTree)
.get('/repos/nodeca/js-yaml/git/blobs/abcd')
.reply(200, {
Expand All @@ -499,7 +499,7 @@ describe('workers/pr/changelog/release-notes', () => {
.scope('https://api.github.com')
.get('/repos/nodeca/js-yaml')
.reply(200)
.get('/repos/nodeca/js-yaml/git/trees/master')
.get('/repos/nodeca/js-yaml/git/trees/HEAD')
.reply(200, githubTreeResponse)
.get('/repos/nodeca/js-yaml/git/blobs/abcd')
.reply(200, {
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/pr/changelog/release-notes.ts
Expand Up @@ -260,7 +260,7 @@ export async function getReleaseNotesMd(
if (word.includes(version) && !isUrl(word)) {
logger.trace({ body }, 'Found release notes for v' + version);
// TODO: fix url
const notesSourceUrl = `${baseUrl}${repository}/blob/master/${changelogFile}`;
const notesSourceUrl = `${baseUrl}${repository}/blob/HEAD/${changelogFile}`;
const url =
notesSourceUrl +
'#' +
Expand Down

0 comments on commit b14e9fa

Please sign in to comment.