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

fix(changelog): remove urls from md heading url (#23112)

parent 5db88aad
Branches
No related tags found
No related merge requests found
...@@ -13,3 +13,5 @@ ...@@ -13,3 +13,5 @@
#### New Contributors #### New Contributors
* @​user made their first contribution in https://github.com/foo/foo/pull/2 * @​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)
...@@ -15,6 +15,7 @@ describe('util/markdown', () => { ...@@ -15,6 +15,7 @@ describe('util/markdown', () => {
* Issue or PR (fork): foo#1 * Issue or PR (fork): foo#1
* Issue or PR (project): remarkjs/remark#1 * Issue or PR (project): remarkjs/remark#1
* Mention: @wooorm * 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 = const after =
...@@ -29,6 +30,7 @@ describe('util/markdown', () => { ...@@ -29,6 +30,7 @@ describe('util/markdown', () => {
- Issue or PR (fork): [foo#1](https://github.com/foo/repo/issues/1) - 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) - Issue or PR (project): [remarkjs/remark#1](https://github.com/remarkjs/remark/issues/1)
- Mention: [@wooorm](https://github.com/wooorm) - 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'; ` + '\n';
it('works', async () => { it('works', async () => {
...@@ -50,7 +52,9 @@ describe('util/markdown', () => { ...@@ -50,7 +52,9 @@ describe('util/markdown', () => {
'* pnpm rebuild accepts --store-dir by @user in https://github.com/foo/foo/pull/1\n' + '* pnpm rebuild accepts --store-dir by @user in https://github.com/foo/foo/pull/1\n' +
'\n' + '\n' +
'#### New Contributors\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'); const expected = Fixtures.get('release-notes.txt');
expect(sanitizeMarkdown(input)).toEqual(expected); expect(sanitizeMarkdown(input)).toEqual(expected);
......
...@@ -6,7 +6,7 @@ import { regEx } from './regex'; ...@@ -6,7 +6,7 @@ import { regEx } from './regex';
export function sanitizeMarkdown(markdown: string): string { export function sanitizeMarkdown(markdown: string): string {
let res = markdown; let res = markdown;
// Put a zero width space after every # followed by a digit // 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 // Put a zero width space after every @ symbol to prevent unintended hyperlinking
res = res.replace(regEx(/@/g), '@​'); res = res.replace(regEx(/@/g), '@​');
res = res.replace(regEx(/(`\[?@)​/g), '$1'); res = res.replace(regEx(/(`\[?@)​/g), '$1');
......
...@@ -57,7 +57,7 @@ exports[`workers/repository/update/pr/changelog/release-notes getReleaseNotesMd( ...@@ -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)) - **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", "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",
} }
`; `;
...@@ -73,7 +73,7 @@ exports[`workers/repository/update/pr/changelog/release-notes getReleaseNotesMd( ...@@ -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)) - 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", "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",
} }
`; `;
......
...@@ -1240,7 +1240,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...@@ -1240,7 +1240,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => {
expect(res).toMatchSnapshot({ expect(res).toMatchSnapshot({
notesSourceUrl: notesSourceUrl:
'https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md', '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',
}); });
}); });
...@@ -1270,7 +1270,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...@@ -1270,7 +1270,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => {
expect(res).toMatchSnapshot({ expect(res).toMatchSnapshot({
notesSourceUrl: notesSourceUrl:
'https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md', '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',
}); });
}); });
......
...@@ -349,10 +349,11 @@ export async function getReleaseNotesMd( ...@@ -349,10 +349,11 @@ export async function getReleaseNotesMd(
logger.trace({ body }, 'Found release notes for v' + version); logger.trace({ body }, 'Found release notes for v' + version);
// TODO: fix url // TODO: fix url
const notesSourceUrl = `${baseUrl}${repository}/blob/HEAD/${changelogFile}`; const notesSourceUrl = `${baseUrl}${repository}/blob/HEAD/${changelogFile}`;
const url = const mdHeadingLink = title
notesSourceUrl + .filter((word) => !isUrl(word))
'#' + .join('-')
title.join('-').replace(regEx(/[^A-Za-z0-9-]/g), ''); .replace(regEx(/[^A-Za-z0-9-]/g), '');
const url = `${notesSourceUrl}#${mdHeadingLink}`;
body = massageBody(body, baseUrl); body = massageBody(body, baseUrl);
if (body?.length) { if (body?.length) {
try { try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment