Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link to current branch in More's Compare and Commits links #2102

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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`;
jerone marked this conversation as resolved.
Show resolved Hide resolved
let tree = '';
jerone marked this conversation as resolved.
Show resolved Hide resolved
const urlParts = location.pathname.split('/');
jerone marked this conversation as resolved.
Show resolved Hide resolved
if (urlParts[3] === 'tree') { // On repo page
tree = urlParts[4];
} else if (urlParts[3] === 'compare' && urlParts[4]) { // 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];
}
jerone marked this conversation as resolved.
Show resolved Hide resolved
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