summaryrefslogtreecommitdiff
path: root/source/github-helpers
diff options
context:
space:
mode:
Diffstat (limited to 'source/github-helpers')
-rw-r--r--source/github-helpers/prevent-link-loss.test.ts45
-rw-r--r--source/github-helpers/prevent-link-loss.ts2
2 files changed, 31 insertions, 16 deletions
diff --git a/source/github-helpers/prevent-link-loss.test.ts b/source/github-helpers/prevent-link-loss.test.ts
index 218cd460..9fa52f73 100644
--- a/source/github-helpers/prevent-link-loss.test.ts
+++ b/source/github-helpers/prevent-link-loss.test.ts
@@ -49,6 +49,11 @@ test('preventPrCommitLinkLoss', t => {
t.is(
replacePrCommitLink('lorem ipsum dolor https://github.com/refined-github/refined-github/pull/3205/commits/1da152b3f8c51dd72d8ae6ad9cc96e0c2d8716f5#diff-932095cc3c0dff00495b4c392d78f0afR60 some random string'),
'lorem ipsum dolor [`1da152b` (#3205)](https://github.com/refined-github/refined-github/pull/3205/commits/1da152b3f8c51dd72d8ae6ad9cc96e0c2d8716f5#diff-932095cc3c0dff00495b4c392d78f0afR60) some random string',
+ 'It should include line-permalink hashes',
+ );
+ t.is(
+ replacePrCommitLink('lorem ipsum dolor https://github.com/refined-github/refined-github/pull/3205/commits/b0ac07948f9d30a760bda25a7106011441abfd5d#r438059292 some random string'),
+ 'lorem ipsum dolor [`b0ac079` (#3205)](https://github.com/refined-github/refined-github/pull/3205/commits/b0ac07948f9d30a760bda25a7106011441abfd5d#r438059292) some random string',
'It should include any hashes',
);
t.is(
@@ -90,35 +95,45 @@ test('preventPrCompareLinkLoss', t => {
test('preventDiscussionLinkLoss', t => {
t.is(
- replaceDiscussionLink('https://github.com/refined-github/refined-github/discussions/2789'),
- 'https://github.com/refined-github/refined-github/discussions/2789',
- 'It should not affect discussion URLs without a query parameter',
+ replaceDiscussionLink('https://github.com/eslint/eslint/discussions/15898'),
+ 'https://github.com/eslint/eslint/discussions/15898',
+ 'It should not affect discussion URLs without a query parameter', // It's what causes the bug
+ );
+ t.is(
+ replaceDiscussionLink('https://github.com/eslint/eslint/discussions/15898#discussion-4086661'),
+ 'https://github.com/eslint/eslint/discussions/15898#discussion-4086661',
+ 'It should not affect discussion comment URLs without a query parameter', // It's what causes the bug
+ );
+ t.is(
+ replaceDiscussionLink('https://github.com/eslint/eslint/discussions/15898?sort=top#discussion-4086661'),
+ '[eslint/eslint#15898 (comment)](https://github.com/eslint/eslint/discussions/15898?sort=top#discussion-4086661)',
);
t.is(
- replaceDiscussionLink('https://github.com/refined-github/refined-github/discussions/2789?sort=top#discussioncomment-646707'),
- '[#2789 (comment)](https://github.com/refined-github/refined-github/discussions/2789?sort=top#discussioncomment-646707)',
+ replaceDiscussionLink('https://github.com/eslint/eslint/discussions/15898?sort=top#issue-comment-box'),
+ '[eslint/eslint#15898 (comment)](https://github.com/eslint/eslint/discussions/15898?sort=top#issue-comment-box)',
+ 'It should work on any hash',
);
t.is(
- replaceDiscussionLink('https://github.com/refined-github/refined-github/discussions/2789?sort=top\nhttps://github.com/refined-github/refined-github/discussions/2789#discussioncomment-646707'),
- '[#2789](https://github.com/refined-github/refined-github/discussions/2789?sort=top)\nhttps://github.com/refined-github/refined-github/discussions/2789#discussioncomment-646707',
+ replaceDiscussionLink('https://github.com/eslint/eslint/discussions/15898?sort=top\nhttps://github.com/eslint/eslint/discussions/15898#discussioncomment-646707'),
+ '[eslint/eslint#15898](https://github.com/eslint/eslint/discussions/15898?sort=top)\nhttps://github.com/eslint/eslint/discussions/15898#discussioncomment-646707',
'It should work separately on links.',
);
t.is(
- replaceDiscussionLink('lorem ipsum dolor https://github.com/refined-github/refined-github/discussions/2789?sort=top some random string'),
- 'lorem ipsum dolor [#2789](https://github.com/refined-github/refined-github/discussions/2789?sort=top) some random string',
+ replaceDiscussionLink('lorem ipsum dolor https://github.com/eslint/eslint/discussions/15898?sort=top some random string'),
+ 'lorem ipsum dolor [eslint/eslint#15898](https://github.com/eslint/eslint/discussions/15898?sort=top) some random string',
);
t.is(
- replaceDiscussionLink(replaceDiscussionLink('lorem ipsum dolor https://github.com/refined-github/refined-github/discussions/2789?sort=top#discussioncomment-646707 some random string')),
- 'lorem ipsum dolor [#2789 (comment)](https://github.com/refined-github/refined-github/discussions/2789?sort=top#discussioncomment-646707) some random string',
+ replaceDiscussionLink(replaceDiscussionLink('lorem ipsum dolor https://github.com/eslint/eslint/discussions/15898?sort=top#discussion-4086661 some random string')),
+ 'lorem ipsum dolor [eslint/eslint#15898 (comment)](https://github.com/eslint/eslint/discussions/15898?sort=top#discussion-4086661) some random string',
'It should not apply it twice',
);
t.is(
- replaceDiscussionLink('I like [turtles](https://github.com/refined-github/refined-github/discussions/2789?sort=top#discussioncomment-646707)'),
- 'I like [turtles](https://github.com/refined-github/refined-github/discussions/2789?sort=top#discussioncomment-646707)',
+ replaceDiscussionLink('I like [turtles](https://github.com/eslint/eslint/discussions/15898#discussion-4086661)'),
+ 'I like [turtles](https://github.com/eslint/eslint/discussions/15898#discussion-4086661)',
'It should ignore Markdown links',
);
t.is(
- replaceDiscussionLink('https://github.com/streetcomplete/StreetComplete/discussions/2789?sort=top#discussioncomment-646707'),
- '[streetcomplete/StreetComplete#2789 (comment)](https://github.com/streetcomplete/StreetComplete/discussions/2789?sort=top#discussioncomment-646707)',
+ replaceDiscussionLink('https://github.com/streetcomplete/StreetComplete/discussions/15898?sort=top#discussioncomment-646707'),
+ '[streetcomplete/StreetComplete#15898 (comment)](https://github.com/streetcomplete/StreetComplete/discussions/15898?sort=top#discussioncomment-646707)',
);
});
diff --git a/source/github-helpers/prevent-link-loss.ts b/source/github-helpers/prevent-link-loss.ts
index 275a149d..2cc6a5ba 100644
--- a/source/github-helpers/prevent-link-loss.ts
+++ b/source/github-helpers/prevent-link-loss.ts
@@ -13,7 +13,7 @@ export const prCommitUrlRegex = new RegExp('\\b' + escapeRegex(location.origin)
const prComparePathnameRegex = /[/]([^/]+[/][^/]+)[/]compare[/](.+)(#diff-[\da-fR-]+)/; // eslint-disable-line unicorn/better-regex
export const prCompareUrlRegex = new RegExp('\\b' + escapeRegex(location.origin) + prComparePathnameRegex.source, 'gi');
-const discussionPathnameRegex = /[/]([^/]+[/][^/]+)[/]discussions[/](\d+)[?][^#\s]+(#discussioncomment-\w+)?\b/; // eslint-disable-line unicorn/better-regex
+const discussionPathnameRegex = /[/]([^/]+[/][^/]+)[/]discussions[/](\d+)[?][^#\s]+(#[\w-]+)?\b/; // eslint-disable-line unicorn/better-regex
export const discussionUrlRegex = new RegExp('\\b' + escapeRegex(location.origin) + discussionPathnameRegex.source, 'gi');
// To be used as replacer callback in string.replace() for PR commit links