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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"@octokit/oauth-methods": "6.0.2",
"@octokit/openapi-types": "27.0.0",
"@octokit/request": "10.0.7",
"@octokit/types": "16.0.0",
"@parcel/watcher": "2.5.4",
"@primer/css": "22.1.0",
"@primer/octicons-react": "19.21.2",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 27 additions & 15 deletions src/renderer/utils/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import type {
Token,
} from '../../types';
import type {
NotificationThreadSubscription,
RawCommit,
RawCommitComment,
RawGitHubNotification,
RawRelease,
GetCommitCommentResponse,
GetCommitResponse,
GetReleaseResponse,
HeadNotificationsResponse,
IgnoreNotificationThreadSubscriptionResponse,
ListNotificationsForAuthenticatedUserResponse,
MarkNotificationThreadAsDoneResponse,
MarkNotificationThreadAsReadResponse,
} from './types';

import { isAnsweredDiscussionFeatureSupported } from '../features';
Expand Down Expand Up @@ -54,7 +57,7 @@ import {
export function headNotifications(
hostname: Hostname,
token: Token,
): AxiosPromise<void> {
): AxiosPromise<HeadNotificationsResponse> {
const url = getGitHubAPIBaseUrl(hostname);
url.pathname += 'notifications';

Expand All @@ -66,10 +69,11 @@ export function headNotifications(
*
* Endpoint documentation: https://docs.github.com/en/rest/activity/notifications#list-notifications-for-the-authenticated-user
*/

export function listNotificationsForAuthenticatedUser(
account: Account,
settings: SettingsState,
): AxiosPromise<RawGitHubNotification[]> {
): AxiosPromise<ListNotificationsForAuthenticatedUserResponse> {
const url = getGitHubAPIBaseUrl(account.hostname);
url.pathname += 'notifications';
url.searchParams.append('participating', String(settings.participating));
Expand All @@ -90,11 +94,12 @@ export function listNotificationsForAuthenticatedUser(
*
* Endpoint documentation: https://docs.github.com/en/rest/activity/notifications#mark-a-thread-as-read
*/

export function markNotificationThreadAsRead(
threadId: string,
hostname: Hostname,
token: Token,
): AxiosPromise<void> {
): AxiosPromise<MarkNotificationThreadAsReadResponse> {
const url = getGitHubAPIBaseUrl(hostname);
url.pathname += `notifications/threads/${threadId}`;

Expand All @@ -113,7 +118,7 @@ export function markNotificationThreadAsDone(
threadId: string,
hostname: Hostname,
token: Token,
): AxiosPromise<void> {
): AxiosPromise<MarkNotificationThreadAsDoneResponse> {
const url = getGitHubAPIBaseUrl(hostname);
url.pathname += `notifications/threads/${threadId}`;

Expand All @@ -129,7 +134,7 @@ export function ignoreNotificationThreadSubscription(
threadId: string,
hostname: Hostname,
token: Token,
): AxiosPromise<NotificationThreadSubscription> {
): AxiosPromise<IgnoreNotificationThreadSubscriptionResponse> {
const url = getGitHubAPIBaseUrl(hostname);
url.pathname += `notifications/threads/${threadId}/subscription`;

Expand All @@ -143,20 +148,22 @@ export function ignoreNotificationThreadSubscription(
*
* Endpoint documentation: https://docs.github.com/en/rest/commits/commits#get-a-commit
*/
export function getCommit(url: Link, token: Token): AxiosPromise<RawCommit> {
export function getCommit(
url: Link,
token: Token,
): AxiosPromise<GetCommitResponse> {
return apiRequestAuth(url, 'GET', token);
}

/**
* Gets a specified commit comment.
*
*
* Endpoint documentation: https://docs.github.com/en/rest/commits/comments#get-a-commit-comment

*/
export function getCommitComment(
url: Link,
token: Token,
): AxiosPromise<RawCommitComment> {
): AxiosPromise<GetCommitCommentResponse> {
return apiRequestAuth(url, 'GET', token);
}

Expand All @@ -165,15 +172,20 @@ export function getCommitComment(
*
* Endpoint documentation: https://docs.github.com/en/rest/releases/releases#get-a-release
*/
export function getRelease(url: Link, token: Token): AxiosPromise<RawRelease> {
export function getRelease(
url: Link,
token: Token,
): AxiosPromise<GetReleaseResponse> {
return apiRequestAuth(url, 'GET', token);
}

/**
* Get the `html_url` from the GitHub response
*
*/
export async function getHtmlUrl(url: Link, token: Token): Promise<string> {
try {
// TODO - Add explicit type for response shape
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a TODO which I intend to clean up via #2545

const response = (await apiRequestAuth(url, 'GET', token)).data;

return response.html_url;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/utils/api/graphql/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21652,6 +21652,7 @@ export type PullRequestSuggestedReviewerActorsArgs = {
before?: InputMaybe<Scalars['String']['input']>;
first?: InputMaybe<Scalars['Int']['input']>;
last?: InputMaybe<Scalars['Int']['input']>;
query?: InputMaybe<Scalars['String']['input']>;
};


Expand Down
35 changes: 29 additions & 6 deletions src/renderer/utils/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { components } from '@octokit/openapi-types';
import type { Endpoints } from '@octokit/types';

import type { Link } from '../../types';

Expand All @@ -7,15 +8,37 @@ export interface GitHubRESTError {
documentation_url: Link;
}

export type NotificationThreadSubscription =
components['schemas']['thread-subscription'];
export type ListNotificationsForAuthenticatedUserResponse =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More explicit use of GitHub REST HTTP verb and path to its response types

Endpoints['GET /notifications']['response']['data'];

export type RawCommit = components['schemas']['commit'];
export type IgnoreNotificationThreadSubscriptionResponse =
Endpoints['PUT /notifications/threads/{thread_id}/subscription']['response']['data'];

export type RawCommitComment = components['schemas']['commit-comment'];
export type GetCommitResponse =
Endpoints['GET /repos/{owner}/{repo}/commits/{ref}']['response']['data'];

export type RawGitHubNotification = components['schemas']['thread'];
export type GetCommitCommentResponse =
Endpoints['GET /repos/{owner}/{repo}/comments/{comment_id}']['response']['data'];

export type RawRelease = components['schemas']['release'];
export type GetReleaseResponse =
Endpoints['GET /repos/{owner}/{repo}/releases/{release_id}']['response']['data'];

export type RawGitHubNotification =
Endpoints['GET /notifications']['response']['data'][number];

export type RawUser = components['schemas']['simple-user'];

/**
* These API endpoints don't return a response body:
* - HEAD /notifications
* - Endpoints['PATCH /notifications/threads/{thread_id}']['response']['data']
* - Endpoints['DELETE /notifications/threads/{thread_id}']['response']['data']
*/
// biome-ignore lint/suspicious/noConfusingVoidType: This endpoint has no response body
export type HeadNotificationsResponse = void;

// biome-ignore lint/suspicious/noConfusingVoidType: This endpoint has no response body
export type MarkNotificationThreadAsReadResponse = void;

// biome-ignore lint/suspicious/noConfusingVoidType: This endpoint has no response body
export type MarkNotificationThreadAsDoneResponse = void;