From f41d7f230463554e8f9ea163d0dad9a004bc6e2f Mon Sep 17 00:00:00 2001
From: Federico <me@fregante.com>
Date: Sat, 3 Apr 2021 22:09:40 +0700
Subject: Improve branch getter function (#4193)

---
 source/features/enable-file-links-in-compare-view.tsx | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

(limited to 'source/features/enable-file-links-in-compare-view.tsx')

diff --git a/source/features/enable-file-links-in-compare-view.tsx b/source/features/enable-file-links-in-compare-view.tsx
index 1b374f2b..2bf1edb8 100644
--- a/source/features/enable-file-links-in-compare-view.tsx
+++ b/source/features/enable-file-links-in-compare-view.tsx
@@ -6,15 +6,16 @@ import * as pageDetect from 'github-url-detection';
 
 import features from '.';
 import GitHubURL from '../github-helpers/github-url';
-import {getCurrentBranch, getPRHeadRepo} from '../github-helpers';
 
 /** Rebuilds the "View file" link because it points to the base repo and to the commit, instead of the head repo and its branch */
 function handlePRMenuOpening({delegateTarget: dropdown}: delegate.Event): void {
 	dropdown.classList.add('rgh-actionable-link'); // Mark this as processed
+
+	const [nameWithOwner, headBranch] = select('.head-ref')!.title.split(':');
 	const filePath = dropdown.closest('[data-path]')!.getAttribute('data-path')!;
 
-	const viewFile = select('a[data-ga-click^="View file"]', dropdown)!;
-	viewFile.pathname = [getPRHeadRepo()!.nameWithOwner, 'blob', getCurrentBranch()!, filePath].join('/'); // Do not replace with `GitHubURL`  #3152 #3111 #2595
+	select('a[data-ga-click^="View file"]', dropdown)!
+		.pathname = [nameWithOwner, 'blob', headBranch, filePath].join('/'); // Do not replace with `GitHubURL`  #3152 #3111 #2595
 }
 
 function handleCompareMenuOpening({delegateTarget: dropdown}: delegate.Event): void {
-- 
cgit v1.2.3

