Skip to content

Commit 7ef1350

Browse files
authored
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
1 parent b562b56 commit 7ef1350

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

index.ts

+22-10
Original file line numberDiff line numberDiff line change
@@ -286,28 +286,40 @@ TEST: addTests('isQuickPR', [
286286
'https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1',
287287
]);
288288

289-
const prStateSelector = [
289+
const stateSelector = [
290290
'.State',
291-
'[class^="StateLabel"]',
291+
'[data-testid="header-state"]',
292292
].join(',');
293293

294-
export const isDraftPR = (): boolean => $(prStateSelector)!.textContent!.trim() === 'Draft';
294+
export const isDraftPR = (): boolean => $(stateSelector)?.textContent!.trim() === 'Draft';
295295
export const isOpenPR = (): boolean => {
296-
const status = $(prStateSelector)!.textContent!.trim();
296+
if (!isPR()) {
297+
return false;
298+
}
299+
300+
const status = $(stateSelector)!.textContent!.trim();
297301
return status === 'Open' || status === 'Draft';
298302
};
299303

300-
export const isMergedPR = (): boolean => {
301-
const status = $(prStateSelector)!.textContent!.trim();
302-
return status === 'Merged';
303-
};
304+
export const isMergedPR = (): boolean => $(stateSelector)?.textContent!.trim() === 'Merged';
304305

305306
export const isClosedPR = (): boolean => {
306-
const status = $(prStateSelector)!.textContent!.trim();
307+
if (!isPR()) {
308+
return false;
309+
}
310+
311+
const status = $(stateSelector)!.textContent!.trim();
307312
return status === 'Closed' || status === 'Merged';
308313
};
309314

310-
export const isClosedIssue = (): boolean => exists('#partial-discussion-header :is(.octicon-issue-closed, .octicon-skip)');
315+
export const isClosedIssue = (): boolean => {
316+
if (!isIssue()) {
317+
return false;
318+
}
319+
320+
const status = $(stateSelector)!.textContent!.trim();
321+
return status === 'Closed' || status === 'Closed as not planned';
322+
};
311323

312324
export const isReleases = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'releases';
313325
TEST: addTests('isReleases', [

0 commit comments

Comments
 (0)