Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor conversation state detections #202

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading