diff --git a/lib/workers/repository/update/pr/changelog/bitbucket/index.spec.ts b/lib/workers/repository/update/pr/changelog/bitbucket/index.spec.ts index f4a9c45f556b5d..4eb26101e06c61 100644 --- a/lib/workers/repository/update/pr/changelog/bitbucket/index.spec.ts +++ b/lib/workers/repository/update/pr/changelog/bitbucket/index.spec.ts @@ -79,7 +79,7 @@ describe('workers/repository/update/pr/changelog/bitbucket/index', () => { it('handles release notes', async () => { httpMock .scope(apiBaseUrl) - .get('/2.0/repositories/some-org/some-repo/src?pagelen=100') + .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, changelogMd); @@ -94,7 +94,7 @@ describe('workers/repository/update/pr/changelog/bitbucket/index', () => { it('handles missing release notes', async () => { httpMock .scope(apiBaseUrl) - .get('/2.0/repositories/some-org/some-repo/src?pagelen=100') + .get('/2.0/repositories/some-org/some-repo/src/HEAD?pagelen=100') .reply(200, bitbucketTreeResponseNoChangelogFiles); const res = await getReleaseNotesMdFile(bitbucketProject); expect(res).toBeNull(); diff --git a/lib/workers/repository/update/pr/changelog/bitbucket/index.ts b/lib/workers/repository/update/pr/changelog/bitbucket/index.ts index 56ddb2b0ac6f66..3f0ca2cce7a7ab 100644 --- a/lib/workers/repository/update/pr/changelog/bitbucket/index.ts +++ b/lib/workers/repository/update/pr/changelog/bitbucket/index.ts @@ -1,3 +1,4 @@ +import path from 'node:path'; import is from '@sindresorhus/is'; import changelogFilenameRegex from 'changelog-filename-regex'; import { logger } from '../../../../../../logger'; @@ -18,15 +19,16 @@ const bitbucketHttp = new BitbucketHttp(id); export async function getReleaseNotesMd( repository: string, apiBaseUrl: string, - _sourceDirectory?: string, + sourceDirectory?: string, ): Promise { logger.trace('bitbucket.getReleaseNotesMd()'); const repositorySourceURl = joinUrlParts( apiBaseUrl, - `2.0/repositories`, + '2.0/repositories', repository, - 'src', + 'src/HEAD', + sourceDirectory ?? '', ); const rootFiles = ( @@ -41,7 +43,9 @@ export async function getReleaseNotesMd( const allFiles = rootFiles.filter((f) => f.type === 'commit_file'); - const files = allFiles.filter((f) => changelogFilenameRegex.test(f.path)); + const files = allFiles.filter((f) => + changelogFilenameRegex.test(path.basename(f.path)), + ); const changelogFile = files .sort((a, b) => compareChangelogFilePath(a.path, b.path)) @@ -59,7 +63,10 @@ export async function getReleaseNotesMd( const fileRes = await bitbucketHttp.get( joinUrlParts( - repositorySourceURl, + apiBaseUrl, + '2.0/repositories', + repository, + 'src', changelogFile.commit.hash, changelogFile.path, ),