From a016beee81a7935487a566887b97f939d2e525ac Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 10 Mar 2024 16:10:30 -0400 Subject: [PATCH 1/2] feat: add types for issue, pullrequest and issuecomments --- src/typesGithub.ts | 73 ++++++++++++++++++++++++++++++++++++++++++++ src/utils/helpers.ts | 9 ++++-- src/utils/state.ts | 15 ++++++--- 3 files changed, 90 insertions(+), 7 deletions(-) diff --git a/src/typesGithub.ts b/src/typesGithub.ts index 2f46d0153..a60293913 100644 --- a/src/typesGithub.ts +++ b/src/typesGithub.ts @@ -165,6 +165,79 @@ export interface Subject { type: SubjectType; } +export interface PullRequest { + url: string; + id: number; + node_id: string; + html_url: string; + diff_url: string; + patch_url: string; + issue_url: string; + number: number; + state: PullRequestStateType; + locked: boolean; + title: string; + user: User; + body: string; + created_at: string; + updated_at: string; + closed_at: string | null; + merged_at: string | null; + merge_commit_sha: string | null; + draft: boolean; + commits_url: string; + review_comments_url: string; + review_comment_url: string; + comments_url: string; + statuses_url: string; + author_association: string; + merged: boolean; + mergeable: boolean; + rebaseable: boolean; + comments: number; + review_comments: number; + maintainer_can_modify: boolean; + commits: number; + additions: number; + deletions: number; + changed_files: number; +} + +export interface Issue { + url: string; + repository_url: string; + labels_url: string; + comments_url: string; + events_url: string; + html_url: string; + id: number; + node_id: string; + number: number; + title: string; + user: User; + state: IssueStateType; + locked: boolean; + comments: number; + created_at: string; + updated_at: string; + closed_at: string | null; + author_association: string; + body: string; + state_reason: IssueStateReasonType | null; +} + +export interface IssueComments { + url: string; + html_url: string; + issue_url: string; + id: number; + node_id: string; + user: User; + created_at: string; + updated_at: string; + body: string; +} + export interface GraphQLSearch { data: { data: { diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 322fb6286..0b1a7f85d 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -4,6 +4,9 @@ import { GraphQLSearch, DiscussionCommentNode, DiscussionSearchResultNode, + PullRequest, + Issue, + IssueComments, } from '../typesGithub'; import { apiRequestAuth } from '../utils/api-requests'; import { openExternalLink } from '../utils/comms'; @@ -66,9 +69,11 @@ export function formatSearchQueryString( } export async function getHtmlUrl(url: string, token: string): Promise { - const response = await apiRequestAuth(url, 'GET', token); + const response: PullRequest | Issue | IssueComments = ( + await apiRequestAuth(url, 'GET', token) + ).data; - return response.data.html_url; + return response.html_url; } export function getCheckSuiteUrl(notification: Notification) { diff --git a/src/utils/state.ts b/src/utils/state.ts index ad783e894..9680f133b 100644 --- a/src/utils/state.ts +++ b/src/utils/state.ts @@ -5,8 +5,11 @@ import { DiscussionStateSearchResultNode, DiscussionStateType, GraphQLSearch, + Issue, + IssueStateReasonType, IssueStateType, Notification, + PullRequest, PullRequestStateType, StateType, WorkflowRunAttributes, @@ -129,9 +132,10 @@ export async function getDiscussionState( export async function getIssueState( notification: Notification, token: string, -): Promise { - const issue = (await apiRequestAuth(notification.subject.url, 'GET', token)) - .data; +): Promise { + const issue: Issue = ( + await apiRequestAuth(notification.subject.url, 'GET', token) + ).data; return issue.state_reason ?? issue.state; } @@ -140,8 +144,9 @@ export async function getPullRequestState( notification: Notification, token: string, ): Promise { - const pr = (await apiRequestAuth(notification.subject.url, 'GET', token)) - .data; + const pr: PullRequest = ( + await apiRequestAuth(notification.subject.url, 'GET', token) + ).data; if (pr.merged) { return 'merged'; From 033083abf215c319315fcad44c43cc5c63a1086c Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 10 Mar 2024 16:11:34 -0400 Subject: [PATCH 2/2] feat: add types for issue, pullrequest and issuecomments --- src/utils/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 0b1a7f85d..d5ddb2a51 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -69,7 +69,7 @@ export function formatSearchQueryString( } export async function getHtmlUrl(url: string, token: string): Promise { - const response: PullRequest | Issue | IssueComments = ( + const response: Issue | IssueComments | PullRequest = ( await apiRequestAuth(url, 'GET', token) ).data;