1+ import type { OctokitResponse } from '@octokit/plugin-paginate-rest/dist-types/types' ;
2+
13import { Constants } from '../../constants' ;
24
35import type {
46 Account ,
57 GitifyNotification ,
6- Hostname ,
78 Link ,
89 SettingsState ,
9- Token ,
1010} from '../../types' ;
1111import type { GitHubGraphQLResponse } from './graphql/types' ;
1212import type {
@@ -36,19 +36,17 @@ import {
3636import { MergeQueryBuilder } from './graphql/MergeQueryBuilder' ;
3737import { createOctokitClient } from './octokit' ;
3838import { performGraphQLRequest , performGraphQLRequestString } from './request' ;
39- import { getGitHubGraphQLUrl , getNumberFromUrl } from './utils' ;
40- import { OctokitResponse } from '@octokit/plugin-paginate-rest/dist-types/types' ;
39+ import { getNumberFromUrl } from './utils' ;
4140
4241/**
4342 * Perform a HEAD operation, used to validate that connectivity is established.
4443 *
4544 * Endpoint documentation: https://docs.github.com/en/rest/activity/notifications
4645 */
4746export async function headNotifications (
48- hostname : Hostname ,
49- token : Token ,
47+ account : Account ,
5048) : Promise < HeadNotificationsResponse > {
51- const octokit = await createOctokitClient ( hostname , token ) ;
49+ const octokit = await createOctokitClient ( account ) ;
5250
5351 await octokit . rest . activity . listNotificationsForAuthenticatedUser ( {
5452 per_page : 1 ,
@@ -64,7 +62,7 @@ export async function listNotificationsForAuthenticatedUser(
6462 account : Account ,
6563 settings : SettingsState ,
6664) : Promise < ListNotificationsForAuthenticatedUserResponse > {
67- const octokit = await createOctokitClient ( account . hostname , account . token ) ;
65+ const octokit = await createOctokitClient ( account ) ;
6866
6967 if ( settings . fetchAllNotifications ) {
7068 // Fetch all pages using Octokit's pagination
@@ -107,7 +105,7 @@ export async function markNotificationThreadAsRead(
107105 account : Account ,
108106 threadId : string ,
109107) : Promise < MarkNotificationThreadAsReadResponse > {
110- const octokit = await createOctokitClient ( account . hostname , account . token ) ;
108+ const octokit = await createOctokitClient ( account ) ;
111109
112110 const response = await octokit . rest . activity . markThreadAsRead ( {
113111 thread_id : Number ( threadId ) ,
@@ -128,7 +126,7 @@ export async function markNotificationThreadAsDone(
128126 account : Account ,
129127 threadId : string ,
130128) : Promise < MarkNotificationThreadAsDoneResponse > {
131- const octokit = await createOctokitClient ( account . hostname , account . token ) ;
129+ const octokit = await createOctokitClient ( account ) ;
132130
133131 const response = await octokit . rest . activity . markThreadAsDone ( {
134132 thread_id : Number ( threadId ) ,
@@ -146,7 +144,7 @@ export async function ignoreNotificationThreadSubscription(
146144 account : Account ,
147145 threadId : string ,
148146) : Promise < IgnoreNotificationThreadSubscriptionResponse > {
149- const octokit = await createOctokitClient ( account . hostname , account . token ) ;
147+ const octokit = await createOctokitClient ( account ) ;
150148
151149 const response = await octokit . rest . activity . setThreadSubscription ( {
152150 thread_id : Number ( threadId ) ,
@@ -165,7 +163,7 @@ export async function getCommit(
165163 account : Account ,
166164 url : Link ,
167165) : Promise < GetCommitResponse > {
168- const octokit = await createOctokitClient ( account . hostname , account . token ) ;
166+ const octokit = await createOctokitClient ( account ) ;
169167
170168 // Perform a generic GET request using Octokit's request method
171169 const response = await octokit . request ( 'GET {+url}' , {
@@ -184,7 +182,7 @@ export async function getCommitComment(
184182 account : Account ,
185183 url : Link ,
186184) : Promise < GetCommitCommentResponse > {
187- const octokit = await createOctokitClient ( account . hostname , account . token ) ;
185+ const octokit = await createOctokitClient ( account ) ;
188186
189187 // Perform a generic GET request using Octokit's request method
190188 const response = await octokit . request ( 'GET {+url}' , {
@@ -203,7 +201,7 @@ export async function getRelease(
203201 account : Account ,
204202 url : Link ,
205203) : Promise < GetReleaseResponse > {
206- const octokit = await createOctokitClient ( account . hostname , account . token ) ;
204+ const octokit = await createOctokitClient ( account ) ;
207205
208206 // Perform a generic GET request using Octokit's request method
209207 const response = await octokit . request ( 'GET {+url}' , {
@@ -220,7 +218,7 @@ export async function getHtmlUrl(
220218 account : Account ,
221219 url : Link ,
222220) : Promise < GitHubHtmlUrlResponse > {
223- const octokit = await createOctokitClient ( account . hostname , account . token ) ;
221+ const octokit = await createOctokitClient ( account ) ;
224222
225223 // Perform a generic GET request using Octokit's request method
226224 const response = await octokit . request ( 'GET {+url}' , {
@@ -230,15 +228,14 @@ export async function getHtmlUrl(
230228 return response . data as GitHubHtmlUrlResponse ;
231229}
232230
233-
234231/**
235232 * Follow GitHub Response URL
236233 */
237234export async function followUrl < TResult > (
238235 account : Account ,
239236 url : Link ,
240237) : Promise < TResult > {
241- const octokit = await createOctokitClient ( account . hostname , account . token ) ;
238+ const octokit = await createOctokitClient ( account ) ;
242239
243240 // Perform a generic GET request using Octokit's request method
244241 const response = await octokit . request ( 'GET {+url}' , {
@@ -252,12 +249,11 @@ export async function followUrl<TResult>(
252249 * Fetch details of the currently authenticated GitHub user.
253250 */
254251export async function fetchAuthenticatedUserDetails (
255- hostname : Hostname ,
256- token : Token ,
252+ account : Account ,
257253) : Promise < OctokitResponse < GetAuthenticatedUserResponse > > {
258- const octokit = await createOctokitClient ( hostname , token ) ;
254+ const octokit = await createOctokitClient ( account ) ;
259255
260- const response = await octokit . rest . users . getAuthenticated ( )
256+ const response = await octokit . rest . users . getAuthenticated ( ) ;
261257
262258 return response ;
263259}
@@ -268,12 +264,10 @@ export async function fetchAuthenticatedUserDetails(
268264export async function fetchDiscussionByNumber (
269265 notification : GitifyNotification ,
270266) : Promise < GitHubGraphQLResponse < FetchDiscussionByNumberQuery > > {
271- const url = getGitHubGraphQLUrl ( notification . account . hostname ) ;
272267 const number = getNumberFromUrl ( notification . subject . url ) ;
273268
274269 return performGraphQLRequest (
275- url . toString ( ) as Link ,
276- notification . account . token ,
270+ notification . account ,
277271 FetchDiscussionByNumberDocument ,
278272 {
279273 owner : notification . repository . owner . login ,
@@ -295,12 +289,10 @@ export async function fetchDiscussionByNumber(
295289export async function fetchIssueByNumber (
296290 notification : GitifyNotification ,
297291) : Promise < GitHubGraphQLResponse < FetchIssueByNumberQuery > > {
298- const url = getGitHubGraphQLUrl ( notification . account . hostname ) ;
299292 const number = getNumberFromUrl ( notification . subject . url ) ;
300293
301294 return performGraphQLRequest (
302- url . toString ( ) as Link ,
303- notification . account . token ,
295+ notification . account ,
304296 FetchIssueByNumberDocument ,
305297 {
306298 owner : notification . repository . owner . login ,
@@ -318,12 +310,10 @@ export async function fetchIssueByNumber(
318310export async function fetchPullByNumber (
319311 notification : GitifyNotification ,
320312) : Promise < GitHubGraphQLResponse < FetchPullRequestByNumberQuery > > {
321- const url = getGitHubGraphQLUrl ( notification . account . hostname ) ;
322313 const number = getNumberFromUrl ( notification . subject . url ) ;
323314
324315 return performGraphQLRequest (
325- url . toString ( ) as Link ,
326- notification . account . token ,
316+ notification . account ,
327317 FetchPullRequestByNumberDocument ,
328318 {
329319 owner : notification . repository . owner . login ,
@@ -399,11 +389,8 @@ export async function fetchNotificationDetailsForList(
399389 const query = builder . getGraphQLQuery ( ) ;
400390 const variables = builder . getGraphQLVariables ( ) ;
401391
402- const url = getGitHubGraphQLUrl ( notifications [ 0 ] . account . hostname ) ;
403-
404392 const response = await performGraphQLRequestString (
405- url . toString ( ) as Link ,
406- notifications [ 0 ] . account . token ,
393+ notifications [ 0 ] . account ,
407394 query ,
408395 variables ,
409396 ) ;
0 commit comments