Skip to content

Commit 8e53674

Browse files
committed
refactor: use fragments for details
Signed-off-by: Adam Setch <[email protected]>
1 parent eceab7b commit 8e53674

File tree

3 files changed

+66
-247
lines changed

3 files changed

+66
-247
lines changed

src/renderer/typesGitHub.ts

Lines changed: 43 additions & 242 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
// import type { components } from '@octokit/openapi-types';
1+
import type { components } from '@octokit/openapi-types';
22

33
import type { GitifyNotification, GitifySubject, Link } from './types';
44

55
// TODO: #828 Add explicit types for GitHub API response vs Gitify Notifications object
6-
export type Notification = GitHubNotification & GitifyNotification;
7-
export type Subject = GitHubSubject & GitifySubject;
6+
export type Notification = GitHubNotification &
7+
GitifyNotification & {
8+
reason: Reason;
9+
subject: Subject;
10+
repository: Repository;
11+
};
12+
export type Subject = GitHubSubject & {
13+
url: Link;
14+
latest_comment_url: Link;
15+
type: SubjectType;
16+
} & GitifySubject;
817

918
/**
10-
*
1119
* GitHub REST API Response Types
12-
*
1320
**/
1421

1522
export type Reason =
@@ -48,254 +55,48 @@ export type UserType =
4855
| 'Organization'
4956
| 'User';
5057

51-
// export type Notification = components['schemas']['thread'];
52-
export interface GitHubNotification {
53-
id: string;
54-
unread: boolean;
55-
reason: Reason;
56-
updated_at: string;
57-
last_read_at: string | null;
58-
subject: Subject;
59-
repository: Repository;
60-
url: Link;
61-
subscription_url: Link;
62-
}
63-
64-
interface GitHubSubject {
65-
title: string;
66-
url: Link | null;
67-
latest_comment_url: Link | null;
68-
type: SubjectType;
69-
}
70-
71-
export type UserDetails = User & UserProfile;
72-
73-
export interface UserProfile {
74-
name: string;
75-
company: string;
76-
blog: string;
77-
location: string;
78-
email: string;
79-
hireable: string;
80-
bio: string;
81-
twitter_username: string;
82-
public_repos: number;
83-
public_gists: number;
84-
followers: number;
85-
following: number;
86-
created_at: string;
87-
updated_at: string;
88-
private_gists: number;
89-
total_private_repos: number;
90-
owned_private_repos: number;
91-
disk_usage: number;
92-
collaborators: number;
93-
two_factor_authentication: boolean;
94-
plan: Plan;
95-
}
96-
97-
export interface Plan {
98-
name: string;
99-
space: number;
100-
private_repos: number;
101-
collaborators: number;
102-
}
58+
export type GitHubNotification = components['schemas']['thread'];
59+
export type GitHubSubject = components['schemas']['thread']['subject'];
10360

104-
export interface User {
105-
login: string;
106-
id: number;
107-
node_id: string;
108-
avatar_url: Link;
109-
gravatar_url: Link;
110-
url: Link;
61+
export type Repository = components['schemas']['repository'] & {
11162
html_url: Link;
112-
followers_url: Link;
113-
following_url: Link;
114-
gists_url: Link;
115-
starred_url: Link;
116-
subscriptions_url: Link;
117-
organizations_url: Link;
118-
repos_url: Link;
119-
events_url: Link;
120-
received_events_url: Link;
121-
type: UserType;
122-
site_admin: boolean;
123-
}
124-
125-
// export type Repository = components['schemas']['repository'];
126-
export interface Repository {
127-
id: number;
128-
node_id: string;
129-
name: string;
130-
full_name: string;
131-
private: boolean;
13263
owner: Owner;
133-
html_url: Link;
134-
description: string;
135-
fork: boolean;
136-
url: Link;
137-
forks_url: Link;
138-
keys_url: Link;
139-
collaborators_url: Link;
140-
teams_url: Link;
141-
hooks_url: Link;
142-
issue_events_url: Link;
143-
events_url: Link;
144-
assignees_url: Link;
145-
branches_url: Link;
146-
tags_url: Link;
147-
blobs_url: Link;
148-
git_tags_url: Link;
149-
git_refs_url: Link;
150-
trees_url: Link;
151-
statuses_url: Link;
152-
languages_url: Link;
153-
stargazers_url: Link;
154-
contributors_url: Link;
155-
subscribers_url: Link;
156-
subscription_url: Link;
157-
commits_url: Link;
158-
git_commits_url: Link;
159-
comments_url: Link;
160-
issue_comment_url: Link;
161-
contents_url: Link;
162-
compare_url: Link;
163-
merges_url: Link;
164-
archive_url: Link;
165-
downloads_url: Link;
166-
issues_url: Link;
167-
pulls_url: Link;
168-
milestones_url: Link;
169-
notifications_url: Link;
170-
labels_url: Link;
171-
releases_url: Link;
172-
deployments_url: Link;
173-
}
64+
};
17465

175-
export interface Owner {
176-
login: string;
177-
id: number;
178-
node_id: string;
66+
export type Owner = NonNullable<BaseRepository['owner']> & {
67+
type: UserType;
17968
avatar_url: Link;
180-
gravatar_id: string;
181-
url: Link;
182-
html_url: Link;
183-
followers_url: Link;
184-
following_url: Link;
185-
gists_url: Link;
186-
starred_url: Link;
187-
subscriptions_url: Link;
188-
organizations_url: Link;
189-
repos_url: Link;
190-
events_url: Link;
191-
received_events_url: Link;
69+
};
70+
type BaseRepository = components['schemas']['repository'];
71+
72+
export type Commit = Omit<BaseCommit, 'author'> & {
73+
author: BaseCommit['author'] extends null ? null : StrongCommitAuthor;
74+
};
75+
type BaseCommit = components['schemas']['commit'];
76+
type StrongCommitAuthor = NonNullable<BaseCommit['author']> & {
19277
type: UserType;
193-
site_admin: boolean;
194-
}
78+
};
19579

