Skip to content

Commit

Permalink
feat(bitbucket): support fetching changelogs with source directory (#…
Browse files Browse the repository at this point in the history
…32691)

Signed-off-by: Adam Setch <adam.setch@outlook.com>
  • Loading branch information
setchy authored Nov 24, 2024
1 parent e5655a8 commit 1234169
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
17 changes: 12 additions & 5 deletions lib/workers/repository/update/pr/changelog/bitbucket/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'node:path';
import is from '@sindresorhus/is';
import changelogFilenameRegex from 'changelog-filename-regex';
import { logger } from '../../../../../../logger';
Expand All @@ -18,15 +19,16 @@ const bitbucketHttp = new BitbucketHttp(id);
export async function getReleaseNotesMd(
repository: string,
apiBaseUrl: string,
_sourceDirectory?: string,
sourceDirectory?: string,
): Promise<ChangeLogFile | null> {
logger.trace('bitbucket.getReleaseNotesMd()');

const repositorySourceURl = joinUrlParts(
apiBaseUrl,
`2.0/repositories`,
'2.0/repositories',
repository,
'src',
'src/HEAD',
sourceDirectory ?? '',
);

const rootFiles = (
Expand All @@ -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))
Expand All @@ -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,
),
Expand Down

0 comments on commit 1234169

Please sign in to comment.