From 1d14dd6e0a687b22d531bb49f603c45ad920cb87 Mon Sep 17 00:00:00 2001 From: Paul Molluzzo Date: Fri, 19 Feb 2016 03:26:25 +0700 Subject: [PATCH] Close #21 PR: Improve branch name assignment. Fixes #18 --- extension/content.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/extension/content.js b/extension/content.js index 2be994ed9828..af6e4ee85e51 100755 --- a/extension/content.js +++ b/extension/content.js @@ -3,7 +3,7 @@ const path = location.pathname; const isDashboard = path === '/'; const isRepo = /^\/[^/]+\/[^/]+/.test(path); -const username = path.split('/')[1]; +const ownerName = path.split('/')[1]; const repoName = path.split('/')[2]; const isPR = () => /^\/[^/]+\/[^/]+\/pull\/\d+$/.test(location.pathname); const isReleases = () => isRepo && /^\/[^/]+\/[^/]+\/(releases|tags)/.test(location.pathname); @@ -12,18 +12,17 @@ const getUsername = () => $('meta[name="user-login"]').attr('content'); function linkifyBranchRefs() { $('.commit-ref').each((i, el) => { const parts = $(el).find('.css-truncate-target'); - let username = parts.eq(0).text(); - let branch = parts.eq(1).text(); + let branch = parts.eq(parts.length - 1).text(); + let username = ownerName; + + // if there are two parts the first part is the username + if (parts.length > 1) { + username = parts.eq(0).text(); + } // forked repos can have their name changed; grab it from first commit in PR const branchRepo = path.includes(username) ? repoName : $('.commit-id').attr('href').split('/')[2]; - // both branches are from the current repo - if (!branch) { - branch = username; - username = getUsername(); - } - $(el).wrap(``); }); } @@ -34,7 +33,7 @@ function addReleasesTab() { const hasReleases = $releasesTab.length > 0; if (!hasReleases) { - $releasesTab = $(` + $releasesTab = $(` Releases `);