Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bitbucket): release notes heading link #32693

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@
{ 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 @@
expect(res).toBeNull();
});

it('handled bitbucket link', async () => {
httpMock
.scope('https://api.bitbucket.org')
.get('/2.0/repositories/some-org/some-repo/src?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).toMatchSnapshot({

Check failure on line 1148 in lib/workers/repository/update/pr/changelog/release-notes.spec.ts

View workflow job for this annotation

GitHub Actions / test (11/16)

workers/repository/update/pr/changelog/release-notes › getReleaseNotesMd() › handled bitbucket link

expect(received).toMatchSnapshot(properties) Snapshot name: `workers/repository/update/pr/changelog/release-notes getReleaseNotesMd() handled bitbucket link 1` New snapshot was not written. The update flag must be explicitly passed to write a new snapshot. This is likely because this test is run in a continuous integration (CI) environment in which snapshots are not written by default. Received: { "body": "#### Bug Fixes - **input:** add `drop` event support for IE ([5dc076](https://github.com/angular/angular.js/commit/5dc07667de00c5e85fd69c5b7b7fe4fb5fd65a77)) - **ngMessages:** prevent memory leak from messages that are never attached ([9d058d](https://github.com/angular/angular.js/commit/9d058de04bb78694b83179e9b97bc40214eca01a), [#16389](https://github.com/angular/angular.js/issues/16389), [#16404](https://github.com/angular/angular.js/issues/16404), [#16406](https://github.com/angular/angular.js/issues/16406)) - **ngTransclude:** remove terminal: true ([1d826e](https://github.com/angular/angular.js/commit/1d826e2f1e941d14c3c56d7a0249f5796ba11f85), [#16411](https://github.com/angular/angular.js/issues/16411), [#16412](https://github.com/angular/angular.js/issues/16412)) - **$sanitize:** sanitize `xml:base` attributes ([b9ef65](https://github.com/angular/angular.js/commit/b9ef6585e10477fbbf912a971fe0b390bca692a6)) #### New Features - **currencyFilter:** trim whitespace around an empty currency symbol ([367390](https://github.com/angular/angular.js/commit/3673909896efb6ff47546caf7fc61549f193e043), [#15018](https://github.com/angular/angular.js/issues/15018), [#15085](https://github.com/angular/angular.js/issues/15085), [#15105](https://github.com/angular/angular.js/issues/15105)) ", "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", } at Object.<anonymous> (lib/workers/repository/update/pr/changelog/release-notes.spec.ts:1148:19)
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';
}
}
Loading