From 50de384f63f8024d2ae187da3e953e3288cf3b13 Mon Sep 17 00:00:00 2001 From: kovsu <2583695112@qq.com> Date: Mon, 4 Nov 2024 14:54:41 +0800 Subject: [PATCH 1/5] Improve `isMergedPR` and `isClosedPR` --- index.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index afa1ba9..79893c4 100644 --- a/index.ts +++ b/index.ts @@ -288,8 +288,19 @@ TEST: addTests('isQuickPR', [ export const isDraftPR = (): boolean => exists('#partial-discussion-header .octicon-git-pull-request-draft'); export const isOpenPR = (): boolean => exists('#partial-discussion-header :is(.octicon-git-pull-request, .octicon-git-pull-request-draft)'); -export const isMergedPR = (): boolean => exists('#partial-discussion-header .octicon-git-merge'); -export const isClosedPR = (): boolean => exists('#partial-discussion-header :is(.octicon-git-pull-request-closed, .octicon-git-merge)'); +export const isMergedPR = (): boolean => { + if (exists('#partial-discussion-header :is(.octicon-git-merge)')) + return true; + const status = $('[class^="StateLabel"]')!.textContent + return status === 'Merged' +} +export const isClosedPR = (): boolean => { + if (exists('#partial-discussion-header :is(.octicon-git-pull-request-closed, .octicon-git-merge)')) + return true; + const status = $('[class^="StateLabel"]')!.textContent + return status === 'Closed' || status === 'Merged' +} + export const isClosedIssue = (): boolean => exists('#partial-discussion-header :is(.octicon-issue-closed, .octicon-skip)'); export const isReleases = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'releases'; From 9d238017b6903e925d503e162daa2fea126ceb33 Mon Sep 17 00:00:00 2001 From: kovsu <2583695112@qq.com> Date: Mon, 4 Nov 2024 14:56:42 +0800 Subject: [PATCH 2/5] lint --- index.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/index.ts b/index.ts index 79893c4..9dabf63 100644 --- a/index.ts +++ b/index.ts @@ -289,17 +289,22 @@ TEST: addTests('isQuickPR', [ export const isDraftPR = (): boolean => exists('#partial-discussion-header .octicon-git-pull-request-draft'); export const isOpenPR = (): boolean => exists('#partial-discussion-header :is(.octicon-git-pull-request, .octicon-git-pull-request-draft)'); export const isMergedPR = (): boolean => { - if (exists('#partial-discussion-header :is(.octicon-git-merge)')) + if (exists('#partial-discussion-header :is(.octicon-git-merge)')) { return true; - const status = $('[class^="StateLabel"]')!.textContent - return status === 'Merged' -} + } + + const status = $('[class^="StateLabel"]')!.textContent; + return status === 'Merged'; +}; + export const isClosedPR = (): boolean => { - if (exists('#partial-discussion-header :is(.octicon-git-pull-request-closed, .octicon-git-merge)')) + if (exists('#partial-discussion-header :is(.octicon-git-pull-request-closed, .octicon-git-merge)')) { return true; - const status = $('[class^="StateLabel"]')!.textContent - return status === 'Closed' || status === 'Merged' -} + } + + const status = $('[class^="StateLabel"]')!.textContent; + return status === 'Closed' || status === 'Merged'; +}; export const isClosedIssue = (): boolean => exists('#partial-discussion-header :is(.octicon-issue-closed, .octicon-skip)'); @@ -751,7 +756,6 @@ TEST: addTests('isRepositoryActions', [ export const isUserTheOrganizationOwner = (): boolean => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]'); - export const canUserAdminRepo = (): boolean => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]'); /** @deprecated Use `canUserAdminRepo` */ From 6aca9902deeb8f2321be7005fbcc01e1ab056b65 Mon Sep 17 00:00:00 2001 From: kovsu <2583695112@qq.com> Date: Mon, 4 Nov 2024 15:36:38 +0800 Subject: [PATCH 3/5] update --- index.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/index.ts b/index.ts index 9dabf63..2040ea7 100644 --- a/index.ts +++ b/index.ts @@ -289,20 +289,12 @@ TEST: addTests('isQuickPR', [ export const isDraftPR = (): boolean => exists('#partial-discussion-header .octicon-git-pull-request-draft'); export const isOpenPR = (): boolean => exists('#partial-discussion-header :is(.octicon-git-pull-request, .octicon-git-pull-request-draft)'); export const isMergedPR = (): boolean => { - if (exists('#partial-discussion-header :is(.octicon-git-merge)')) { - return true; - } - - const status = $('[class^="StateLabel"]')!.textContent; + const status = ($('.State') || $('[class^="StateLabel"]'))!.textContent!.trim(); return status === 'Merged'; }; export const isClosedPR = (): boolean => { - if (exists('#partial-discussion-header :is(.octicon-git-pull-request-closed, .octicon-git-merge)')) { - return true; - } - - const status = $('[class^="StateLabel"]')!.textContent; + const status = ($('.State') || $('[class^="StateLabel"]'))!.textContent!.trim(); return status === 'Closed' || status === 'Merged'; }; From 02ee907d955cc9d64596de51e39eb71bd0f218f8 Mon Sep 17 00:00:00 2001 From: kovsu <2583695112@qq.com> Date: Mon, 4 Nov 2024 15:44:23 +0800 Subject: [PATCH 4/5] update --- index.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index 2040ea7..0672d30 100644 --- a/index.ts +++ b/index.ts @@ -286,15 +286,19 @@ TEST: addTests('isQuickPR', [ 'https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1', ]); -export const isDraftPR = (): boolean => exists('#partial-discussion-header .octicon-git-pull-request-draft'); -export const isOpenPR = (): boolean => exists('#partial-discussion-header :is(.octicon-git-pull-request, .octicon-git-pull-request-draft)'); +export const isDraftPR = (): boolean => ($('.State') ?? $('[class^="StateLabel"]'))!.textContent!.trim() === 'Draft'; +export const isOpenPR = (): boolean => { + const status = ($('.State') ?? $('[class^="StateLabel"]'))!.textContent!.trim(); + return status === 'Open' || status === 'Draft'; +}; + export const isMergedPR = (): boolean => { - const status = ($('.State') || $('[class^="StateLabel"]'))!.textContent!.trim(); + const status = ($('.State') ?? $('[class^="StateLabel"]'))!.textContent!.trim(); return status === 'Merged'; }; export const isClosedPR = (): boolean => { - const status = ($('.State') || $('[class^="StateLabel"]'))!.textContent!.trim(); + const status = ($('.State') ?? $('[class^="StateLabel"]'))!.textContent!.trim(); return status === 'Closed' || status === 'Merged'; }; From d144e72159c06f80f9b01bc58cba9e0edb484ccc Mon Sep 17 00:00:00 2001 From: kovsu <2583695112@qq.com> Date: Mon, 4 Nov 2024 16:28:13 +0800 Subject: [PATCH 5/5] update --- index.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index 0672d30..24e5036 100644 --- a/index.ts +++ b/index.ts @@ -286,19 +286,24 @@ TEST: addTests('isQuickPR', [ 'https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1', ]); -export const isDraftPR = (): boolean => ($('.State') ?? $('[class^="StateLabel"]'))!.textContent!.trim() === 'Draft'; +const prStateSelector = [ + '.State', + '[class^="StateLabel"]', +].join(','); + +export const isDraftPR = (): boolean => $(prStateSelector)!.textContent!.trim() === 'Draft'; export const isOpenPR = (): boolean => { - const status = ($('.State') ?? $('[class^="StateLabel"]'))!.textContent!.trim(); + const status = $(prStateSelector)!.textContent!.trim(); return status === 'Open' || status === 'Draft'; }; export const isMergedPR = (): boolean => { - const status = ($('.State') ?? $('[class^="StateLabel"]'))!.textContent!.trim(); + const status = $(prStateSelector)!.textContent!.trim(); return status === 'Merged'; }; export const isClosedPR = (): boolean => { - const status = ($('.State') ?? $('[class^="StateLabel"]'))!.textContent!.trim(); + const status = $(prStateSelector)!.textContent!.trim(); return status === 'Closed' || status === 'Merged'; };