@@ -9,8 +9,11 @@ import * as vscode from 'vscode';
99import { AuthProvider } from '../common/authentication' ;
1010import Logger from '../common/logger' ;
1111import { ITelemetry } from '../common/telemetry' ;
12- import { CredentialStore } from './credentials' ;
12+ import { CredentialStore , GitHub } from './credentials' ;
13+ import { PRType } from './interface' ;
1314import { LoggingOctokit } from './loggingOctokit' ;
15+ import { PullRequestModel } from './pullRequestModel' ;
16+ import { RepositoriesManager } from './repositoriesManager' ;
1417import { hasEnterpriseUri } from './utils' ;
1518
1619const LEARN_MORE_URL = 'https://docs.github.com/en/copilot/how-tos/agents/copilot-coding-agent' ;
@@ -35,10 +38,19 @@ export interface RemoteAgentJobResponse {
3538 }
3639}
3740
41+ export interface ChatSessionWithPR extends vscode . ChatSessionContent {
42+ pullRequest : PullRequestModel ;
43+ }
44+
3845export class CopilotApi {
3946 protected static readonly ID = 'copilotApi' ;
4047
41- constructor ( private octokit : LoggingOctokit , private token : string , private telemetry : ITelemetry ) { }
48+ constructor (
49+ private octokit : LoggingOctokit ,
50+ private token : string ,
51+ private credentialStore : CredentialStore ,
52+ private telemetry : ITelemetry
53+ ) { }
4254
4355 private get baseUrl ( ) : string {
4456 return 'https://api.githubcopilot.com' ;
@@ -173,6 +185,23 @@ export class CopilotApi {
173185 return sessions . sessions ;
174186 }
175187
188+ public async getAllCodingAgentPRs ( repositoriesManager : RepositoriesManager ) : Promise < PullRequestModel [ ] > {
189+ const hub = this . getHub ( ) ;
190+ const username = ( await hub ?. currentUser ) ?. login ;
191+ if ( ! username ) {
192+ Logger . error ( 'Failed to get GitHub username from auth provider' , CopilotApi . ID ) ;
193+ return [ ] ;
194+ }
195+ const query = `is:open author:copilot-swe-agent[bot] assignee:${ username } is:pr` ;
196+ const allItems = await Promise . all (
197+ repositoriesManager . folderManagers . map ( async fm => {
198+ const result = await fm . getPullRequests ( PRType . Query , undefined , query ) ;
199+ return result . items ;
200+ } )
201+ ) ;
202+ return allItems . flat ( ) ;
203+ }
204+
176205 public async getSessionInfo ( sessionId : string ) : Promise < SessionInfo > {
177206 const response = await fetch ( `https://api.githubcopilot.com/agents/sessions/${ sessionId } ` , {
178207 method : 'GET' ,
@@ -201,6 +230,19 @@ export class CopilotApi {
201230 }
202231 return await logsResponse . text ( ) ;
203232 }
233+
234+ private getHub ( ) : GitHub | undefined {
235+ let authProvider : AuthProvider | undefined ;
236+ if ( this . credentialStore . isAuthenticated ( AuthProvider . githubEnterprise ) && hasEnterpriseUri ( ) ) {
237+ authProvider = AuthProvider . githubEnterprise ;
238+ } else if ( this . credentialStore . isAuthenticated ( AuthProvider . github ) ) {
239+ authProvider = AuthProvider . github ;
240+ } else {
241+ return ;
242+ }
243+
244+ return this . credentialStore . getHub ( authProvider ) ;
245+ }
204246}
205247
206248
@@ -242,5 +284,5 @@ export async function getCopilotApi(credentialStore: CredentialStore, telemetry:
242284 }
243285
244286 const { token } = await github . octokit . api . auth ( ) as { token : string } ;
245- return new CopilotApi ( github . octokit , token , telemetry ) ;
287+ return new CopilotApi ( github . octokit , token , credentialStore , telemetry ) ;
246288}
0 commit comments