fix(bitbucket): release notes heading link ()

Signed-off-by: Adam Setch <adam.setch@outlook.com>
pull/32744/head 39.31.2
Adam Setch 2024-11-26 05:22:51 -05:00 committed by GitHub
parent 5fd720a022
commit 9cbf83a798
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 89 additions and 2 deletions
lib/workers/repository/update/pr/changelog

View File

@ -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<ChangeLogProject>({
type: 'bitbucket',
apiBaseUrl: 'https://api.bitbucket.org/',
baseUrl: 'https://bitbucket.org/',
});
const githubProject = partial<ChangeLogProject>({
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<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')

View File

@ -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';
}
}