Skip to content
Draft
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
13 changes: 8 additions & 5 deletions src/renderer/components/metrics/MetricGroup.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { renderWithAppContext } from '../../__helpers__/test-utils';
import { mockSettings } from '../../__mocks__/state-mocks';
import type { Milestone } from '../../typesGitHub';
import { mockSingleNotification } from '../../utils/api/__mocks__/response-mocks';
import {
type MilestoneFieldsFragment,
MilestoneState,
} from '../../utils/api/graphql/generated/graphql';
import { MetricGroup } from './MetricGroup';

describe('renderer/components/metrics/MetricGroup.tsx', () => {
Expand Down Expand Up @@ -103,8 +106,8 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {
const mockNotification = mockSingleNotification;
mockNotification.subject.milestone = {
title: 'Milestone 1',
state: 'open',
} as Milestone;
state: MilestoneState.Open,
} as MilestoneFieldsFragment;

const props = {
notification: mockNotification,
Expand All @@ -118,8 +121,8 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {
const mockNotification = mockSingleNotification;
mockNotification.subject.milestone = {
title: 'Milestone 1',
state: 'closed',
} as Milestone;
state: MilestoneState.Closed,
} as MilestoneFieldsFragment;

const props = {
notification: mockNotification,
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/metrics/MetricGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { AppContext } from '../../context/App';
import { IconColor } from '../../types';
import type { Notification } from '../../typesGitHub';
import { MilestoneState } from '../../utils/api/graphql/generated/graphql';
import { getPullRequestReviewIcon } from '../../utils/icons';
import { MetricPill } from './MetricPill';

Expand Down Expand Up @@ -84,7 +85,7 @@ export const MetricGroup: FC<MetricGroupProps> = ({
{notification.subject.milestone && (
<MetricPill
color={
notification.subject.milestone.state === 'open'
notification.subject.milestone.state === MilestoneState.Open
? IconColor.GREEN
: IconColor.RED
}
Expand Down
21 changes: 13 additions & 8 deletions src/renderer/typesGitHub.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import type { Account, Link } from './types';
import type {
AuthorFieldsFragment,
IssueState,
IssueStateReason,
MilestoneFieldsFragment,
PullRequestState,
} from './utils/api/graphql/generated/graphql';

export type Reason =
| 'approval_requested'
Expand Down Expand Up @@ -60,7 +67,10 @@ export type StateType =
| DiscussionStateType
| IssueStateType
| IssueStateReasonType
| PullRequestStateType;
| PullRequestStateType
| IssueState
| IssueStateReason
| PullRequestState;

export type CheckSuiteStatus =
| 'action_required'
Expand Down Expand Up @@ -169,12 +179,7 @@ export interface User {
site_admin: boolean;
}

export interface SubjectUser {
login: string;
html_url: Link;
avatar_url: Link;
type: UserType;
}
export type SubjectUser = AuthorFieldsFragment;

export interface Repository {
id: number;
Expand Down Expand Up @@ -264,7 +269,7 @@ export interface GitifySubject {
linkedIssues?: string[];
comments?: number;
labels?: string[];
milestone?: Milestone;
milestone?: MilestoneFieldsFragment;
}

export interface PullRequest {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/utils/api/__mocks__/response-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export const mockDiscussionByNumberGraphQLResponse: FetchDiscussionByNumberQuery
url: 'https://github.com/gitify-app/notifications-test/discussions/612' as Link,
author: {
login: 'comment-user',
url: 'https://github.com/comment-user' as Link,
html_url: 'https://github.com/comment-user' as Link,
avatar_url:
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
type: 'User',
Expand All @@ -393,7 +393,7 @@ export const mockDiscussionByNumberGraphQLResponse: FetchDiscussionByNumberQuery
createdAt: '2017-02-20T17:51:57Z',
author: {
login: 'comment-user',
url: 'https://github.com/comment-user' as Link,
html_url: 'https://github.com/comment-user' as Link,
avatar_url:
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
type: 'User',
Expand All @@ -405,7 +405,7 @@ export const mockDiscussionByNumberGraphQLResponse: FetchDiscussionByNumberQuery
createdAt: '2017-05-20T17:51:57Z',
author: {
login: 'reply-user',
url: 'https://github.com/reply-user' as Link,
html_url: 'https://github.com/reply-user' as Link,
avatar_url:
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
type: 'User',
Expand Down
103 changes: 49 additions & 54 deletions src/renderer/utils/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ import type {
import type {
Commit,
CommitComment,
Issue,
IssueOrPullRequestComment,
Notification,
NotificationThreadSubscription,
PullRequest,
PullRequestReview,
Release,
UserDetails,
} from '../../typesGitHub';
Expand All @@ -25,6 +21,10 @@ import { rendererLogError } from '../logger';
import {
FetchDiscussionByNumberDocument,
type FetchDiscussionByNumberQuery,
FetchIssueByNumberDocument,
type FetchIssueByNumberQuery,
FetchPullByNumberDocument,
type FetchPullByNumberQuery,
} from './graphql/generated/graphql';
import { apiRequestAuth, performGraphQLRequest } from './request';
import {
Expand Down Expand Up @@ -161,52 +161,6 @@ export function getCommitComment(
return apiRequestAuth(url, 'GET', token);
}

/**
* Get details of an issue.
*
* Endpoint documentation: https://docs.github.com/en/rest/issues/issues#get-an-issue
*/
export function getIssue(url: Link, token: Token): AxiosPromise<Issue> {
return apiRequestAuth(url, 'GET', token);
}

/**
* Get comments on issues and pull requests.
* Every pull request is an issue, but not every issue is a pull request.
*
* Endpoint documentation: https://docs.github.com/en/rest/issues/comments#get-an-issue-comment
*/
export function getIssueOrPullRequestComment(
url: Link,
token: Token,
): AxiosPromise<IssueOrPullRequestComment> {
return apiRequestAuth(url, 'GET', token);
}

/**
* Get details of a pull request.
*
* Endpoint documentation: https://docs.github.com/en/rest/pulls/pulls#get-a-pull-request
*/
export function getPullRequest(
url: Link,
token: Token,
): AxiosPromise<PullRequest> {
return apiRequestAuth(url, 'GET', token);
}

/**
* Lists all reviews for a specified pull request. The list of reviews returns in chronological order.
*
* Endpoint documentation: https://docs.github.com/en/rest/pulls/reviews#list-reviews-for-a-pull-request
*/
export function getPullRequestReviews(
url: Link,
token: Token,
): AxiosPromise<PullRequestReview[]> {
return apiRequestAuth(url, 'GET', token);
}

/**
* Gets a public release with the specified release ID.
*
Expand Down Expand Up @@ -234,10 +188,51 @@ export async function getHtmlUrl(url: Link, token: Token): Promise<string> {
}

/**
* Search for Discussions that match notification title and repository.
*
* Returns the latest discussion and their latest comments / replies
*
* Fetch GitHub Issue by Issue Number.
*/
export async function fetchIssueByNumber(
notification: Notification,
): Promise<ExecutionResult<FetchIssueByNumberQuery>> {
const url = getGitHubGraphQLUrl(notification.account.hostname);
const number = getNumberFromUrl(notification.subject.url);

return performGraphQLRequest(
url.toString() as Link,
notification.account.token,
FetchIssueByNumberDocument,
{
owner: notification.repository.owner.login,
name: notification.repository.name,
number: number,
firstLabels: 100,
},
);
}

/**
* Fetch GitHub Pull Request by PR Number.
*/
export async function fetchPullByNumber(
notification: Notification,
): Promise<ExecutionResult<FetchPullByNumberQuery>> {
const url = getGitHubGraphQLUrl(notification.account.hostname);
const number = getNumberFromUrl(notification.subject.url);

return performGraphQLRequest(
url.toString() as Link,
notification.account.token,
FetchPullByNumberDocument,
{
owner: notification.repository.owner.login,
name: notification.repository.name,
number: number,
firstLabels: 100,
},
);
}

/**
* Fetch GitHub Discussion by Discussion Number.
*/
export async function fetchDiscussionByNumber(
notification: Notification,
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/utils/api/graphql/common.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fragment AuthorFields on Actor {
login
html_url: url
avatar_url: avatarUrl
type: __typename
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ query FetchDiscussionByNumber(
}
}

fragment AuthorFields on Actor {
login
url
avatar_url: avatarUrl
type: __typename
}

fragment CommentFields on DiscussionComment {
databaseId
createdAt
Expand Down
Loading
Loading