Skip to content

Commit

Permalink
Refactor conversation state detections
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Nov 10, 2024
1 parent e1a3aa3 commit b80581d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
40 changes: 11 additions & 29 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,38 +286,20 @@ TEST: addTests('isQuickPR', [
'https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1',
]);

const stateSelector = [
'.State',
'[data-testid="header-state"]',
].join(',');

export const isDraftPR = (): boolean => $(stateSelector)?.textContent!.trim() === 'Draft';
export const isOpenPR = (): boolean => {
if (!isPR()) {
return false;
}

const status = $(stateSelector)!.textContent!.trim();
const getStateLabel = (): string | undefined => $([
'.State', // Old view
'[class^="StateLabel"]', // React version
].join(','))?.textContent?.trim();

export const isMergedPR = (): boolean => getStateLabel() === 'Merged';
export const isDraftPR = (): boolean => getStateLabel() === 'Draft';
export const isOpenConversation = (): boolean => {
const status = getStateLabel();
return status === 'Open' || status === 'Draft';
};

export const isMergedPR = (): boolean => $(stateSelector)?.textContent!.trim() === 'Merged';

export const isClosedPR = (): boolean => {
if (!isPR()) {
return false;
}

const status = $(stateSelector)!.textContent!.trim();
return status === 'Closed' || status === 'Merged';
};

export const isClosedIssue = (): boolean => {
if (!isIssue()) {
return false;
}

const status = $(stateSelector)!.textContent!.trim();
export const isClosedConversation = (): boolean => {
const status = getStateLabel();
return status === 'Closed' || status === 'Closed as not planned';
};

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"build:esbuild": "esbuild index.ts --bundle --external:github-reserved-names --outdir=distribution --format=esm --drop-labels=TEST",
"build:typescript": "tsc --declaration --emitDeclarationOnly",
"build:demo": "vite build demo",
"fix": "xo --fix",
"prepack": "npm run build",
"test": "run-p build test:* xo",
"test:unit": "vitest",
Expand Down

0 comments on commit b80581d

Please sign in to comment.