@@ -13,6 +13,7 @@ import Logger from '../common/logger';
1313import { GitHubRemote } from '../common/remote' ;
1414import { CODING_AGENT , CODING_AGENT_AUTO_COMMIT_AND_PUSH , CODING_AGENT_ENABLED } from '../common/settingKeys' ;
1515import { toOpenPullRequestWebviewUri } from '../common/uri' ;
16+ import { OctokitCommon } from './common' ;
1617import { CopilotApi , RemoteAgentJobPayload } from './copilotApi' ;
1718import { CopilotPRWatcher , CopilotStateModel } from './copilotPrWatcher' ;
1819import { CredentialStore } from './credentials' ;
@@ -45,7 +46,6 @@ const CONTINUE_WITHOUT_PUSHING = vscode.l10n.t('Ignore changes');
4546
4647export class CopilotRemoteAgentManager extends Disposable {
4748 public static ID = 'CopilotRemoteAgentManager' ;
48- private readonly workflowRunUrlBase = 'https://github.com/microsoft/vscode/actions/runs/' ;
4949
5050 private readonly _stateModel : CopilotStateModel ;
5151 private readonly _onDidChangeStates = this . _register ( new vscode . EventEmitter < void > ( ) ) ;
@@ -403,18 +403,30 @@ export class CopilotRemoteAgentManager extends Disposable {
403403 if ( ! capi ) {
404404 return [ ] ;
405405 }
406+ const lastRun = await this . getLatestCodingAgentFromAction ( pullRequest ) ;
407+ if ( ! lastRun ) {
408+ return [ ] ;
409+ }
410+
411+ return await capi . getLogsFromZipUrl ( lastRun . logs_url ) ;
412+ }
413+
414+ async getLatestCodingAgentFromAction ( pullRequest : PullRequestModel , sessionIndex = 0 , completedOnly = true ) : Promise < OctokitCommon . WorkflowRun | undefined > {
415+ const capi = await this . copilotApi ;
416+ if ( ! capi ) {
417+ return ;
418+ }
406419 const runs = await capi . getWorkflowRunsFromAction ( pullRequest ) ;
407420 const padawanRuns = runs
408421 . filter ( run => run . path && run . path . startsWith ( 'dynamic/copilot-swe-agent' ) )
409422 . filter ( run => run . pull_requests ?. some ( pr => pr . id === pullRequest . id ) ) ;
410423
411- const lastRun = this . getLatestRun ( padawanRuns ) ;
412-
413- if ( ! lastRun ) {
414- return [ ] ;
424+ const session = padawanRuns . filter ( s => ! completedOnly || s . status === 'completed' ) . at ( sessionIndex ) ;
425+ if ( ! session ) {
426+ return ;
415427 }
416428
417- return await capi . getLogsFromZipUrl ( lastRun . logs_url ) ;
429+ return this . getLatestRun ( padawanRuns ) ;
418430 }
419431
420432 async getSessionLogFromPullRequest ( pullRequestId : number , sessionIndex = 0 , completedOnly = true ) : Promise < IAPISessionLogs | undefined > {
@@ -433,18 +445,17 @@ export class CopilotRemoteAgentManager extends Disposable {
433445 return { sessionId : session . id , logs } ;
434446 }
435447
436- async getSessionUrlFromPullRequest ( pullRequestId : number , sessionIndex = 0 , completedOnly = true ) : Promise < string | undefined > {
448+ async getSessionUrlFromPullRequest ( pullRequest : PullRequestModel ) : Promise < string | undefined > {
437449 const capi = await this . copilotApi ;
438450 if ( ! capi ) {
439- return undefined ;
451+ return ;
440452 }
441453
442- const sessions = await capi . getAllSessions ( pullRequestId ) ;
443- const session = sessions . filter ( s => ! completedOnly || s . state === 'completed' ) . at ( sessionIndex ) ;
444- if ( ! session ) {
445- return undefined ;
454+ const sessions = await this . getLatestCodingAgentFromAction ( pullRequest ) ;
455+ if ( ! sessions ) {
456+ return ;
446457 }
447- return ` ${ this . workflowRunUrlBase } ${ session . workflow_run_id } ` ;
458+ return sessions . html_url ;
448459 }
449460
450461 async getSessionLogsFromSessionId ( sessionId : string ) : Promise < IAPISessionLogs > {
0 commit comments