Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/typesGithub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
data: {
data: {
Expand Down
9 changes: 7 additions & 2 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {
GraphQLSearch,
DiscussionCommentNode,
DiscussionSearchResultNode,
PullRequest,
Issue,
IssueComments,
} from '../typesGithub';
import { apiRequestAuth } from '../utils/api-requests';
import { openExternalLink } from '../utils/comms';
Expand Down Expand Up @@ -66,9 +69,11 @@ export function formatSearchQueryString(
}

export async function getHtmlUrl(url: string, token: string): Promise<string> {
const response = await apiRequestAuth(url, 'GET', token);
const response: Issue | IssueComments | PullRequest = (
await apiRequestAuth(url, 'GET', token)
).data;

return response.data.html_url;
return response.html_url;
}

export function getCheckSuiteUrl(notification: Notification) {
Expand Down
15 changes: 10 additions & 5 deletions src/utils/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import {
DiscussionStateSearchResultNode,
DiscussionStateType,
GraphQLSearch,
Issue,
IssueStateReasonType,
IssueStateType,
Notification,
PullRequest,
PullRequestStateType,
StateType,
WorkflowRunAttributes,
Expand Down Expand Up @@ -129,9 +132,10 @@ export async function getDiscussionState(
export async function getIssueState(
notification: Notification,
token: string,
): Promise<IssueStateType> {
const issue = (await apiRequestAuth(notification.subject.url, 'GET', token))
.data;
): Promise<IssueStateType | IssueStateReasonType> {
const issue: Issue = (
await apiRequestAuth(notification.subject.url, 'GET', token)
).data;

return issue.state_reason ?? issue.state;
}
Expand All @@ -140,8 +144,9 @@ export async function getPullRequestState(
notification: Notification,
token: string,
): Promise<PullRequestStateType> {
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';
Expand Down