Skip to content

Commit b80581d

Browse files
committed
Refactor conversation state detections
1 parent e1a3aa3 commit b80581d

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

index.ts

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

289-
const stateSelector = [
290-
'.State',
291-
'[data-testid="header-state"]',
292-
].join(',');
293-
294-
export const isDraftPR = (): boolean => $(stateSelector)?.textContent!.trim() === 'Draft';
295-
export const isOpenPR = (): boolean => {
296-
if (!isPR()) {
297-
return false;
298-
}
299-
300-
const status = $(stateSelector)!.textContent!.trim();
289+
const getStateLabel = (): string | undefined => $([
290+
'.State', // Old view
291+
'[class^="StateLabel"]', // React version
292+
].join(','))?.textContent?.trim();
293+
294+
export const isMergedPR = (): boolean => getStateLabel() === 'Merged';
295+
export const isDraftPR = (): boolean => getStateLabel() === 'Draft';
296+
export const isOpenConversation = (): boolean => {
297+
const status = getStateLabel();
301298
return status === 'Open' || status === 'Draft';
302299
};
303300

304-
export const isMergedPR = (): boolean => $(stateSelector)?.textContent!.trim() === 'Merged';
305-
306-
export const isClosedPR = (): boolean => {
307-
if (!isPR()) {
308-
return false;
309-
}
310-
311-
const status = $(stateSelector)!.textContent!.trim();
312-
return status === 'Closed' || status === 'Merged';
313-
};
314-
315-
export const isClosedIssue = (): boolean => {
316-
if (!isIssue()) {
317-
return false;
318-
}
319-
320-
const status = $(stateSelector)!.textContent!.trim();
301+
export const isClosedConversation = (): boolean => {
302+
const status = getStateLabel();
321303
return status === 'Closed' || status === 'Closed as not planned';
322304
};
323305

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"build:esbuild": "esbuild index.ts --bundle --external:github-reserved-names --outdir=distribution --format=esm --drop-labels=TEST",
2929
"build:typescript": "tsc --declaration --emitDeclarationOnly",
3030
"build:demo": "vite build demo",
31+
"fix": "xo --fix",
3132
"prepack": "npm run build",
3233
"test": "run-p build test:* xo",
3334
"test:unit": "vitest",

0 commit comments

Comments
 (0)