Skip to content

Commit 499b25f

Browse files
authored
Format partial PR files views (#32)
1 parent 756b4ae commit 499b25f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const patchDiffRegex = /[.](patch|diff)$/;
44
const releaseRegex = /^releases[/]tag[/]([^/]+)/;
55
const labelRegex = /^labels[/]([^/]+)/;
66
const compareRegex = /^compare[/]([^/]+)/;
7-
const pullRegex = /^pull[/](\d+)[/]([^/]+)$/;
7+
const pullRegex = /^pull[/](\d+)[/]([^/]+)(?:[/]([\da-f]{40})[.][.]([\da-f]{40}))?$/;
88
const releaseArchiveRegex = /^archive[/](.+)([.]zip|[.]tar[.]gz)/;
99
const releaseDownloadRegex = /^releases[/]download[/]([^/]+)[/](.+)/;
1010
const dependentsRegex = /^network[/]dependents[/]?$/;
@@ -90,7 +90,7 @@ function shortenURL(href, currentUrl = 'https://github.com') {
9090
const [, downloadTag, downloadFilename] = repoPath.match(releaseDownloadRegex) || [];
9191
const [, label] = repoPath.match(labelRegex) || [];
9292
const [, compare] = repoPath.match(compareRegex) || [];
93-
const [, pull, pullPage] = repoPath.match(pullRegex) || [];
93+
const [, pull, pullPage, pullPartialStart, pullPartialEnd] = repoPath.match(pullRegex) || [];
9494
const isFileOrDir = revision && [
9595
'raw',
9696
'tree',
@@ -164,8 +164,14 @@ function shortenURL(href, currentUrl = 'https://github.com') {
164164
return `${user}/${repo} (dependencies)`;
165165
}
166166

167-
if (pull && pullPage) {
168-
return `${repoUrl}#${pull} (${pullPage})`;
167+
if (pull) {
168+
if (pullPage === 'files' && pullPartialStart && pullPartialEnd) {
169+
return `<code>${pullPartialStart.slice(0, 8)}..${pullPartialEnd.slice(0, 8)}</code> (#${pull})`;
170+
}
171+
172+
if (pullPage) {
173+
return `${repoUrl}#${pull} (${pullPage})`;
174+
}
169175
}
170176

171177
if (compare) {

test.js

+4
Original file line numberDiff line numberDiff line change
@@ -434,4 +434,8 @@ test('GitHub.com URLs', urlMatcherMacro, new Map([
434434
'https://github.com/fregante/shorten-repo-url/issues?q=is%3Aissue++is%3Aopen+sort%3Aupdated-desc+&unrelated=true',
435435
'fregante/shorten-repo-url/issues?unrelated=true (is:open sort:updated-desc)',
436436
],
437+
[
438+
'https://github.com/sindresorhus/notifier-for-github/pull/253/files/6b4489d417c9425dc27c5fb8d6b4a8518debd035..60cdcf3c3646164441bf8f037cef620479cdec59',
439+
'<code>6b4489d4..60cdcf3c</code> (#253)',
440+
],
437441
]));

0 commit comments

Comments
 (0)