Skip to content

Commit 4f915d5

Browse files
committed
Refactor PR state selectors and add checks for PR and issue types
1 parent b562b56 commit 4f915d5

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

index.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,28 +286,47 @@ 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',
291291
'[class^="StateLabel"]',
292292
].join(',');
293293

294-
export const isDraftPR = (): boolean => $(prStateSelector)!.textContent!.trim() === 'Draft';
294+
export const isDraftPR = (): boolean => isPR() && $(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

300304
export const isMergedPR = (): boolean => {
301-
const status = $(prStateSelector)!.textContent!.trim();
305+
if (isPR()) {
306+
return false;
307+
}
308+
309+
const status = $(stateSelector)?.textContent!.trim();
302310
return status === 'Merged';
303311
};
304312

305313
export const isClosedPR = (): boolean => {
306-
const status = $(prStateSelector)!.textContent!.trim();
314+
if (isPR()) {
315+
return false;
316+
}
317+
318+
const status = $(stateSelector)?.textContent!.trim();
307319
return status === 'Closed' || status === 'Merged';
308320
};
309321

310-
export const isClosedIssue = (): boolean => exists('#partial-discussion-header :is(.octicon-issue-closed, .octicon-skip)');
322+
export const isClosedIssue = (): boolean => {
323+
if (isIssue()) {
324+
return false;
325+
}
326+
327+
const status = $(stateSelector)?.textContent!.trim();
328+
return status === 'Closed';
329+
};
311330

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

0 commit comments

Comments
 (0)