Skip to content

Commit c11ec23

Browse files
committed
further type refactoring
Signed-off-by: Adam Setch <[email protected]>
1 parent e32f2f5 commit c11ec23

File tree

23 files changed

+118
-149
lines changed

23 files changed

+118
-149
lines changed

src/renderer/__mocks__/notifications-mocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import type {
77
GitifySubject,
88
Hostname,
99
Link,
10+
SubjectType,
1011
} from '../types';
11-
import type { SubjectType } from '../typesGitHub';
1212
import {
1313
mockEnterpriseNotifications,
1414
mockGitHubNotifications,

src/renderer/__mocks__/user-mocks.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { GitifyUser, Link } from '../types';
2-
import type { User } from '../typesGitHub';
3-
import type { AuthorFieldsFragment } from '../utils/api/graphql/generated/graphql';
1+
import type { GitifyNotificationUser, GitifyUser, Link } from '../types';
2+
import type { RawUser } from '../utils/api/types';
43

54
export const mockGitifyUser: GitifyUser = {
65
login: 'octocat',
@@ -9,18 +8,20 @@ export const mockGitifyUser: GitifyUser = {
98
avatar: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link,
109
};
1110

12-
export function createPartialMockUser(login: string): User {
13-
const mockUser: Partial<User> = {
11+
export function createPartialMockUser(login: string): RawUser {
12+
const mockUser: Partial<RawUser> = {
1413
login: login,
1514
html_url: `https://github.com/${login}` as Link,
1615
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link,
1716
type: 'User',
1817
};
1918

20-
return mockUser as User;
19+
return mockUser as RawUser;
2120
}
2221

23-
export function createMockAuthorFragment(login: string): AuthorFieldsFragment {
22+
export function createMockAuthorFragment(
23+
login: string,
24+
): GitifyNotificationUser {
2425
return {
2526
__typename: 'User',
2627
login: login,

src/renderer/components/avatars/AvatarWithFallback.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { useState } from 'react';
33

44
import { Avatar, Stack, Truncate } from '@primer/react';
55

6-
import { type Link, Size } from '../../types';
7-
import type { UserType } from '../../typesGitHub';
6+
import { type Link, Size, type UserType } from '../../types';
87
import { getDefaultUserIcon } from '../../utils/icons';
98
import { isNonHumanUser } from '../../utils/notifications/filters/userType';
109

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

Lines changed: 3 additions & 3 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 { GitifyMilestone } from '../../types';
34
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', () => {
@@ -104,7 +104,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {
104104
mockNotification.subject.milestone = {
105105
title: 'Milestone 1',
106106
state: 'OPEN',
107-
} as MilestoneFieldsFragment;
107+
} as GitifyMilestone;
108108

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

124124
const props = {
125125
notification: mockNotification,

src/renderer/components/notifications/NotificationFooter.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import userEvent from '@testing-library/user-event';
33

44
import { renderWithAppContext } from '../../__helpers__/test-utils';
55
import { mockGitHubCloudAccount } from '../../__mocks__/account-mocks';
6-
import type { Link } from '../../types';
7-
import type { UserType } from '../../typesGitHub';
6+
import type { Link, UserType } from '../../types';
87
import { mockSingleNotification } from '../../utils/api/__mocks__/response-mocks';
98
import * as comms from '../../utils/comms';
109
import { NotificationFooter } from './NotificationFooter';

src/renderer/types.ts

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { FC } from 'react';
22

33
import type { OcticonProps } from '@primer/octicons-react';
44

5-
import type { Reason, SubjectType, UserType } from './typesGitHub';
65
import type {
76
AuthorFieldsFragment,
87
DiscussionStateReason,
@@ -261,8 +260,9 @@ export type FilterStateType = 'open' | 'closed' | 'merged' | 'draft' | 'other';
261260
* Gitify Notification Types
262261
*
263262
* These types represent the clean, UI-focused notification structure
264-
* used throughout the application. Raw GitHub API responses are
265-
* transformed into these types at the API boundary.
263+
* used throughout the application.
264+
*
265+
* Raw GitHub API responses are transformed into these types at the API boundary.
266266
*
267267
**/
268268

@@ -297,12 +297,12 @@ export interface GitifySubject {
297297
title: string;
298298
/** Subject type (Issue, PullRequest, etc.) */
299299
type: SubjectType;
300-
/** API URL for the subject (used for GraphQL fetching) */
300+
/** API URL for the subject */
301301
url: Link | null;
302302
/** API URL for the latest comment */
303303
latestCommentUrl: Link | null;
304304

305-
// Enriched fields (from GraphQL - all optional)
305+
// Enriched fields (from additional GraphQL or REST API calls)
306306
/** Issue/PR/Discussion number */
307307
number?: number;
308308
/** Parsed state from GraphQL */
@@ -318,7 +318,7 @@ export interface GitifySubject {
318318
/** Label names */
319319
labels?: string[];
320320
/** Milestone state/title */
321-
milestone?: MilestoneFieldsFragment;
321+
milestone?: GitifyMilestone;
322322
/** Deep link to latest comment */
323323
htmlUrl?: Link;
324324
}
@@ -351,6 +351,8 @@ export interface GitifyOwner {
351351

352352
export type GitifyNotificationUser = AuthorFieldsFragment;
353353

354+
export type GitifyMilestone = MilestoneFieldsFragment;
355+
354356
export interface GitifyPullRequestReview {
355357
state: PullRequestReviewState;
356358
users: string[];
@@ -382,3 +384,50 @@ export type GitifyCheckSuiteStatus =
382384
| 'SUCCESS'
383385
| 'TIMED_OUT'
384386
| 'WAITING';
387+
388+
/**
389+
*
390+
* Gitify Type Enhancements
391+
*
392+
* These types represent the clean, UI-focused notification structure
393+
* used throughout the application. Raw GitHub API responses are
394+
* transformed into these types at the API boundary.
395+
*
396+
**/
397+
398+
// Stronger typings for string literal attributes
399+
export type Reason =
400+
| 'approval_requested'
401+
| 'assign'
402+
| 'author'
403+
| 'ci_activity'
404+
| 'comment'
405+
| 'invitation'
406+
| 'manual'
407+
| 'member_feature_requested'
408+
| 'mention'
409+
| 'review_requested'
410+
| 'security_advisory_credit'
411+
| 'security_alert'
412+
| 'state_change'
413+
| 'subscribed'
414+
| 'team_mention';
415+
416+
export type SubjectType =
417+
| 'CheckSuite'
418+
| 'Commit'
419+
| 'Discussion'
420+
| 'Issue'
421+
| 'PullRequest'
422+
| 'Release'
423+
| 'RepositoryDependabotAlertsThread'
424+
| 'RepositoryInvitation'
425+
| 'RepositoryVulnerabilityAlert'
426+
| 'WorkflowRun';
427+
428+
export type UserType =
429+
| 'Bot'
430+
| 'EnterpriseUserAccount'
431+
| 'Mannequin'
432+
| 'Organization'
433+
| 'User';

src/renderer/typesGitHub.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
GitifyRepository,
1010
Link,
1111
} from '../../../types';
12-
import type { User } from '../../../typesGitHub';
12+
import type { RawUser } from '../types';
1313

1414
export const mockNotificationUser = {
1515
id: 123456789,
@@ -18,7 +18,7 @@ export const mockNotificationUser = {
1818
url: 'https://api.github.com/users/octocat' as Link,
1919
html_url: 'https://github.com/octocat' as Link,
2020
type: 'User',
21-
} satisfies Partial<User>;
21+
} satisfies Partial<RawUser>;
2222

2323
// 2 Notifications
2424
// Hostname : 'github.com'

src/renderer/utils/api/client.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { components } from '@octokit/openapi-types';
21
import type { AxiosPromise } from 'axios';
32
import type { ExecutionResult } from 'graphql';
43

@@ -10,15 +9,6 @@ import type {
109
SettingsState,
1110
Token,
1211
} from '../../types';
13-
14-
type RawGitHubNotification = components['schemas']['thread'];
15-
16-
import type {
17-
Commit,
18-
CommitComment,
19-
NotificationThreadSubscription,
20-
Release,
21-
} from '../../typesGitHub';
2212
import { isAnsweredDiscussionFeatureSupported } from '../features';
2313
import { rendererLogError } from '../logger';
2414
import {
@@ -36,6 +26,13 @@ import {
3626
type ExecutionResultWithHeaders,
3727
performGraphQLRequest,
3828
} from './request';
29+
import type {
30+
NotificationThreadSubscription,
31+
RawCommit,
32+
RawCommitComment,
33+
RawGitHubNotification,
34+
RawRelease,
35+
} from './types';
3936
import {
4037
getGitHubAPIBaseUrl,
4138
getGitHubGraphQLUrl,
@@ -138,7 +135,7 @@ export function ignoreNotificationThreadSubscription(
138135
*
139136
* Endpoint documentation: https://docs.github.com/en/rest/commits/commits#get-a-commit
140137
*/
141-
export function getCommit(url: Link, token: Token): AxiosPromise<Commit> {
138+
export function getCommit(url: Link, token: Token): AxiosPromise<RawCommit> {
142139
return apiRequestAuth(url, 'GET', token);
143140
}
144141

@@ -151,7 +148,7 @@ export function getCommit(url: Link, token: Token): AxiosPromise<Commit> {
151148
export function getCommitComment(
152149
url: Link,
153150
token: Token,
154-
): AxiosPromise<CommitComment> {
151+
): AxiosPromise<RawCommitComment> {
155152
return apiRequestAuth(url, 'GET', token);
156153
}
157154

@@ -160,7 +157,7 @@ export function getCommitComment(
160157
*
161158
* Endpoint documentation: https://docs.github.com/en/rest/releases/releases#get-a-release
162159
*/
163-
export function getRelease(url: Link, token: Token): AxiosPromise<Release> {
160+
export function getRelease(url: Link, token: Token): AxiosPromise<RawRelease> {
164161
return apiRequestAuth(url, 'GET', token);
165162
}
166163

src/renderer/utils/api/errors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { AxiosError, type AxiosResponse } from 'axios';
33
import { EVENTS } from '../../../shared/events';
44

55
import type { Link } from '../../types';
6-
import type { GitHubRESTError } from '../../typesGitHub';
76
import { Errors } from '../errors';
87
import { determineFailureType } from './errors';
8+
import type { GitHubRESTError } from './types';
99

1010
describe('renderer/utils/api/errors.ts', () => {
1111
it('network error', async () => {

0 commit comments

Comments
 (0)