summaryrefslogtreecommitdiff
path: root/source/libs/utils.ts
diff options
context:
space:
mode:
authorGravatar Maximiliano Arias <max@max-arias.com> 2020-05-18 19:40:07 -0300
committerGravatar GitHub <noreply@github.com> 2020-05-19 00:40:07 +0200
commit2531c75bd2fdc233a3d1299cc60717376ca1dcab (patch)
treeaed34bb83396d1a24a3e940d26f37cd8444b137a /source/libs/utils.ts
parent0a602b8b706a57c13c3f1e90abf1a3dac5fedb73 (diff)
downloadrefined-github-2531c75bd2fdc233a3d1299cc60717376ca1dcab.tar.gz
refined-github-2531c75bd2fdc233a3d1299cc60717376ca1dcab.tar.zst
refined-github-2531c75bd2fdc233a3d1299cc60717376ca1dcab.zip
Add `prevent-pr-commit-link-loss` feature (#3085)
Co-authored-by: Fregante <opensource@bfred.it>
Diffstat (limited to 'source/libs/utils.ts')
-rw-r--r--source/libs/utils.ts7
1 files changed, 7 insertions, 0 deletions
diff --git a/source/libs/utils.ts b/source/libs/utils.ts
index a4629fca..0d9ca856 100644
--- a/source/libs/utils.ts
+++ b/source/libs/utils.ts
@@ -204,3 +204,10 @@ export function getLatestVersionTag(tags: string[]): string {
return latestVersion;
}
+
+const escapeRegex = (string: string) => string.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
+export const prCommitRegex = new RegExp(`\\b${escapeRegex(location.origin)}[/][^/]+[/][^/]+[/]pull[/]\\d+[/]commits[/][0-9a-f]{7,40}\\b(?! \\]|\\))`, 'gi');
+
+export function preventPrCommitLinkBreak(comment: string) {
+ return comment.replace(prCommitRegex, '[$& ]($&)');
+}