From 7ef135060b11712dc732a6f315dedc4fe5119d67 Mon Sep 17 00:00:00 2001 From: Konv Suu <2583695112@qq.com> Date: Wed, 6 Nov 2024 11:29:36 +0800 Subject: [PATCH] Support new PR view in `isClosedIssue`; tighten related checks (#201) * Refactor PR state selectors and add checks for PR and issue types * update * update * update * update * lint * update --- index.ts | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/index.ts b/index.ts index 24e5036..4090e57 100644 --- a/index.ts +++ b/index.ts @@ -286,28 +286,40 @@ TEST: addTests('isQuickPR', [ 'https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1', ]); -const prStateSelector = [ +const stateSelector = [ '.State', - '[class^="StateLabel"]', + '[data-testid="header-state"]', ].join(','); -export const isDraftPR = (): boolean => $(prStateSelector)!.textContent!.trim() === 'Draft'; +export const isDraftPR = (): boolean => $(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(); - return status === 'Merged'; -}; +export const isMergedPR = (): boolean => $(stateSelector)?.textContent!.trim() === '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' || status === 'Closed as not planned'; +}; export const isReleases = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'releases'; TEST: addTests('isReleases', [