Skip to content

Commit

Permalink
fix(bitbucket): release notes heading link (#32693)
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Setch <[email protected]>
  • Loading branch information
setchy authored Nov 26, 2024
1 parent 5fd720a commit 9cbf83a
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
71 changes: 71 additions & 0 deletions lib/workers/repository/update/pr/changelog/release-notes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -53,6 +93,12 @@ const gitlabTreeResponse = [
{ path: 'README.md', name: 'README.md', type: 'blob' },
];

const bitbucketProject = partial<ChangeLogProject>({
type: 'bitbucket',
apiBaseUrl: 'https://api.bitbucket.org/',
baseUrl: 'https://bitbucket.org/',
});

const githubProject = partial<ChangeLogProject>({
type: 'github',
apiBaseUrl: 'https://api.github.com/',
Expand Down Expand Up @@ -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<ChangeLogRelease>({
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')
Expand Down
20 changes: 18 additions & 2 deletions lib/workers/repository/update/pr/changelog/release-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -18,6 +18,7 @@ import * as gitlab from './gitlab';
import type {
ChangeLogFile,
ChangeLogNotes,
ChangeLogPlatform,
ChangeLogProject,
ChangeLogRelease,
ChangeLogResult,
Expand Down Expand Up @@ -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('-')
Expand Down Expand Up @@ -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';
}
}

0 comments on commit 9cbf83a

Please sign in to comment.