@@ -102,11 +102,10 @@ export async function listNotificationsForAuthenticatedUser(
102102 * Endpoint documentation: https://docs.github.com/en/rest/activity/notifications#mark-a-thread-as-read
103103 */
104104export async function markNotificationThreadAsRead (
105+ account : Account ,
105106 threadId : string ,
106- hostname : Hostname ,
107- token : Token ,
108107) : Promise < MarkNotificationThreadAsReadResponse > {
109- const octokit = await createOctokitClient ( hostname , token ) ;
108+ const octokit = await createOctokitClient ( account . hostname , account . token ) ;
110109
111110 const response = await octokit . rest . activity . markThreadAsRead ( {
112111 thread_id : Number ( threadId ) ,
@@ -124,11 +123,10 @@ export async function markNotificationThreadAsRead(
124123 * Endpoint documentation: https://docs.github.com/en/rest/activity/notifications#mark-a-thread-as-done
125124 */
126125export async function markNotificationThreadAsDone (
126+ account : Account ,
127127 threadId : string ,
128- hostname : Hostname ,
129- token : Token ,
130128) : Promise < MarkNotificationThreadAsDoneResponse > {
131- const octokit = await createOctokitClient ( hostname , token ) ;
129+ const octokit = await createOctokitClient ( account . hostname , account . token ) ;
132130
133131 const response = await octokit . rest . activity . markThreadAsDone ( {
134132 thread_id : Number ( threadId ) ,
@@ -143,11 +141,10 @@ export async function markNotificationThreadAsDone(
143141 * Endpoint documentation: https://docs.github.com/en/rest/activity/notifications#delete-a-thread-subscription
144142 */
145143export async function ignoreNotificationThreadSubscription (
144+ account : Account ,
146145 threadId : string ,
147- hostname : Hostname ,
148- token : Token ,
149146) : Promise < IgnoreNotificationThreadSubscriptionResponse > {
150- const octokit = await createOctokitClient ( hostname , token ) ;
147+ const octokit = await createOctokitClient ( account . hostname , account . token ) ;
151148
152149 const response = await octokit . rest . activity . setThreadSubscription ( {
153150 thread_id : Number ( threadId ) ,
@@ -163,31 +160,17 @@ export async function ignoreNotificationThreadSubscription(
163160 * Endpoint documentation: https://docs.github.com/en/rest/commits/commits#get-a-commit
164161 */
165162export async function getCommit (
163+ account : Account ,
166164 url : Link ,
167- token : Token ,
168165) : Promise < GetCommitResponse > {
169- // Parse URL: /repos/{owner}/{repo}/commits/{ref}
170- const urlObj = new URL ( url ) ;
171- const match = urlObj . pathname . match (
172- / ^ \/ r e p o s \/ (?< owner > [ ^ / ] + ) \/ (?< repo > [ ^ / ] + ) \/ c o m m i t s \/ (?< ref > .+ ) $ / ,
173- ) ;
166+ const octokit = await createOctokitClient ( account . hostname , account . token ) ;
174167
175- if ( ! match ?. groups ) {
176- throw new Error ( `Invalid commit URL format: ${ url } ` ) ;
177- }
178-
179- const { owner, repo, ref } = match . groups ;
180- const hostname = urlObj . hostname as Hostname ;
181-
182- const octokit = await createOctokitClient ( hostname , token ) ;
183-
184- const response = await octokit . rest . repos . getCommit ( {
185- owner,
186- repo,
187- ref,
168+ // Perform a generic GET request using Octokit's request method
169+ const response = await octokit . request ( 'GET {+url}' , {
170+ url : url ,
188171 } ) ;
189172
190- return response . data ;
173+ return response . data as GetCommitResponse ;
191174}
192175
193176/**
@@ -196,31 +179,17 @@ export async function getCommit(
196179 * Endpoint documentation: https://docs.github.com/en/rest/commits/comments#get-a-commit-comment
197180 */
198181export async function getCommitComment (
182+ account : Account ,
199183 url : Link ,
200- token : Token ,
201184) : Promise < GetCommitCommentResponse > {
202- // Parse URL: /repos/{owner}/{repo}/comments/{comment_id}
203- const urlObj = new URL ( url ) ;
204- const match = urlObj . pathname . match (
205- / ^ \/ r e p o s \/ (?< owner > [ ^ / ] + ) \/ (?< repo > [ ^ / ] + ) \/ c o m m e n t s \/ (?< commentId > \d + ) $ / ,
206- ) ;
207-
208- if ( ! match ?. groups ) {
209- throw new Error ( `Invalid commit comment URL format: ${ url } ` ) ;
210- }
185+ const octokit = await createOctokitClient ( account . hostname , account . token ) ;
211186
212- const { owner, repo, commentId } = match . groups ;
213- const hostname = urlObj . hostname as Hostname ;
214-
215- const octokit = await createOctokitClient ( hostname , token ) ;
216-
217- const response = await octokit . rest . repos . getCommitComment ( {
218- owner : owner ,
219- repo : repo ,
220- comment_id : Number ( commentId ) ,
187+ // Perform a generic GET request using Octokit's request method
188+ const response = await octokit . request ( 'GET {+url}' , {
189+ url : url ,
221190 } ) ;
222191
223- return response . data ;
192+ return response . data as GetCommitCommentResponse ;
224193}
225194
226195/**
@@ -229,45 +198,27 @@ export async function getCommitComment(
229198 * Endpoint documentation: https://docs.github.com/en/rest/releases/releases#get-a-release
230199 */
231200export async function getRelease (
201+ account : Account ,
232202 url : Link ,
233- token : Token ,
234203) : Promise < GetReleaseResponse > {
235- // Parse URL: /repos/{owner}/{repo}/releases/{release_id}
236- const urlObj = new URL ( url ) ;
237- const match = urlObj . pathname . match (
238- / ^ \/ r e p o s \/ (?< owner > [ ^ / ] + ) \/ (?< repo > [ ^ / ] + ) \/ r e l e a s e s \/ (?< releaseId > \d + ) $ / ,
239- ) ;
240-
241- if ( ! match ?. groups ) {
242- throw new Error ( `Invalid release URL format: ${ url } ` ) ;
243- }
244-
245- const { owner, repo, releaseId } = match . groups ;
246- const hostname = urlObj . hostname as Hostname ;
247-
248- const octokit = await createOctokitClient ( hostname , token ) ;
204+ const octokit = await createOctokitClient ( account . hostname , account . token ) ;
249205
250- const response = await octokit . rest . repos . getRelease ( {
251- owner : owner ,
252- repo : repo ,
253- release_id : Number ( releaseId ) ,
206+ // Perform a generic GET request using Octokit's request method
207+ const response = await octokit . request ( 'GET {+url}' , {
208+ url : url ,
254209 } ) ;
255210
256- return response . data ;
211+ return response . data as GetReleaseResponse ;
257212}
258213
259214/**
260215 * Get the `html_url` from the GitHub response
261216 */
262217export async function getHtmlUrl (
218+ account : Account ,
263219 url : Link ,
264- token : Token ,
265220) : Promise < GitHubHtmlUrlResponse > {
266- // Extract hostname from URL to determine which Octokit client to use
267- const urlObj = new URL ( url ) ;
268- const hostname = urlObj . hostname as Hostname ;
269-
270- const octokit = await createOctokitClient ( hostname , token ) ;
221+ const octokit = await createOctokitClient ( account . hostname , account . token ) ;
271222
272223 // Perform a generic GET request using Octokit's request method
273224 const response = await octokit . request ( 'GET {+url}' , {
@@ -277,6 +228,24 @@ export async function getHtmlUrl(
277228 return response . data as GitHubHtmlUrlResponse ;
278229}
279230
231+
232+ /**
233+ * Follow GitHub Response URL
234+ */
235+ export async function followUrl < TResult > (
236+ account : Account ,
237+ url : Link ,
238+ ) : Promise < TResult > {
239+ const octokit = await createOctokitClient ( account . hostname , account . token ) ;
240+
241+ // Perform a generic GET request using Octokit's request method
242+ const response = await octokit . request ( 'GET {+url}' , {
243+ url : url ,
244+ } ) ;
245+
246+ return response . data as TResult ;
247+ }
248+
280249/**
281250 * Fetch details of the currently authenticated GitHub user.
282251 */
0 commit comments