196-
// export type Commit = components['schemas']['commit'];
197-
export interface Commit {
198-
sha: string;
199-
node_id: string;
200-
commit: {
201-
author: CommitUser;
202-
committer: CommitUser;
203-
message: string;
204-
tree: {
205-
sha: string;
206-
url: Link;
207-
};
208-
url: Link;
209-
comment_count: number;
210-
verification: {
211-
verified: boolean;
212-
reason: string;
213-
signature: string | null;
214-
payload: string | null;
215-
};
216-
};
217-
url: Link;
218-
html_url: Link;
219-
comments_url: Link;
220-
author: User;
221-
committer: User;
222-
parents: CommitParent[];
223-
stats: {
224-
total: number;
225-
additions: number;
226-
deletions: number;
227-
};
228-
files: CommitFiles[];
229-
}
230-
231-
interface CommitUser {
232-
name: string;
233-
email: string;
234-
date: string;
235-
}
236-
237-
interface CommitParent {
238-
sha: string;
239-
url: Link;
240-
html_url: Link;
241-
}
242-
243-
interface CommitFiles {
244-
sha: string;
245-
filename: string;
246-
status: string;
247-
additions: number;
248-
deletions: number;
249-
changes: number;
250-
blob_url: Link;
251-
raw_url: Link;
252-
contents_url: Link;
253-
patch: string;
254-
}
80+
export type CommitComment = Omit<BaseCommitComment, 'user'> & {
81+
user: BaseCommitComment['user'] extends null ? null : StrongCommitCommentUser;
82+
};
83+
type BaseCommitComment = components['schemas']['commit-comment'];
84+
type StrongCommitCommentUser = NonNullable<BaseCommitComment['user']> & {
85+
type: UserType;
86+
};
25587

256-
export interface CommitComment {
257-
url: Link;
258-
html_url: Link;
259-
issue_url: Link;
260-
id: number;
261-
node_id: string;
262-
user: User;
263-
created_at: string;
264-
updated_at: string;
265-
body: string;
266-
}
88+
export type Release = Omit<BaseRelease, 'author'> & {
89+
author: BaseRelease['author'] extends null ? null : StrongReleaseAuthor;
90+
};
91+
type BaseRelease = components['schemas']['release'];
92+
type StrongReleaseAuthor = NonNullable<BaseRelease['author']> & {
93+
type: UserType;
94+
};
26795

268-
// export type Release = components['schemas']['release'];
269-
export interface Release {
270-
url: Link;
271-
assets_url: Link;
272-
upload_url: Link;
273-
html_url: Link;
274-
id: number;
275-
author: User;
276-
node_id: string;
277-
tag_name: string;
278-
target_commitish: string;
279-
name: string | null;
280-
body: string | null;
281-
draft: boolean;
282-
prerelease: boolean;
283-
created_at: string;
284-
published_at: string | null;
285-
}
96+
export type NotificationThreadSubscription =
97+
components['schemas']['thread-subscription'];
28698

28799
export interface GitHubRESTError {
288100
message: string;
289101
documentation_url: Link;
290102
}
291-
292-
// export type NotificationThreadSubscription =
293-
// components['schemas']['thread-subscription'];
294-
export interface NotificationThreadSubscription {
295-
subscribed: boolean;
296-
ignored: boolean;
297-
reason: string | null;
298-
created_at: string;
299-
url: Link;
300-
thread_url: Link;
301-
}

src/renderer/utils/notifications/handlers/commit.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { GitCommitIcon } from '@primer/octicons-react';
55

66
import type {
77
GitifyNotificationState,
8+
GitifyNotificationUser,
89
GitifySubject,
910
SettingsState,
1011
} from '../../../types';
11-
import type { Notification, Subject, User } from '../../../typesGitHub';
12+
import type { Notification, Subject } from '../../../typesGitHub';
1213
import { getCommit, getCommitComment } from '../../api/client';
1314
import { isStateFilteredOut } from '../filters/filter';
1415
import { DefaultHandler } from './default';
@@ -28,7 +29,7 @@ class CommitHandler extends DefaultHandler {
2829
return null;
2930
}
3031

31-
let user: User;
32+
let user: GitifyNotificationUser;
3233

3334
if (notification.subject.latest_comment_url) {
3435
const commitComment = (
@@ -38,13 +39,23 @@ class CommitHandler extends DefaultHandler {
3839
)
3940
).data;
4041

41-
user = commitComment.user;
42+
user = {
43+
login: commitComment.user.login,
44+
html_url: commitComment.user.html_url,
45+
avatar_url: commitComment.user.avatar_url,
46+
type: commitComment.user.type,
47+
};
4248
} else {
4349
const commit = (
4450
await getCommit(notification.subject.url, notification.account.token)
4551
).data;
4652

47-
user = commit.author;
53+
user = {
54+
login: commit.author.login,
55+
html_url: commit.author.html_url,
56+
avatar_url: commit.author.avatar_url,
57+
type: commit.author.type,
58+
};
4859
}
4960

5061
return {

src/renderer/utils/notifications/handlers/release.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ class ReleaseHandler extends DefaultHandler {
3535

3636
return {
3737
state: releaseState,
38-
user: getNotificationAuthor([release.author]),
38+
user: getNotificationAuthor([
39+
{
40+
login: release.author.login,
41+
html_url: release.author.html_url,
42+
avatar_url: release.author.avatar_url,
43+
type: release.author.type,
44+
},
45+
]),
3946
};
4047
}
4148

0 commit comments

Comments
 (0)