From d17a13725e7823fb42916014cbd2944d36ee8eac Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 16 Feb 2016 04:55:04 +0700 Subject: [PATCH] handle the PR case when both source and target branches are from the same repo --- extension/content.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/extension/content.js b/extension/content.js index 07d2ede..a512e70 100755 --- a/extension/content.js +++ b/extension/content.js @@ -2,21 +2,29 @@ 'use strict'; const path = location.pathname; const isDashboard = path === '/'; -const isRepo = /^\/[^/]+\/[^/]+/.test(location.pathname); -const isPR = () => /^\/[^/]+\/[^/]+\/pull\/\d+$/.test(location.pathname); +const isRepo = /^\/[^/]+\/[^/]+/.test(path); const repoName = path.split('/')[2]; +const isPR = () => /^\/[^/]+\/[^/]+\/pull\/\d+$/.test(location.pathname); +const getUsername = () => $('meta[name="user-login"]').attr('content'); function linkifyBranchRefs() { $('.commit-ref').each((i, el) => { const parts = $(el).find('.css-truncate-target'); - const username = parts.eq(0).text(); - const branch = parts.eq(1).text(); + let username = parts.eq(0).text(); + let branch = parts.eq(1).text(); + + // both branches are from the current repo + if (!branch) { + branch = username; + username = getUsername(); + } + $(el).wrap(``); }); } document.addEventListener('DOMContentLoaded', () => { - const username = $('meta[name="user-login"]').attr('content'); + const username = getUsername(); if (isDashboard) { // hide other users starring/forking your repos