Skip to content

Commit f2d6198

Browse files
committed
refactor(api): update types
Signed-off-by: Adam Setch <[email protected]>
1 parent 8f3099d commit f2d6198

File tree

21 files changed

+1621
-1965
lines changed

21 files changed

+1621
-1965
lines changed

codegen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const config: CodegenConfig = {
2222
},
2323
config: {
2424
documentMode: 'string',
25+
enumsAsTypes: true,
2526
useTypeImports: true,
2627
},
2728
},

src/renderer/components/metrics/MetricGroup.test.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { renderWithAppContext } from '../../__helpers__/test-utils';
22
import { mockSettings } from '../../__mocks__/state-mocks';
33
import { mockSingleNotification } from '../../utils/api/__mocks__/response-mocks';
4-
import {
5-
type MilestoneFieldsFragment,
6-
MilestoneState,
7-
} from '../../utils/api/graphql/generated/graphql';
4+
import type { MilestoneFieldsFragment } from '../../utils/api/graphql/generated/graphql';
85
import { MetricGroup } from './MetricGroup';
96

107
describe('renderer/components/metrics/MetricGroup.tsx', () => {
@@ -106,7 +103,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {
106103
const mockNotification = mockSingleNotification;
107104
mockNotification.subject.milestone = {
108105
title: 'Milestone 1',
109-
state: MilestoneState.Open,
106+
state: 'OPEN',
110107
} as MilestoneFieldsFragment;
111108

112109
const props = {
@@ -121,7 +118,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {
121118
const mockNotification = mockSingleNotification;
122119
mockNotification.subject.milestone = {
123120
title: 'Milestone 1',
124-
state: MilestoneState.Closed,
121+
state: 'CLOSED',
125122
} as MilestoneFieldsFragment;
126123

127124
const props = {

src/renderer/components/metrics/MetricGroup.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
import { AppContext } from '../../context/App';
1111
import { IconColor } from '../../types';
1212
import type { Notification } from '../../typesGitHub';
13-
import { MilestoneState } from '../../utils/api/graphql/generated/graphql';
1413
import { getPullRequestReviewIcon } from '../../utils/icons';
1514
import { MetricPill } from './MetricPill';
1615

@@ -85,7 +84,7 @@ export const MetricGroup: FC<MetricGroupProps> = ({
8584
{notification.subject.milestone && (
8685
<MetricPill
8786
color={
88-
notification.subject.milestone.state === MilestoneState.Open
87+
notification.subject.milestone.state === 'OPEN'
8988
? IconColor.GREEN
9089
: IconColor.RED
9190
}

src/renderer/typesGitHub.ts

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Account, Link } from './types';
22
import type {
33
AuthorFieldsFragment,
4+
DiscussionStateReason,
45
IssueState,
56
IssueStateReason,
67
MilestoneFieldsFragment,
@@ -26,13 +27,7 @@ export type Reason =
2627
| 'team_mention';
2728

2829
// Note: ANSWERED and OPEN are not an official discussion state type in the GitHub API
29-
export type DiscussionStateType =
30-
| 'ANSWERED'
31-
| 'DUPLICATE'
32-
| 'OPEN'
33-
| 'OUTDATED'
34-
| 'REOPENED'
35-
| 'RESOLVED';
30+
export type GitifyDiscussionState = DiscussionStateReason | 'OPEN' | 'ANSWERED';
3631

3732
export type SubjectType =
3833
| 'CheckSuite'
@@ -57,30 +52,30 @@ export type UserType =
5752
* Note: draft and merged are not official states in the GitHub API.
5853
* These are derived from the pull request's `merged` and `draft` properties.
5954
*/
60-
export type PullRequestStateType = 'closed' | 'draft' | 'merged' | 'open';
55+
export type GitifyPullRequestState = PullRequestState | 'DRAFT';
56+
57+
export type GitifyIssueState = IssueState | IssueStateReason;
6158

6259
export type StateType =
63-
| CheckSuiteStatus
64-
| DiscussionStateType
65-
| PullRequestStateType
66-
| IssueState
67-
| IssueStateReason
68-
| PullRequestState;
60+
| GitifyCheckSuiteStatus
61+
| GitifyDiscussionState
62+
| GitifyIssueState
63+
| GitifyPullRequestState;
6964

70-
export type CheckSuiteStatus =
71-
| 'action_required'
72-
| 'cancelled'
73-
| 'completed'
74-
| 'failure'
75-
| 'in_progress'
76-
| 'pending'
77-
| 'queued'
78-
| 'requested'
79-
| 'skipped'
80-
| 'stale'
81-
| 'success'
82-
| 'timed_out'
83-
| 'waiting';
65+
export type GitifyCheckSuiteStatus =
66+
| 'ACTION_REQUIRED'
67+
| 'CANCELLED'
68+
| 'COMPLETED'
69+
| 'FAILURE'
70+
| 'IN_PROGRESS'
71+
| 'PENDING'
72+
| 'QUEUED'
73+
| 'REQUESTED'
74+
| 'SKIPPED'
75+
| 'STALE'
76+
| 'SUCCESS'
77+
| 'TIMED_OUT'
78+
| 'WAITING';
8479

8580
// TODO: #828 Add explicit types for GitHub API response vs Gitify Notifications object
8681
export type Notification = GitHubNotification & GitifyNotification;
@@ -345,20 +340,6 @@ export interface Release {
345340
published_at: string | null;
346341
}
347342

348-
export interface CheckSuiteAttributes {
349-
workflowName: string;
350-
attemptNumber?: number;
351-
statusDisplayName: string;
352-
status: CheckSuiteStatus | null;
353-
branchName: string;
354-
}
355-
356-
export interface WorkflowRunAttributes {
357-
user: string;
358-
statusDisplayName: string;
359-
status: CheckSuiteStatus | null;
360-
}
361-
362343
export interface GitHubRESTError {
363344
message: string;
364345
documentation_url: Link;

src/renderer/utils/api/__mocks__/response-mocks.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import {
44
} from '../../../__mocks__/account-mocks';
55
import type { Link } from '../../../types';
66
import type { Notification, Repository, User } from '../../../typesGitHub';
7-
import {
8-
type FetchDiscussionByNumberQuery,
9-
PullRequestReviewState,
10-
} from '../graphql/generated/graphql';
7+
import type { FetchDiscussionByNumberQuery } from '../graphql/generated/graphql';
118

129
export const mockNotificationUser: User = {
1310
login: 'octocat',
@@ -52,7 +49,7 @@ export const mockGitHubNotifications: Notification[] = [
5249
latest_comment_url:
5350
'https://api.github.com/repos/gitify-app/notifications-test/issues/comments/302888448' as Link,
5451
type: 'Issue',
55-
state: 'open',
52+
state: 'OPEN',
5653
user: {
5754
login: 'gitify-app',
5855
html_url: 'https://github.com/gitify-app' as Link,
@@ -62,15 +59,15 @@ export const mockGitHubNotifications: Notification[] = [
6259
},
6360
reviews: [
6461
{
65-
state: PullRequestReviewState.Approved,
62+
state: 'APPROVED',
6663
users: ['octocat'],
6764
},
6865
{
69-
state: PullRequestReviewState.ChangesRequested,
66+
state: 'CHANGES_REQUESTED',
7067
users: ['gitify-app'],
7168
},
7269
{
73-
state: PullRequestReviewState.Pending,
70+
state: 'PENDING',
7471
users: ['gitify-user'],
7572
},
7673
],

0 commit comments

Comments
 (0)