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

Shorten no-referrer GitHub URLs too #33

Merged
merged 9 commits into from
Nov 16, 2021
Next Next commit
Shorten GitHub redirect domains
  • Loading branch information
cheap-glitch committed Nov 9, 2021
commit 3d8d1cc8d784c7d92788a8a21e2c30cf87be3658
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ function shortenURL(href, currentUrl = 'https://github.com') {
'https://rawgit.com',
].includes(origin);

const isRedirection = [
'https://github.com', // Renovate
'https://github-redirect.dependabot.com', // Dependabot
].includes(origin);

let [
user,
repo,
Expand All @@ -80,7 +85,7 @@ function shortenURL(href, currentUrl = 'https://github.com') {
filePath = filePath.join('/');

const isLocal = origin === currentUrl.origin;
const isThisRepo = (isLocal || isRaw) && currentRepo === `${user}/${repo}`;
const isThisRepo = (isLocal || isRaw || isRedirection) && currentRepo === `${user}/${repo}`;
const isReserved = reservedPaths.includes(user);
const isDependents = dependentsRegex.test(repoPath);
const isDependencies = dependenciesRegex.test(repoPath);
Expand All @@ -105,7 +110,7 @@ function shortenURL(href, currentUrl = 'https://github.com') {
* Shorten URL
*/

if (isReserved || pathname === '/' || (!isLocal && !isRaw)) {
if (isReserved || pathname === '/' || (!isLocal && !isRaw && !isRedirection)) {
return href
.replace(/^https:[/][/]/, '')
.replace(/^www[.]/, '')
Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,12 @@ test('github.com URLs', urlMatcherMacro, new Map([
'https://github.com/sindresorhus/notifier-for-github/pull/253/files/6b4489d417c9425dc27c5fb8d6b4a8518debd035..60cdcf3c3646164441bf8f037cef620479cdec59',
'<code>6b4489d4..60cdcf3c</code> (#253)',
],
[
'https://github.com/fregante/shorten-repo-url/pull/32/files',
'#32 (files)',
],
[
'https://github.com/nodejs/node/pull/123/files',
'nodejs/node#123 (files)',
],
]));