diff --git a/lib/workers/repository/update/pr/changelog/release-notes.spec.ts b/lib/workers/repository/update/pr/changelog/release-notes.spec.ts index bb55d243a1b84e..7bb3bd2ebb0c77 100644 --- a/lib/workers/repository/update/pr/changelog/release-notes.spec.ts +++ b/lib/workers/repository/update/pr/changelog/release-notes.spec.ts @@ -35,6 +35,46 @@ const yargsChangelogMd = Fixtures.get('yargs.md'); const adapterutilsChangelogMd = Fixtures.get('adapter-utils.md'); const gitterWebappChangelogMd = Fixtures.get('gitter-webapp.md'); +const bitbucketTreeResponse = { + values: [ + { + type: 'commit_directory', + path: 'lib', + commit: { + hash: '1234', + }, + }, + { + type: 'commit_file', + path: 'CHANGELOG', + commit: { + hash: 'cdef', + }, + }, + { + type: 'commit_file', + path: 'CHANGELOG.json', + commit: { + hash: 'defg', + }, + }, + { + type: 'commit_file', + path: 'CHANGELOG.md', + commit: { + hash: 'abcd', + }, + }, + { + type: 'commit_file', + path: 'RELEASE_NOTES.md', + commit: { + hash: 'asdf', + }, + }, + ], +}; + const githubTreeResponse = { tree: [ { path: 'lib', type: 'tree' }, @@ -53,6 +93,12 @@ const gitlabTreeResponse = [ { path: 'README.md', name: 'README.md', type: 'blob' }, ]; +const bitbucketProject = partial({ + type: 'bitbucket', + apiBaseUrl: 'https://api.bitbucket.org/', + baseUrl: 'https://bitbucket.org/', +}); + const githubProject = partial({ type: 'github', apiBaseUrl: 'https://api.github.com/', @@ -1081,6 +1127,31 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { expect(res).toBeNull(); }); + it('handles bitbucket release notes link', async () => { + httpMock + .scope('https://api.bitbucket.org') + .get('/2.0/repositories/some-org/some-repo/src/HEAD?pagelen=100') + .reply(200, bitbucketTreeResponse) + .get('/2.0/repositories/some-org/some-repo/src/abcd/CHANGELOG.md') + .reply(200, angularJsChangelogMd); + + const res = await getReleaseNotesMd( + { + ...bitbucketProject, + repository: 'some-org/some-repo', + }, + partial({ + version: '1.6.9', + gitRef: '1.6.9', + }), + ); + expect(res).toMatchObject({ + notesSourceUrl: + 'https://bitbucket.org/some-org/some-repo/src/HEAD/CHANGELOG.md', + url: 'https://bitbucket.org/some-org/some-repo/src/HEAD/CHANGELOG.md#169-fiery-basilisk-2018-02-02', + }); + }); + it('parses angular.js', async () => { httpMock .scope('https://api.github.com') diff --git a/lib/workers/repository/update/pr/changelog/release-notes.ts b/lib/workers/repository/update/pr/changelog/release-notes.ts index 0fc00710fa3482..32aebe599c5a42 100644 --- a/lib/workers/repository/update/pr/changelog/release-notes.ts +++ b/lib/workers/repository/update/pr/changelog/release-notes.ts @@ -9,7 +9,7 @@ import { detectPlatform } from '../../../../../util/common'; import { linkify } from '../../../../../util/markdown'; import { newlineRegex, regEx } from '../../../../../util/regex'; import { coerceString } from '../../../../../util/string'; -import { isHttpUrl } from '../../../../../util/url'; +import { isHttpUrl, joinUrlParts } from '../../../../../util/url'; import type { BranchUpgradeConfig } from '../../../../types'; import * as bitbucket from './bitbucket'; import * as gitea from './gitea'; @@ -18,6 +18,7 @@ import * as gitlab from './gitlab'; import type { ChangeLogFile, ChangeLogNotes, + ChangeLogPlatform, ChangeLogProject, ChangeLogRelease, ChangeLogResult, @@ -359,7 +360,13 @@ export async function getReleaseNotesMd( if (word.includes(version) && !isHttpUrl(word)) { logger.trace({ body }, 'Found release notes for v' + version); // TODO: fix url - const notesSourceUrl = `${baseUrl}${repository}/blob/HEAD/${changelogFile}`; + const notesSourceUrl = joinUrlParts( + baseUrl, + repository, + getSourceRootPath(project.type), + 'HEAD', + changelogFile, + ); const mdHeadingLink = title .filter((word) => !isHttpUrl(word)) .join('-') @@ -479,3 +486,12 @@ export async function addReleaseNotes( export function shouldSkipChangelogMd(repository: string): boolean { return repositoriesToSkipMdFetching.includes(repository); } + +function getSourceRootPath(type: ChangeLogPlatform): string { + switch (type) { + case 'bitbucket': + return 'src'; + default: + return 'blob'; + } +}