From 4f915d5f9d26e789e76fdb0c6d0b0469746ac055 Mon Sep 17 00:00:00 2001 From: kovsu <2583695112@qq.com> Date: Wed, 6 Nov 2024 09:22:40 +0800 Subject: [PATCH 1/7] Refactor PR state selectors and add checks for PR and issue types --- index.ts | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/index.ts b/index.ts index 24e5036..981798b 100644 --- a/index.ts +++ b/index.ts @@ -286,28 +286,47 @@ TEST: addTests('isQuickPR', [ 'https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1', ]); -const prStateSelector = [ +const stateSelector = [ '.State', '[class^="StateLabel"]', ].join(','); -export const isDraftPR = (): boolean => $(prStateSelector)!.textContent!.trim() === 'Draft'; +export const isDraftPR = (): boolean => isPR() && $(stateSelector)?.textContent!.trim() === 'Draft'; export const isOpenPR = (): boolean => { - const status = $(prStateSelector)!.textContent!.trim(); + if (isPR()) { + return false; + } + + const status = $(stateSelector)?.textContent!.trim(); return status === 'Open' || status === 'Draft'; }; export const isMergedPR = (): boolean => { - const status = $(prStateSelector)!.textContent!.trim(); + if (isPR()) { + return false; + } + + const status = $(stateSelector)?.textContent!.trim(); return status === 'Merged'; }; export const isClosedPR = (): boolean => { - const status = $(prStateSelector)!.textContent!.trim(); + if (isPR()) { + return false; + } + + const status = $(stateSelector)?.textContent!.trim(); return status === 'Closed' || status === 'Merged'; }; -export const isClosedIssue = (): boolean => exists('#partial-discussion-header :is(.octicon-issue-closed, .octicon-skip)'); +export const isClosedIssue = (): boolean => { + if (isIssue()) { + return false; + } + + const status = $(stateSelector)?.textContent!.trim(); + return status === 'Closed'; +}; export const isReleases = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'releases'; TEST: addTests('isReleases', [ From 7d6a488136c9e89ac2c11313f1b9ef890c82ec27 Mon Sep 17 00:00:00 2001 From: kovsu <2583695112@qq.com> Date: Wed, 6 Nov 2024 09:26:01 +0800 Subject: [PATCH 2/7] update --- index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.ts b/index.ts index 981798b..1f56196 100644 --- a/index.ts +++ b/index.ts @@ -291,13 +291,13 @@ const stateSelector = [ '[class^="StateLabel"]', ].join(','); -export const isDraftPR = (): boolean => isPR() && $(stateSelector)?.textContent!.trim() === 'Draft'; +export const isDraftPR = (): boolean => isPR() && $(stateSelector)!.textContent!.trim() === 'Draft'; export const isOpenPR = (): boolean => { if (isPR()) { return false; } - const status = $(stateSelector)?.textContent!.trim(); + const status = $(stateSelector)!.textContent!.trim(); return status === 'Open' || status === 'Draft'; }; @@ -306,7 +306,7 @@ export const isMergedPR = (): boolean => { return false; } - const status = $(stateSelector)?.textContent!.trim(); + const status = $(stateSelector)!.textContent!.trim(); return status === 'Merged'; }; @@ -315,7 +315,7 @@ export const isClosedPR = (): boolean => { return false; } - const status = $(stateSelector)?.textContent!.trim(); + const status = $(stateSelector)!.textContent!.trim(); return status === 'Closed' || status === 'Merged'; }; @@ -324,7 +324,7 @@ export const isClosedIssue = (): boolean => { return false; } - const status = $(stateSelector)?.textContent!.trim(); + const status = $(stateSelector)!.textContent!.trim(); return status === 'Closed'; }; From cbad3da55e31b212b5e3545504399b5baef6a45a Mon Sep 17 00:00:00 2001 From: kovsu <2583695112@qq.com> Date: Wed, 6 Nov 2024 10:16:40 +0800 Subject: [PATCH 3/7] update --- index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 1f56196..087a091 100644 --- a/index.ts +++ b/index.ts @@ -325,7 +325,7 @@ export const isClosedIssue = (): boolean => { } const status = $(stateSelector)!.textContent!.trim(); - return status === 'Closed'; + return status === 'Closed' || status === 'Closed as not planned'; }; export const isReleases = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'releases'; From efb1f7d9008130a89541fe1b33711801687edd3f Mon Sep 17 00:00:00 2001 From: kovsu <2583695112@qq.com> Date: Wed, 6 Nov 2024 10:18:20 +0800 Subject: [PATCH 4/7] update --- index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index 087a091..344a4b4 100644 --- a/index.ts +++ b/index.ts @@ -293,7 +293,7 @@ const stateSelector = [ export const isDraftPR = (): boolean => isPR() && $(stateSelector)!.textContent!.trim() === 'Draft'; export const isOpenPR = (): boolean => { - if (isPR()) { + if (!isPR()) { return false; } @@ -302,7 +302,7 @@ export const isOpenPR = (): boolean => { }; export const isMergedPR = (): boolean => { - if (isPR()) { + if (!isPR()) { return false; } @@ -311,7 +311,7 @@ export const isMergedPR = (): boolean => { }; export const isClosedPR = (): boolean => { - if (isPR()) { + if (!isPR()) { return false; } @@ -320,7 +320,7 @@ export const isClosedPR = (): boolean => { }; export const isClosedIssue = (): boolean => { - if (isIssue()) { + if (!isIssue()) { return false; } From fcc805f5cfc7de9a2f703c4d9189a40dada7f751 Mon Sep 17 00:00:00 2001 From: kovsu <2583695112@qq.com> Date: Wed, 6 Nov 2024 10:21:52 +0800 Subject: [PATCH 5/7] update --- index.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/index.ts b/index.ts index 344a4b4..00cc33b 100644 --- a/index.ts +++ b/index.ts @@ -291,7 +291,7 @@ const stateSelector = [ '[class^="StateLabel"]', ].join(','); -export const isDraftPR = (): boolean => isPR() && $(stateSelector)!.textContent!.trim() === 'Draft'; +export const isDraftPR = (): boolean => $(stateSelector)?.textContent!.trim() === 'Draft'; export const isOpenPR = (): boolean => { if (!isPR()) { return false; @@ -302,11 +302,7 @@ export const isOpenPR = (): boolean => { }; export const isMergedPR = (): boolean => { - if (!isPR()) { - return false; - } - - const status = $(stateSelector)!.textContent!.trim(); + const status = $(stateSelector)?.textContent!.trim(); return status === 'Merged'; }; From e3aa1626cb97dddca3b908d2a8a2a483c80c6e3d Mon Sep 17 00:00:00 2001 From: kovsu <2583695112@qq.com> Date: Wed, 6 Nov 2024 10:25:35 +0800 Subject: [PATCH 6/7] lint --- index.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/index.ts b/index.ts index 00cc33b..5cd21e8 100644 --- a/index.ts +++ b/index.ts @@ -301,10 +301,7 @@ export const isOpenPR = (): boolean => { return status === 'Open' || status === 'Draft'; }; -export const isMergedPR = (): boolean => { - const status = $(stateSelector)?.textContent!.trim(); - return status === 'Merged'; -}; +export const isMergedPR = (): boolean => $(stateSelector)?.textContent!.trim() === 'Merged'; export const isClosedPR = (): boolean => { if (!isPR()) { From 156bdf1e3fd6bb702146bbca3e0971477cb394d2 Mon Sep 17 00:00:00 2001 From: kovsu <2583695112@qq.com> Date: Wed, 6 Nov 2024 10:58:46 +0800 Subject: [PATCH 7/7] update --- index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 5cd21e8..4090e57 100644 --- a/index.ts +++ b/index.ts @@ -288,7 +288,7 @@ TEST: addTests('isQuickPR', [ const stateSelector = [ '.State', - '[class^="StateLabel"]', + '[data-testid="header-state"]', ].join(','); export const isDraftPR = (): boolean => $(stateSelector)?.textContent!.trim() === 'Draft';