Skip to content

Commit 8ab6077

Browse files
setchyadufr
authored andcommitted
feat: add types for issue, pullrequest and issuecomments (gitify-app#871)
1 parent 8da7383 commit 8ab6077

File tree

3 files changed

+90
-7
lines changed

3 files changed

+90
-7
lines changed

src/typesGithub.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,79 @@ export interface Subject {
165165
type: SubjectType;
166166
}
167167

168+
export interface PullRequest {
169+
url: string;
170+
id: number;
171+
node_id: string;
172+
html_url: string;
173+
diff_url: string;
174+
patch_url: string;
175+
issue_url: string;
176+
number: number;
177+
state: PullRequestStateType;
178+
locked: boolean;
179+
title: string;
180+
user: User;
181+
body: string;
182+
created_at: string;
183+
updated_at: string;
184+
closed_at: string | null;
185+
merged_at: string | null;
186+
merge_commit_sha: string | null;
187+
draft: boolean;
188+
commits_url: string;
189+
review_comments_url: string;
190+
review_comment_url: string;
191+
comments_url: string;
192+
statuses_url: string;
193+
author_association: string;
194+
merged: boolean;
195+
mergeable: boolean;
196+
rebaseable: boolean;
197+
comments: number;
198+
review_comments: number;
199+
maintainer_can_modify: boolean;
200+
commits: number;
201+
additions: number;
202+
deletions: number;
203+
changed_files: number;
204+
}
205+
206+
export interface Issue {
207+
url: string;
208+
repository_url: string;
209+
labels_url: string;
210+
comments_url: string;
211+
events_url: string;
212+
html_url: string;
213+
id: number;
214+
node_id: string;
215+
number: number;
216+
title: string;
217+
user: User;
218+
state: IssueStateType;
219+
locked: boolean;
220+
comments: number;
221+
created_at: string;
222+
updated_at: string;
223+
closed_at: string | null;
224+
author_association: string;
225+
body: string;
226+
state_reason: IssueStateReasonType | null;
227+
}
228+
229+
export interface IssueComments {
230+
url: string;
231+
html_url: string;
232+
issue_url: string;
233+
id: number;
234+
node_id: string;
235+
user: User;
236+
created_at: string;
237+
updated_at: string;
238+
body: string;
239+
}
240+
168241
export interface GraphQLSearch<T> {
169242
data: {
170243
data: {

src/utils/helpers.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import {
44
GraphQLSearch,
55
DiscussionCommentNode,
66
DiscussionSearchResultNode,
7+
PullRequest,
8+
Issue,
9+
IssueComments,
710
} from '../typesGithub';
811
import { apiRequestAuth } from '../utils/api-requests';
912
import { openExternalLink } from '../utils/comms';
@@ -66,9 +69,11 @@ export function formatSearchQueryString(
6669
}
6770

6871
export async function getHtmlUrl(url: string, token: string): Promise<string> {
69-
const response = await apiRequestAuth(url, 'GET', token);
72+
const response: Issue | IssueComments | PullRequest = (
73+
await apiRequestAuth(url, 'GET', token)
74+
).data;
7075

71-
return response.data.html_url;
76+
return response.html_url;
7277
}
7378

7479
export function getCheckSuiteUrl(notification: Notification) {

src/utils/state.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import {
55
DiscussionStateSearchResultNode,
66
DiscussionStateType,
77
GraphQLSearch,
8+
Issue,
9+
IssueStateReasonType,
810
IssueStateType,
911
Notification,
12+
PullRequest,
1013
PullRequestStateType,
1114
StateType,
1215
WorkflowRunAttributes,
@@ -129,9 +132,10 @@ export async function getDiscussionState(
129132
export async function getIssueState(
130133
notification: Notification,
131134
token: string,
132-
): Promise<IssueStateType> {
133-
const issue = (await apiRequestAuth(notification.subject.url, 'GET', token))
134-
.data;
135+
): Promise<IssueStateType | IssueStateReasonType> {
136+
const issue: Issue = (
137+
await apiRequestAuth(notification.subject.url, 'GET', token)
138+
).data;
135139

136140
return issue.state_reason ?? issue.state;
137141
}
@@ -140,8 +144,9 @@ export async function getPullRequestState(
140144
notification: Notification,
141145
token: string,
142146
): Promise<PullRequestStateType> {
143-
const pr = (await apiRequestAuth(notification.subject.url, 'GET', token))
144-
.data;
147+
const pr: PullRequest = (
148+
await apiRequestAuth(notification.subject.url, 'GET', token)
149+
).data;
145150

146151
if (pr.merged) {
147152
return 'merged';

0 commit comments

Comments
 (0)