Skip to content
Snippets Groups Projects
Unverified Commit 12341691 authored by Adam Setch's avatar Adam Setch Committed by GitHub
Browse files

feat(bitbucket): support fetching changelogs with source directory (#32691)

parent e5655a80
No related branches found
No related tags found
No related merge requests found
...@@ -79,7 +79,7 @@ describe('workers/repository/update/pr/changelog/bitbucket/index', () => { ...@@ -79,7 +79,7 @@ describe('workers/repository/update/pr/changelog/bitbucket/index', () => {
it('handles release notes', async () => { it('handles release notes', async () => {
httpMock httpMock
.scope(apiBaseUrl) .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) .reply(200, bitbucketTreeResponse)
.get('/2.0/repositories/some-org/some-repo/src/abcd/CHANGELOG.md') .get('/2.0/repositories/some-org/some-repo/src/abcd/CHANGELOG.md')
.reply(200, changelogMd); .reply(200, changelogMd);
...@@ -94,7 +94,7 @@ describe('workers/repository/update/pr/changelog/bitbucket/index', () => { ...@@ -94,7 +94,7 @@ describe('workers/repository/update/pr/changelog/bitbucket/index', () => {
it('handles missing release notes', async () => { it('handles missing release notes', async () => {
httpMock httpMock
.scope(apiBaseUrl) .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); .reply(200, bitbucketTreeResponseNoChangelogFiles);
const res = await getReleaseNotesMdFile(bitbucketProject); const res = await getReleaseNotesMdFile(bitbucketProject);
expect(res).toBeNull(); expect(res).toBeNull();
......
import path from 'node:path';
import is from '@sindresorhus/is'; import is from '@sindresorhus/is';
import changelogFilenameRegex from 'changelog-filename-regex'; import changelogFilenameRegex from 'changelog-filename-regex';
import { logger } from '../../../../../../logger'; import { logger } from '../../../../../../logger';
...@@ -18,15 +19,16 @@ const bitbucketHttp = new BitbucketHttp(id); ...@@ -18,15 +19,16 @@ const bitbucketHttp = new BitbucketHttp(id);
export async function getReleaseNotesMd( export async function getReleaseNotesMd(
repository: string, repository: string,
apiBaseUrl: string, apiBaseUrl: string,
_sourceDirectory?: string, sourceDirectory?: string,
): Promise<ChangeLogFile | null> { ): Promise<ChangeLogFile | null> {
logger.trace('bitbucket.getReleaseNotesMd()'); logger.trace('bitbucket.getReleaseNotesMd()');
const repositorySourceURl = joinUrlParts( const repositorySourceURl = joinUrlParts(
apiBaseUrl, apiBaseUrl,
`2.0/repositories`, '2.0/repositories',
repository, repository,
'src', 'src/HEAD',
sourceDirectory ?? '',
); );
const rootFiles = ( const rootFiles = (
...@@ -41,7 +43,9 @@ export async function getReleaseNotesMd( ...@@ -41,7 +43,9 @@ export async function getReleaseNotesMd(
const allFiles = rootFiles.filter((f) => f.type === 'commit_file'); 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 const changelogFile = files
.sort((a, b) => compareChangelogFilePath(a.path, b.path)) .sort((a, b) => compareChangelogFilePath(a.path, b.path))
...@@ -59,7 +63,10 @@ export async function getReleaseNotesMd( ...@@ -59,7 +63,10 @@ export async function getReleaseNotesMd(
const fileRes = await bitbucketHttp.get( const fileRes = await bitbucketHttp.get(
joinUrlParts( joinUrlParts(
repositorySourceURl, apiBaseUrl,
'2.0/repositories',
repository,
'src',
changelogFile.commit.hash, changelogFile.commit.hash,
changelogFile.path, changelogFile.path,
), ),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment