Skip to content

Commit

Permalink
refactor(github): use github.com (#31025)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed Aug 29, 2024
1 parent 36f66cf commit fbe4dba
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ exports[`modules/platform/github/index initRepo should update fork when using fo
}
`;

exports[`modules/platform/github/index massageMarkdown(input) returns updated pr body 1`] = `"[https://github.com/foo/bar/issues/5](https://togithub.com/foo/bar/issues/5) plus also [a link](https://togithub.com/foo/bar/issues/5)"`;
exports[`modules/platform/github/index massageMarkdown(input) returns updated pr body 1`] = `"[https://github.com/foo/bar/issues/5](https://redirect.github.com/foo/bar/issues/5) plus also [a link](https://redirect.github.com/foo/bar/issues/5)"`;
14 changes: 10 additions & 4 deletions lib/modules/platform/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1944,13 +1944,19 @@ export function massageMarkdown(input: string): string {
return smartTruncate(input, maxBodyLength());
}
const massagedInput = massageMarkdownLinks(input)
// to be safe, replace all github.com links with renovatebot redirector
// to be safe, replace all github.com links with github.com
.replace(
regEx(/href="https?:\/\/github.com\//g),
'href="https://github.com/',
'href="https://github.com/',
)
.replace(
regEx(/]\(https:\/\/github\.com\//g),
'](https://github.com/',
)
.replace(
regEx(/]: https:\/\/github\.com\//g),
']: https://github.com/',
)
.replace(regEx(/]\(https:\/\/github\.com\//g), '](https://github.com/')
.replace(regEx(/]: https:\/\/github\.com\//g), ']: https://github.com/')
.replace('> ℹ **Note**\n> \n', '> [!NOTE]\n')
.replace('> ⚠ **Warning**\n> \n', '> [!WARNING]\n')
.replace('> ⚠️ **Warning**\n> \n', '> [!WARNING]\n')
Expand Down
60 changes: 30 additions & 30 deletions lib/modules/platform/github/massage-markdown-links.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ describe('modules/platform/github/massage-markdown-links', () => {
const res = massageMarkdownLinks(input);
expect(res).toEqual(
[
'Link [foo/bar#1](https://togithub.com/foo/bar/pull/1) points to [https://github.com/foo/bar/pull/1](https://togithub.com/foo/bar/pull/1).',
'URL [https://github.com/foo/bar/pull/1](https://togithub.com/foo/bar/pull/1) becomes [foo/bar#1](https://togithub.com/foo/bar/pull/1).',
'Link [foo/bar#1](https://redirect.github.com/foo/bar/pull/1) points to [https://github.com/foo/bar/pull/1](https://redirect.github.com/foo/bar/pull/1).',
'URL [https://github.com/foo/bar/pull/1](https://redirect.github.com/foo/bar/pull/1) becomes [foo/bar#1](https://redirect.github.com/foo/bar/pull/1).',
].join('\n'),
);
});
Expand Down Expand Up @@ -45,10 +45,10 @@ describe('modules/platform/github/massage-markdown-links', () => {
${'https://github.com/foo/bar/issues/'}
${'https://github.com/foo/bar/pull/'}
${'api.github.com'}
${'togithub.com'}
${'www.togithub.com'}
${'https://togithub.com/foo/bar/releases/tag/v0.20.3'}
${'https://togithub.com/foo/bar/compare/v0.20.2...v0.20.3'}
${'redirect.github.com'}
${'www.redirect.github.com'}
${'https://redirect.github.com/foo/bar/releases/tag/v0.20.3'}
${'https://redirect.github.com/foo/bar/compare/v0.20.2...v0.20.3'}
`('Unchanged: $input', ({ input }: { input: string }) => {
const inputText = `Foo ${input}, bar.`;
expect(massageMarkdownLinks(inputText)).toEqual(inputText);
Expand All @@ -59,30 +59,30 @@ describe('modules/platform/github/massage-markdown-links', () => {

it.each`
input | output
${'github.com/foo/bar/discussions/1'} | ${'[github.com/foo/bar/discussions/1](togithub.com/foo/bar/discussions/1)'}
${'github.com/foo/bar/issues/1'} | ${'[github.com/foo/bar/issues/1](togithub.com/foo/bar/issues/1)'}
${'github.com/foo/bar/pull/1'} | ${'[github.com/foo/bar/pull/1](togithub.com/foo/bar/pull/1)'}
${'github.com/Foo/bar/pull/1'} | ${'[github.com/Foo/bar/pull/1](togithub.com/Foo/bar/pull/1)'}
${'www.github.com/foo/bar.foo/pull/1'} | ${'[www.github.com/foo/bar.foo/pull/1](www.togithub.com/foo/bar.foo/pull/1)'}
${'www.github.com/foo/bar/discussions/1'} | ${'[www.github.com/foo/bar/discussions/1](www.togithub.com/foo/bar/discussions/1)'}
${'www.github.com/foo/bar/issues/1'} | ${'[www.github.com/foo/bar/issues/1](www.togithub.com/foo/bar/issues/1)'}
${'www.github.com/foo/bar/pull/1'} | ${'[www.github.com/foo/bar/pull/1](www.togithub.com/foo/bar/pull/1)'}
${'https://github.com/foo/bar/discussions/1'} | ${'[https://github.com/foo/bar/discussions/1](https://togithub.com/foo/bar/discussions/1)'}
${'https://github.com/foo/bar/issues/1'} | ${'[https://github.com/foo/bar/issues/1](https://togithub.com/foo/bar/issues/1)'}
${'https://github.com/foo/bar/pull/1'} | ${'[https://github.com/foo/bar/pull/1](https://togithub.com/foo/bar/pull/1)'}
${'https://github.com/foo/bar/discussions/1#comment-123'} | ${'[https://github.com/foo/bar/discussions/1#comment-123](https://togithub.com/foo/bar/discussions/1#comment-123)'}
${'https://github.com/foo/bar/issues/1#comment-123'} | ${'[https://github.com/foo/bar/issues/1#comment-123](https://togithub.com/foo/bar/issues/1#comment-123)'}
${'https://github.com/foo/bar/pull/1#comment-123'} | ${'[https://github.com/foo/bar/pull/1#comment-123](https://togithub.com/foo/bar/pull/1#comment-123)'}
${'[github.com/foo/bar/discussions/1](github.com/foo/bar/discussions/1)'} | ${'[github.com/foo/bar/discussions/1](togithub.com/foo/bar/discussions/1)'}
${'[github.com/foo/bar/issues/1](github.com/foo/bar/issues/1)'} | ${'[github.com/foo/bar/issues/1](togithub.com/foo/bar/issues/1)'}
${'[github.com/foo/bar/pull/1](github.com/foo/bar/pull/1)'} | ${'[github.com/foo/bar/pull/1](togithub.com/foo/bar/pull/1)'}
${'[www.github.com/foo/bar/discussions/1](www.github.com/foo/bar/discussions/1)'} | ${'[www.github.com/foo/bar/discussions/1](www.togithub.com/foo/bar/discussions/1)'}
${'[www.github.com/foo/bar/issues/1](www.github.com/foo/bar/issues/1)'} | ${'[www.github.com/foo/bar/issues/1](www.togithub.com/foo/bar/issues/1)'}
${'[www.github.com/foo/bar.foo/pull/1](www.github.com/foo/bar.foo/pull/1)'} | ${'[www.github.com/foo/bar.foo/pull/1](www.togithub.com/foo/bar.foo/pull/1)'}
${'[www.github.com/foo/bar/pull/1](www.github.com/foo/bar/pull/1)'} | ${'[www.github.com/foo/bar/pull/1](www.togithub.com/foo/bar/pull/1)'}
${'[https://github.com/foo/bar/discussions/1](https://github.com/foo/bar/discussions/1)'} | ${'[https://github.com/foo/bar/discussions/1](https://togithub.com/foo/bar/discussions/1)'}
${'[https://github.com/foo/bar/issues/1](https://github.com/foo/bar/issues/1)'} | ${'[https://github.com/foo/bar/issues/1](https://togithub.com/foo/bar/issues/1)'}
${'[https://github.com/foo/bar/pull/1](https://github.com/foo/bar/pull/1)'} | ${'[https://github.com/foo/bar/pull/1](https://togithub.com/foo/bar/pull/1)'}
${'github.com/foo/bar/discussions/1'} | ${'[github.com/foo/bar/discussions/1](redirect.github.com/foo/bar/discussions/1)'}
${'github.com/foo/bar/issues/1'} | ${'[github.com/foo/bar/issues/1](redirect.github.com/foo/bar/issues/1)'}
${'github.com/foo/bar/pull/1'} | ${'[github.com/foo/bar/pull/1](redirect.github.com/foo/bar/pull/1)'}
${'github.com/Foo/bar/pull/1'} | ${'[github.com/Foo/bar/pull/1](redirect.github.com/Foo/bar/pull/1)'}
${'www.github.com/foo/bar.foo/pull/1'} | ${'[www.github.com/foo/bar.foo/pull/1](redirect.github.com/foo/bar.foo/pull/1)'}
${'www.github.com/foo/bar/discussions/1'} | ${'[www.github.com/foo/bar/discussions/1](redirect.github.com/foo/bar/discussions/1)'}
${'www.github.com/foo/bar/issues/1'} | ${'[www.github.com/foo/bar/issues/1](redirect.github.com/foo/bar/issues/1)'}
${'www.github.com/foo/bar/pull/1'} | ${'[www.github.com/foo/bar/pull/1](redirect.github.com/foo/bar/pull/1)'}
${'https://github.com/foo/bar/discussions/1'} | ${'[https://github.com/foo/bar/discussions/1](https://redirect.github.com/foo/bar/discussions/1)'}
${'https://github.com/foo/bar/issues/1'} | ${'[https://github.com/foo/bar/issues/1](https://redirect.github.com/foo/bar/issues/1)'}
${'https://github.com/foo/bar/pull/1'} | ${'[https://github.com/foo/bar/pull/1](https://redirect.github.com/foo/bar/pull/1)'}
${'https://github.com/foo/bar/discussions/1#comment-123'} | ${'[https://github.com/foo/bar/discussions/1#comment-123](https://redirect.github.com/foo/bar/discussions/1#comment-123)'}
${'https://github.com/foo/bar/issues/1#comment-123'} | ${'[https://github.com/foo/bar/issues/1#comment-123](https://redirect.github.com/foo/bar/issues/1#comment-123)'}
${'https://github.com/foo/bar/pull/1#comment-123'} | ${'[https://github.com/foo/bar/pull/1#comment-123](https://redirect.github.com/foo/bar/pull/1#comment-123)'}
${'[github.com/foo/bar/discussions/1](github.com/foo/bar/discussions/1)'} | ${'[github.com/foo/bar/discussions/1](redirect.github.com/foo/bar/discussions/1)'}
${'[github.com/foo/bar/issues/1](github.com/foo/bar/issues/1)'} | ${'[github.com/foo/bar/issues/1](redirect.github.com/foo/bar/issues/1)'}
${'[github.com/foo/bar/pull/1](github.com/foo/bar/pull/1)'} | ${'[github.com/foo/bar/pull/1](redirect.github.com/foo/bar/pull/1)'}
${'[www.github.com/foo/bar/discussions/1](www.github.com/foo/bar/discussions/1)'} | ${'[www.github.com/foo/bar/discussions/1](redirect.github.com/foo/bar/discussions/1)'}
${'[www.github.com/foo/bar/issues/1](www.github.com/foo/bar/issues/1)'} | ${'[www.github.com/foo/bar/issues/1](redirect.github.com/foo/bar/issues/1)'}
${'[www.github.com/foo/bar.foo/pull/1](www.github.com/foo/bar.foo/pull/1)'} | ${'[www.github.com/foo/bar.foo/pull/1](redirect.github.com/foo/bar.foo/pull/1)'}
${'[www.github.com/foo/bar/pull/1](www.github.com/foo/bar/pull/1)'} | ${'[www.github.com/foo/bar/pull/1](redirect.github.com/foo/bar/pull/1)'}
${'[https://github.com/foo/bar/discussions/1](https://github.com/foo/bar/discussions/1)'} | ${'[https://github.com/foo/bar/discussions/1](https://redirect.github.com/foo/bar/discussions/1)'}
${'[https://github.com/foo/bar/issues/1](https://github.com/foo/bar/issues/1)'} | ${'[https://github.com/foo/bar/issues/1](https://redirect.github.com/foo/bar/issues/1)'}
${'[https://github.com/foo/bar/pull/1](https://github.com/foo/bar/pull/1)'} | ${'[https://github.com/foo/bar/pull/1](https://redirect.github.com/foo/bar/pull/1)'}
`(
'$input -> $output',
({ input, output }: { input: string; output: string }) => {
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/platform/github/massage-markdown-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const urlRegex =
/(?:https?:)?(?:\/\/)?(?:www\.)?(?<!api\.)(?:to)?github\.com\/[-a-z0-9]+\/[-_a-z0-9.]+\/(?:discussions|issues|pull)\/[0-9]+(?:#[-_a-z0-9]+)?/i; // TODO #12872 (?<!re) after text not matching

function massageLink(input: string): string {
return input.replace(regEx(/(?:to)?github\.com/i), 'github.com');
return input.replace(
regEx(/(?:to|redirect\.|www\.)?github\.com/i),
'github.com',
);
}

function collectLinkPosition(input: string, matches: UrlMatch[]): Plugin {
Expand Down

0 comments on commit fbe4dba

Please sign in to comment.