From 86a06f098bd80fd132a8cdc58a525e8838ae9677 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Fri, 26 Jun 2020 21:26:22 +0800 Subject: [PATCH] feat: show pull request title --- src/platforms/GitHub/DOMHelper.ts | 6 ++++++ src/platforms/GitHub/index.ts | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/platforms/GitHub/DOMHelper.ts b/src/platforms/GitHub/DOMHelper.ts index 1bff0c4..0d141f6 100644 --- a/src/platforms/GitHub/DOMHelper.ts +++ b/src/platforms/GitHub/DOMHelper.ts @@ -10,6 +10,12 @@ export function isInCodePage() { return Boolean($(branchListSelector)) } +export function getIssueTitle() { + const title = $('.gh-header-title .js-issue-title')?.textContent + const id = $('.gh-header-title .gh-header-number')?.textContent + if (title && id) return `${id} ${title}` +} + export function getCurrentBranch() { const selectedBranchButtonSelector = [ '.repository-content #branch-select-menu summary', diff --git a/src/platforms/GitHub/index.ts b/src/platforms/GitHub/index.ts index 2d254ef..c0b33e4 100644 --- a/src/platforms/GitHub/index.ts +++ b/src/platforms/GitHub/index.ts @@ -73,7 +73,9 @@ export const GitHub: Platform = { } let detectedBranchName - if (DOMHelper.isInCodePage()) { + if (URLHelper.isInPullPage()) { + detectedBranchName = DOMHelper.getIssueTitle() + } else if (DOMHelper.isInCodePage()) { // not working well with non-branch blob // cannot handle '/' split branch name, should not use when possibly on branch page detectedBranchName = DOMHelper.getCurrentBranch() || URLHelper.parseSHA()