diff --git a/package.json b/package.json index c2055c98f..5848d2946 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7d7aa8ef4..1eaf67fc4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -57,6 +57,9 @@ importers: '@octokit/request': specifier: 10.0.7 version: 10.0.7 + '@octokit/types': + specifier: 16.0.0 + version: 16.0.0 '@parcel/watcher': specifier: 2.5.4 version: 2.5.4 diff --git a/src/renderer/utils/api/client.ts b/src/renderer/utils/api/client.ts index 9b07f9281..4f7d392c6 100644 --- a/src/renderer/utils/api/client.ts +++ b/src/renderer/utils/api/client.ts @@ -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'; @@ -54,7 +57,7 @@ import { export function headNotifications( hostname: Hostname, token: Token, -): AxiosPromise { +): AxiosPromise { const url = getGitHubAPIBaseUrl(hostname); url.pathname += 'notifications'; @@ -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 { +): AxiosPromise { const url = getGitHubAPIBaseUrl(account.hostname); url.pathname += 'notifications'; url.searchParams.append('participating', String(settings.participating)); @@ -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 { +): AxiosPromise { const url = getGitHubAPIBaseUrl(hostname); url.pathname += `notifications/threads/${threadId}`; @@ -113,7 +118,7 @@ export function markNotificationThreadAsDone( threadId: string, hostname: Hostname, token: Token, -): AxiosPromise { +): AxiosPromise { const url = getGitHubAPIBaseUrl(hostname); url.pathname += `notifications/threads/${threadId}`; @@ -129,7 +134,7 @@ export function ignoreNotificationThreadSubscription( threadId: string, hostname: Hostname, token: Token, -): AxiosPromise { +): AxiosPromise { const url = getGitHubAPIBaseUrl(hostname); url.pathname += `notifications/threads/${threadId}/subscription`; @@ -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 { +export function getCommit( + url: Link, + token: Token, +): AxiosPromise { 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 { +): AxiosPromise { return apiRequestAuth(url, 'GET', token); } @@ -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 { +export function getRelease( + url: Link, + token: Token, +): AxiosPromise { return apiRequestAuth(url, 'GET', token); } /** * Get the `html_url` from the GitHub response + * */ export async function getHtmlUrl(url: Link, token: Token): Promise { try { + // TODO - Add explicit type for response shape const response = (await apiRequestAuth(url, 'GET', token)).data; return response.html_url; diff --git a/src/renderer/utils/api/graphql/generated/graphql.ts b/src/renderer/utils/api/graphql/generated/graphql.ts index 24969e990..57a1d9b18 100644 --- a/src/renderer/utils/api/graphql/generated/graphql.ts +++ b/src/renderer/utils/api/graphql/generated/graphql.ts @@ -21652,6 +21652,7 @@ export type PullRequestSuggestedReviewerActorsArgs = { before?: InputMaybe; first?: InputMaybe; last?: InputMaybe; + query?: InputMaybe; }; diff --git a/src/renderer/utils/api/types.ts b/src/renderer/utils/api/types.ts index 2ada18d0b..d09cdd5e1 100644 --- a/src/renderer/utils/api/types.ts +++ b/src/renderer/utils/api/types.ts @@ -1,4 +1,5 @@ import type { components } from '@octokit/openapi-types'; +import type { Endpoints } from '@octokit/types'; import type { Link } from '../../types'; @@ -7,15 +8,37 @@ export interface GitHubRESTError { documentation_url: Link; } -export type NotificationThreadSubscription = - components['schemas']['thread-subscription']; +export type ListNotificationsForAuthenticatedUserResponse = + 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;