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

Fix finding a wrong branch in pull request page #217

Merged
merged 1 commit into from
Dec 7, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/adapters/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,21 @@ class GitHub extends Adapter {
const GH_BRANCH_SEL_1 = '[aria-label="Switch branches or tags"]'
const GH_BRANCH_SEL_2 = '.repo-root a[data-branch]'
const GH_BRANCH_SEL_3 = '.repository-sidebar a[aria-label="Code"]'
const GH_BRANCH_SEL_4 = 'link[title*="Recent Commits to"]'
const GH_BRANCH_SEL_4 = '.current-branch'
const GH_BRANCH_SEL_5 = 'link[title*="Recent Commits to"]'

const branch =
// Detect branch in code page (don't care about non-code pages, let them use the next fallback)
$(GH_BRANCH_SEL_1).attr('title') || $(GH_BRANCH_SEL_2).data('branch') ||
// Non-code page
($(GH_BRANCH_SEL_3).attr('href') || ' ').match(/([^\/]+)/g)[3] ||
// Non-code page (new design)
// Specific handle /commit page
($(GH_BRANCH_SEL_4).attr('title') || ' ').match(/([^\:]+)/g)[1] ||
// Ignore if Github expands one more <link> - use last selected one instead
($(GH_BRANCH_SEL_5).length === 1
&& ($(GH_BRANCH_SEL_5).attr('title') || ' ').match(/([^\:]+)/g)[1]) ||

// Reuse last selected branch if exist
(currentRepo.username === username && currentRepo.reponame === reponame && currentRepo.branch)
// Get default branch from cache
Expand Down