Skip to content

Commit

Permalink
fix(changelog): remove urls from md heading url (#23112)
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed Jul 3, 2023
1 parent 5db88aa commit 8b819dd
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/util/__fixtures__/release-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

#### New Contributors
* @​user made their first contribution in https://github.com/foo/foo/pull/2

#### [Heading With Markdown Link](https://github.com/foo/foo/blob/HEAD/CHANGELOG.md#1234-2023-07-03)
6 changes: 5 additions & 1 deletion lib/util/markdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('util/markdown', () => {
* Issue or PR (fork): foo#1
* Issue or PR (project): remarkjs/remark#1
* Mention: @wooorm
* Changelog heading with link: [v2.23.1](https://github.com/bootstrap-vue/bootstrap-vue/blob/HEAD/CHANGELOG.md#2231-2022-10-26)
`;

const after =
Expand All @@ -29,6 +30,7 @@ describe('util/markdown', () => {
- Issue or PR (fork): [foo#1](https://github.com/foo/repo/issues/1)
- Issue or PR (project): [remarkjs/remark#1](https://github.com/remarkjs/remark/issues/1)
- Mention: [@wooorm](https://github.com/wooorm)
- Changelog heading with link: [v2.23.1](https://github.com/bootstrap-vue/bootstrap-vue/blob/HEAD/CHANGELOG.md#2231-2022-10-26)
` + '\n';

it('works', async () => {
Expand All @@ -50,7 +52,9 @@ describe('util/markdown', () => {
'* pnpm rebuild accepts --store-dir by @user in https://github.com/foo/foo/pull/1\n' +
'\n' +
'#### New Contributors\n' +
'* @user made their first contribution in https://github.com/foo/foo/pull/2\n';
'* @user made their first contribution in https://github.com/foo/foo/pull/2\n' +
'#### [Heading With Markdown Link](https://github.com/foo/foo/blob/HEAD/CHANGELOG.md#1234-2023-07-03)' +
'\n';

const expected = Fixtures.get('release-notes.txt');
expect(sanitizeMarkdown(input)).toEqual(expected);
Expand Down
2 changes: 1 addition & 1 deletion lib/util/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { regEx } from './regex';
export function sanitizeMarkdown(markdown: string): string {
let res = markdown;
// Put a zero width space after every # followed by a digit
res = res.replace(regEx(/#(\d)/gi), '#​$1');
res = res.replace(regEx(/\W#(\d)/gi), '#​$1');
// Put a zero width space after every @ symbol to prevent unintended hyperlinking
res = res.replace(regEx(/@/g), '@​');
res = res.replace(regEx(/(`\[?@)​/g), '$1');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ exports[`workers/repository/update/pr/changelog/release-notes getReleaseNotesMd(
- **yargs:** correct support of bundled electron apps ([#1554](https://www.github.com/yargs/yargs/issues/1554)) ([a0b61ac](https://www.github.com/yargs/yargs/commit/a0b61ac21e2b554aa73dbf1a66d4a7af94047c2f))
",
"notesSourceUrl": "https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md",
"url": "https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1520-httpswwwgithubcomyargsyargscomparev1510v1520-2020-03-01",
"url": "https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1520-2020-03-01",
}
`;
Expand All @@ -73,7 +73,7 @@ exports[`workers/repository/update/pr/changelog/release-notes getReleaseNotesMd(
- address ambiguity between nargs of 1 and requiresArg ([#1572](https://www.github.com/yargs/yargs/issues/1572)) ([a5edc32](https://www.github.com/yargs/yargs/commit/a5edc328ecb3f90d1ba09cfe70a0040f68adf50a))
",
"notesSourceUrl": "https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md",
"url": "https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1530-httpswwwgithubcomyargsyargscomparev1520v1530-2020-03-08",
"url": "https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1530-2020-03-08",
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => {
expect(res).toMatchSnapshot({
notesSourceUrl:
'https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md',
url: 'https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1530-httpswwwgithubcomyargsyargscomparev1520v1530-2020-03-08',
url: 'https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1530-2020-03-08',
});
});

Expand Down Expand Up @@ -1270,7 +1270,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => {
expect(res).toMatchSnapshot({
notesSourceUrl:
'https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md',
url: 'https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1520-httpswwwgithubcomyargsyargscomparev1510v1520-2020-03-01',
url: 'https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1520-2020-03-01',
});
});

Expand Down
9 changes: 5 additions & 4 deletions lib/workers/repository/update/pr/changelog/release-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,11 @@ export async function getReleaseNotesMd(
logger.trace({ body }, 'Found release notes for v' + version);
// TODO: fix url
const notesSourceUrl = `${baseUrl}${repository}/blob/HEAD/${changelogFile}`;
const url =
notesSourceUrl +
'#' +
title.join('-').replace(regEx(/[^A-Za-z0-9-]/g), '');
const mdHeadingLink = title
.filter((word) => !isUrl(word))
.join('-')
.replace(regEx(/[^A-Za-z0-9-]/g), '');
const url = `${notesSourceUrl}#${mdHeadingLink}`;
body = massageBody(body, baseUrl);
if (body?.length) {
try {
Expand Down

0 comments on commit 8b819dd

Please sign in to comment.