Skip to content

Commit

Permalink
Handle draft PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
rgehan committed Feb 29, 2024
1 parent 0a8bdbf commit 2d360f9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/lib/assertUnreachable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function assertUnreachable<T>(_: never, defaultValue: T): T {
return defaultValue;
}
3 changes: 2 additions & 1 deletion src/providers/github/components/IssueCard/IssueCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface IIssue {
url: string;
html_url: string;
state: 'open' | 'closed' | 'merged';
isDraft: boolean;
status: IssueStatus;
number: number;
createdAt: string;
Expand Down Expand Up @@ -101,7 +102,7 @@ export const IssueCard = compose<IInnerProps, IProps>(
<div className="flex-1 min-w-0">
<div className="flex-1 flex justify-between items-center">
<div className="flex-1 flex items-center mb-1 min-w-0">
<IssueStatusIndicator type={issue.type} state={issue.state} />
<IssueStatusIndicator issue={issue} />

<span className={cx('truncate pb-1 min-w-0', linkStyle)}>
<a
Expand Down
30 changes: 19 additions & 11 deletions src/providers/github/components/IssueCard/IssueStatusIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@ import cx from 'classnames';
import React from 'react';

import { IIssue } from './IssueCard';

const ISSUE_STATUS_COLORS: Record<IIssue['state'], string> = {
open: 'text-green-500',
closed: 'text-red-500',
merged: 'text-purple-500',
};
import {assertUnreachable} from "../../../../lib/assertUnreachable";

interface IProps {
type: IIssue['type'];
state: IIssue['state'];
issue: Pick<IIssue, 'state' | 'isDraft' | 'type'>;
}

export const IssueStatusIndicator = ({ type, state }: IProps) => (
export const IssueStatusIndicator = ({ issue }: IProps) => (
<i
className={cx(
'mr-2',
type === 'PullRequest'
issue.type === 'PullRequest'
? 'fas fa-code-branch'
: 'fas fa-exclamation-circle',
ISSUE_STATUS_COLORS[state.toLowerCase() as IIssue['state']]
getColor(issue.state.toLowerCase() as IIssue['state'], issue.isDraft)
)}
/>
);

function getColor(state: IIssue['state'], isDraft: boolean)
{
switch (state) {
case 'open':
return isDraft ? 'text-gray-500' : 'text-green-500';
case 'closed':
return 'text-red-500';
case 'merged':
return 'text-purple-500';
default:
return assertUnreachable(state, 'text-gray-500');
}
}
1 change: 1 addition & 0 deletions src/providers/github/fetchers/graphql/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const pullRequestFragment = `
fragment PullRequestFragment on PullRequest {
${commonFields}
mergeable
isDraft
reviews {
totalCount
}
Expand Down

0 comments on commit 2d360f9

Please sign in to comment.