Skip to content

Commit 1ba7d24

Browse files
authored
refactor(api): use graphql api for issue and pull request enrichment (#2468)
* refactor(api): use graphql api for issue and pull request enrichment Signed-off-by: Adam Setch <[email protected]> * refactor(api): use graphql api for issue and pull request enrichment Signed-off-by: Adam Setch <[email protected]> * refactor(api): use graphql api for issue and pull request enrichment Signed-off-by: Adam Setch <[email protected]> * refactor(api): use graphql api for issue and pull request enrichment Signed-off-by: Adam Setch <[email protected]> * refactor(api): use graphql api for issue and pull request enrichment Signed-off-by: Adam Setch <[email protected]> * refactor(api): use graphql api for issue and pull request enrichment Signed-off-by: Adam Setch <[email protected]> * refactor(api): use graphql api for issue and pull request enrichment Signed-off-by: Adam Setch <[email protected]> * refactor(api): update types Signed-off-by: Adam Setch <[email protected]> * refactor(api): update types Signed-off-by: Adam Setch <[email protected]> * refactor: tests Signed-off-by: Adam Setch <[email protected]> * refactor: tests Signed-off-by: Adam Setch <[email protected]> * refactor: tests Signed-off-by: Adam Setch <[email protected]> * Update issue.test.ts * refactor: tests Signed-off-by: Adam Setch <[email protected]> * Merge branch 'main' into refactor/fetch-issue-graphql Signed-off-by: Adam Setch <[email protected]> * Merge branch 'main' into refactor/fetch-issue-graphql Signed-off-by: Adam Setch <[email protected]> * Merge branch 'main' into refactor/fetch-issue-graphql Signed-off-by: Adam Setch <[email protected]> * Merge branch 'main' into refactor/fetch-issue-graphql Signed-off-by: Adam Setch <[email protected]> * Merge branch 'main' into refactor/fetch-issue-graphql Signed-off-by: Adam Setch <[email protected]> * Merge branch 'main' into refactor/fetch-issue-graphql Signed-off-by: Adam Setch <[email protected]> * Merge branch 'main' into refactor/fetch-issue-graphql Signed-off-by: Adam Setch <[email protected]> * simplify state filtering Signed-off-by: Adam Setch <[email protected]> * refactor test suites Signed-off-by: Adam Setch <[email protected]> * refactor test suites Signed-off-by: Adam Setch <[email protected]> * refactor: remove unused code Signed-off-by: Adam Setch <[email protected]> --------- Signed-off-by: Adam Setch <[email protected]>
1 parent 5e05265 commit 1ba7d24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3297
-4080
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/__mocks__/notifications-mocks.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { Constants } from '../constants';
2-
import type { AccountNotifications, Hostname } from '../types';
2+
import type {
3+
AccountNotifications,
4+
GitifyNotificationState,
5+
Hostname,
6+
} from '../types';
37
import type {
48
Notification,
59
Repository,
6-
StateType,
710
Subject,
811
SubjectType,
912
} from '../typesGitHub';
@@ -43,12 +46,12 @@ export const mockSingleAccountNotifications: AccountNotifications[] = [
4346
export function createMockSubject(mocks: {
4447
title?: string;
4548
type?: SubjectType;
46-
state?: StateType;
49+
state?: GitifyNotificationState;
4750
}): Subject {
4851
return {
4952
title: mocks.title ?? 'Mock Subject',
5053
type: mocks.type ?? ('Unknown' as SubjectType),
51-
state: mocks.state ?? ('Unknown' as StateType),
54+
state: mocks.state ?? ('Unknown' as GitifyNotificationState),
5255
url: null,
5356
latest_comment_url: null,
5457
};
@@ -68,7 +71,15 @@ export function createPartialMockNotification(
6871
hasRequiredScopes: true,
6972
},
7073
subject: subject as Subject,
71-
repository: repository as Repository,
74+
repository: {
75+
name: 'notifications-test',
76+
full_name: 'gitify-app/notifications-test',
77+
html_url: 'https://github.com/gitify-app/notifications-test',
78+
owner: {
79+
login: 'gitify-app',
80+
},
81+
...repository,
82+
} as Repository,
7283
};
7384

7485
return mockNotification as Notification;

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

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

77
describe('renderer/components/metrics/MetricGroup.tsx', () => {
@@ -103,8 +103,8 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {
103103
const mockNotification = mockSingleNotification;
104104
mockNotification.subject.milestone = {
105105
title: 'Milestone 1',
106-
state: 'open',
107-
} as Milestone;
106+
state: 'OPEN',
107+
} as MilestoneFieldsFragment;
108108

109109
const props = {
110110
notification: mockNotification,
@@ -118,8 +118,8 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {
118118
const mockNotification = mockSingleNotification;
119119
mockNotification.subject.milestone = {
120120
title: 'Milestone 1',
121-
state: 'closed',
122-
} as Milestone;
121+
state: 'CLOSED',
122+
} as MilestoneFieldsFragment;
123123

124124
const props = {
125125
notification: mockNotification,

src/renderer/components/metrics/MetricGroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const MetricGroup: FC<MetricGroupProps> = ({
8484
{notification.subject.milestone && (
8585
<MetricPill
8686
color={
87-
notification.subject.milestone.state === 'open'
87+
notification.subject.milestone.state === 'OPEN'
8888
? IconColor.GREEN
8989
: IconColor.RED
9090
}

src/renderer/types.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ import type {
88
SubjectType,
99
UserType,
1010
} from './typesGitHub';
11+
import type {
12+
AuthorFieldsFragment,
13+
DiscussionStateReason,
14+
IssueState,
15+
IssueStateReason,
16+
MilestoneFieldsFragment,
17+
PullRequestReviewState,
18+
PullRequestState,
19+
} from './utils/api/graphql/generated/graphql';
1120
import type { AuthMethod, PlatformType } from './utils/auth/types';
1221

1322
declare const __brand: unique symbol;
@@ -251,3 +260,60 @@ export interface Chevron {
251260
}
252261

253262
export type FilterStateType = 'open' | 'closed' | 'merged' | 'draft' | 'other';
263+
264+
/**
265+
*
266+
* Gitify Notification Types
267+
*
268+
**/
269+
270+
export interface GitifyNotification {
271+
account: Account;
272+
order: number;
273+
}
274+
275+
export interface GitifySubject {
276+
number?: number;
277+
state?: GitifyNotificationState;
278+
user?: GitifyNotificationUser;
279+
reviews?: GitifyPullRequestReview[];
280+
linkedIssues?: string[];
281+
comments?: number;
282+
labels?: string[];
283+
milestone?: MilestoneFieldsFragment;
284+
htmlUrl?: Link;
285+
}
286+
287+
export type GitifyNotificationUser = AuthorFieldsFragment;
288+
289+
export interface GitifyPullRequestReview {
290+
state: PullRequestReviewState;
291+
users: string[];
292+
}
293+
294+
export type GitifyDiscussionState = DiscussionStateReason | 'OPEN' | 'ANSWERED';
295+
296+
export type GitifyPullRequestState = PullRequestState | 'DRAFT';
297+
298+
export type GitifyIssueState = IssueState | IssueStateReason;
299+
300+
export type GitifyNotificationState =
301+
| GitifyCheckSuiteStatus
302+
| GitifyDiscussionState
303+
| GitifyIssueState
304+
| GitifyPullRequestState;
305+
306+
export type GitifyCheckSuiteStatus =
307+
| 'ACTION_REQUIRED'
308+
| 'CANCELLED'
309+
| 'COMPLETED'
310+
| 'FAILURE'
311+
| 'IN_PROGRESS'
312+
| 'PENDING'
313+
| 'QUEUED'
314+
| 'REQUESTED'
315+
| 'SKIPPED'
316+
| 'STALE'
317+
| 'SUCCESS'
318+
| 'TIMED_OUT'
319+
| 'WAITING';

0 commit comments

Comments
 (0)