diff --git a/index.js b/index.js
index 9e6329e..9b0db17 100644
--- a/index.js
+++ b/index.js
@@ -4,7 +4,7 @@ const patchDiffRegex = /[.](patch|diff)$/;
const releaseRegex = /^releases[/]tag[/]([^/]+)/;
const labelRegex = /^labels[/]([^/]+)/;
const compareRegex = /^compare[/]([^/]+)/;
-const pullRegex = /^pull[/](\d+)[/]([^/]+)$/;
+const pullRegex = /^pull[/](\d+)[/]([^/]+)(?:[/]([\da-f]{40})[.][.]([\da-f]{40}))?$/;
const releaseArchiveRegex = /^archive[/](.+)([.]zip|[.]tar[.]gz)/;
const releaseDownloadRegex = /^releases[/]download[/]([^/]+)[/](.+)/;
const dependentsRegex = /^network[/]dependents[/]?$/;
@@ -90,7 +90,7 @@ function shortenURL(href, currentUrl = 'https://github.com') {
const [, downloadTag, downloadFilename] = repoPath.match(releaseDownloadRegex) || [];
const [, label] = repoPath.match(labelRegex) || [];
const [, compare] = repoPath.match(compareRegex) || [];
- const [, pull, pullPage] = repoPath.match(pullRegex) || [];
+ const [, pull, pullPage, pullPartialStart, pullPartialEnd] = repoPath.match(pullRegex) || [];
const isFileOrDir = revision && [
'raw',
'tree',
@@ -164,8 +164,14 @@ function shortenURL(href, currentUrl = 'https://github.com') {
return `${user}/${repo} (dependencies)`;
}
- if (pull && pullPage) {
- return `${repoUrl}#${pull} (${pullPage})`;
+ if (pull) {
+ if (pullPage === 'files' && pullPartialStart && pullPartialEnd) {
+ return `${pullPartialStart.slice(0, 8)}..${pullPartialEnd.slice(0, 8)}
(#${pull})`;
+ }
+
+ if (pullPage) {
+ return `${repoUrl}#${pull} (${pullPage})`;
+ }
}
if (compare) {
diff --git a/test.js b/test.js
index 2280ab9..9238675 100644
--- a/test.js
+++ b/test.js
@@ -434,4 +434,8 @@ test('GitHub.com URLs', urlMatcherMacro, new Map([
'https://github.com/fregante/shorten-repo-url/issues?q=is%3Aissue++is%3Aopen+sort%3Aupdated-desc+&unrelated=true',
'fregante/shorten-repo-url/issues?unrelated=true (is:open sort:updated-desc)',
],
+ [
+ 'https://github.com/sindresorhus/notifier-for-github/pull/253/files/6b4489d417c9425dc27c5fb8d6b4a8518debd035..60cdcf3c3646164441bf8f037cef620479cdec59',
+ '6b4489d4..60cdcf3c
(#253)',
+ ],
]));