From 0a6b6b4613a5caa2e21d46d11ef686b13d09504c Mon Sep 17 00:00:00 2001 From: Jeroen van Warmerdam Date: Tue, 4 Jun 2019 20:29:24 +0200 Subject: Link to current branch in More's Compare and Commits links (#2102) --- source/libs/utils.ts | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source/libs/utils.ts') diff --git a/source/libs/utils.ts b/source/libs/utils.ts index a7ddf562..f3a7b2c8 100644 --- a/source/libs/utils.ts +++ b/source/libs/utils.ts @@ -40,6 +40,15 @@ export const getOwnerAndRepo = (): { return {ownerName, repoName}; }; +export const getRef = (): string | undefined => { + const pathnameParts = location.pathname.split('/'); + if (['commits', 'blob', 'tree', 'blame'].includes(pathnameParts[3])) { + return pathnameParts[4]; + } + + return undefined; +}; + export const parseTag = (tag: string): {version: string; namespace: string} => { const [, namespace = '', version = ''] = tag.match(/(?:(.*)@)?([^@]+)/) || []; return {namespace, version}; -- cgit v1.2.3