@@ -58,16 +58,24 @@ export class CopilotApi {
5858 return 'https://api.githubcopilot.com' ;
5959 }
6060
61+ private async makeApiCallFullUrl ( url : string , init : RequestInit ) : Promise < Response > {
62+ const apiCall = ( ) => fetch ( url , init ) ;
63+ return this . octokit . call ( apiCall ) ;
64+ }
65+ private async makeApiCall ( api : string , init : RequestInit ) : Promise < Response > {
66+ return this . makeApiCallFullUrl ( `${ this . baseUrl } ${ api } ` , init ) ;
67+ }
68+
6169 async postRemoteAgentJob (
6270 owner : string ,
6371 name : string ,
6472 payload : RemoteAgentJobPayload ,
6573 ) : Promise < RemoteAgentJobResponse > {
6674 const repoSlug = `${ owner } /${ name } ` ;
67- const apiUrl = `${ this . baseUrl } /agents/swe/v0/jobs/${ repoSlug } ` ;
75+ const apiUrl = `/agents/swe/v0/jobs/${ repoSlug } ` ;
6876 let status : number | undefined ;
6977 try {
70- const response = await fetch ( apiUrl , {
78+ const response = await this . makeApiCall ( apiUrl , {
7179 method : 'POST' ,
7280 headers : {
7381 'Copilot-Integration-Id' : 'copilot-developer-dev' ,
@@ -147,7 +155,7 @@ export class CopilotApi {
147155 }
148156
149157 public async getLogsFromZipUrl ( logsUrl : string ) : Promise < string [ ] > {
150- const logsZip = await fetch ( logsUrl , {
158+ const logsZip = await this . makeApiCallFullUrl ( logsUrl , {
151159 headers : {
152160 Authorization : `Bearer ${ this . token } ` ,
153161 Accept : 'application/json' ,
@@ -170,10 +178,10 @@ export class CopilotApi {
170178 }
171179
172180 public async getAllSessions ( pullRequestId : number | undefined ) : Promise < SessionInfo [ ] > {
173- const response = await fetch (
181+ const response = await this . makeApiCall (
174182 pullRequestId
175- ? `https://api.githubcopilot.com /agents/sessions/resource/pull/${ pullRequestId } `
176- : 'https://api.githubcopilot.com/ agents/sessions' ,
183+ ? `/agents/sessions/resource/pull/${ pullRequestId } `
184+ : `/ agents/sessions` ,
177185 {
178186 headers : {
179187 Authorization : `Bearer ${ this . token } ` ,
@@ -205,7 +213,7 @@ export class CopilotApi {
205213 }
206214
207215 public async getSessionInfo ( sessionId : string ) : Promise < SessionInfo > {
208- const response = await fetch ( `https://api.githubcopilot.com /agents/sessions/${ sessionId } `, {
216+ const response = await this . makeApiCall ( ` /agents/sessions/${ sessionId } `, {
209217 method : 'GET' ,
210218 headers : {
211219 Authorization : `Bearer ${ this . token } ` ,
@@ -220,7 +228,7 @@ export class CopilotApi {
220228 }
221229
222230 public async getLogsFromSession ( sessionId : string ) : Promise < string > {
223- const logsResponse = await fetch ( `https://api.githubcopilot.com /agents/sessions/${ sessionId } /logs`, {
231+ const logsResponse = await this . makeApiCall ( ` /agents/sessions/${ sessionId } /logs`, {
224232 method : 'GET' ,
225233 headers : {
226234 'Authorization' : `Bearer ${ this . token } ` ,
@@ -235,7 +243,7 @@ export class CopilotApi {
235243
236244 public async getJobBySessionId ( owner : string , repo : string , sessionId : string ) : Promise < JobInfo | undefined > {
237245 try {
238- const response = await fetch ( ` ${ this . baseUrl } /agents/swe/v0/jobs/${ owner } /${ repo } /session/${ sessionId } `, {
246+ const response = await this . makeApiCall ( ` /agents/swe/v0/jobs/${ owner } /${ repo } /session/${ sessionId } `, {
239247 method : 'GET' ,
240248 headers : {
241249 'Copilot-Integration-Id' : 'copilot-developer-dev' ,
0 commit comments