Skip to content

Commit

Permalink
Meta: Use named capture groups in PR regex (#34)
Browse files Browse the repository at this point in the history
Co-authored-by: Federico Brigante <[email protected]>
  • Loading branch information
cheap-glitch and fregante committed Sep 12, 2023
1 parent 083517d commit 8cf65ff
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const patchDiffRegex = /[.](patch|diff)$/;
const releaseRegex = /^releases[/]tag[/]([^/]+)/;
const labelRegex = /^labels[/]([^/]+)/;
const compareRegex = /^compare[/]([^/]+)/;
const pullRegex = /^pull[/](\d+)(?:[/]([^/]+))?(?:[/]([\da-f]{40})[.][.]([\da-f]{40}))?$/;
const pullRegex = /^pull[/](?<pull>\d+)(?:[/](?<pullPage>[^/]+))?(?:[/](?<pullPartialStart>[\da-f]{40})[.][.](?<pullPartialEnd>[\da-f]{40}))?$/;
const issueRegex = /^issues[/](\d+)$/;
const commitRegex = /^commit[/]([\da-f]{40})$/;
const releaseArchiveRegex = /^archive[/](.+)([.]zip|[.]tar[.]gz)/;
Expand Down Expand Up @@ -110,7 +110,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, pullPartialStart, pullPartialEnd] = repoPath.match(pullRegex) || [];
const {pull, pullPage, pullPartialStart, pullPartialEnd} = repoPath.match(pullRegex)?.groups ?? {};
const [, issue] = isRedirection ? repoPath.match(issueRegex) || [] : [];
const [, commit] = isRedirection ? repoPath.match(commitRegex) || [] : [];
const [, wiki] = repoPath.match(wikiRegex) || [];
Expand Down

0 comments on commit 8cf65ff

Please sign in to comment.