Skip to content

Commit

Permalink
Include current branch/tag in compare & commit repo links. Closes ref…
Browse files Browse the repository at this point in the history
  • Loading branch information
jerone committed May 30, 2019
1 parent 09d6a69 commit 66c2de0
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions source/features/more-dropdown.tsx
Expand Up @@ -31,10 +31,32 @@ async function init(): Promise<void> {
createDropdown();
}

let compareUrl = `/${repoUrl}/compare`;
let commitsUrl = `/${repoUrl}/commits`;
let tree = '';
const urlParts = location.pathname.split('/');
if (urlParts[3] === 'tree') { // On repo page
tree = urlParts[4];
} else if (urlParts[3] === 'compare') { // On compare page
if (urlParts[4].includes('...')) {
tree = urlParts[4].split('...')[0];
} else {
tree = urlParts[4];
}
} else if (urlParts[3] === 'commits') { // On commits page
tree = urlParts[4];
} else if (urlParts[3] === 'releases' && urlParts[4] === 'tag') { // On tag page
tree = urlParts[5];
}
if (tree) {
compareUrl += `/${tree}`;
commitsUrl += `/${tree}`;
}

const menu = select('.reponav-dropdown .dropdown-menu')!;

menu.append(
<a href={`/${repoUrl}/compare`} className="rgh-reponav-more dropdown-item">
<a href={compareUrl} className="rgh-reponav-more dropdown-item">
{icons.darkCompare()} Compare
</a>,

Expand All @@ -43,7 +65,7 @@ async function init(): Promise<void> {
{icons.dependency()} Dependencies
</a>,

<a href={`/${repoUrl}/commits`} className="rgh-reponav-more dropdown-item">
<a href={commitsUrl} className="rgh-reponav-more dropdown-item">
{icons.history()} Commits
</a>,

Expand Down

0 comments on commit 66c2de0

Please sign in to comment.