From 00cc08d5fd8a0d5fc023febc8c3ae1fed553fff1 Mon Sep 17 00:00:00 2001 From: lukeaxu Date: Fri, 13 Sep 2019 12:05:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dgithub=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/adapters/github.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/adapters/github.js b/src/adapters/github.js index 4507acf..a081d58 100644 --- a/src/adapters/github.js +++ b/src/adapters/github.js @@ -112,17 +112,30 @@ class GitHub extends PjaxAdapter { if (!showInNonCodePage && type && !~['tree', 'blob'].indexOf(type)) { return cb() } - + const branchDropdownMenuSummary = $('.branch-select-menu summary'); + const branchNameInTitle = branchDropdownMenuSummary.attr('title'); + const branchNameInSpan = branchDropdownMenuSummary.find('span').text(); + const branchFromSummary = + branchNameInTitle && branchNameInTitle.toLowerCase().startsWith('switch branches') + ? branchNameInSpan + : branchNameInTitle; + // Get branch by inspecting page, quite fragile so provide multiple fallbacks const branch = - // Code page - $('.branch-select-menu .select-menu-item.selected').data('name') || + // Pick the commit ID as branch name when the code page is listing tree in a particular commit + (type === 'commit' && typeId) || + // Pick the commit ID or branch name from the DOM + branchFromSummary || + ($('.overall-summary .numbers-summary .commits a').attr('href') || '').replace( + `/${username}/${reponame}/commits/`, + '' + ) || // Pull requests page ($('.commit-ref.base-ref').attr('title') || ':').match(/:(.*)/)[1] || // Reuse last selected branch if exist (currentRepo.username === username && currentRepo.reponame === reponame && currentRepo.branch) || // Get default branch from cache - this._defaultBranch[username + '/' + reponame] + this._defaultBranch[username + '/' + reponame]; // Still no luck, get default branch for real const repo = {username: username, reponame: reponame, branch: branch, pullNumber: pullNumber} -- Gitee