Skip to content

Commit 80b4f44

Browse files
authored
Fallback for actions URL (#7133)
1 parent 540c5aa commit 80b4f44

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

src/github/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export namespace OctokitCommon {
7373
export type Notification = Endpoints['GET /notifications']['response']['data'][0];
7474
export type ListEventsForTimelineResponse = Endpoints['GET /repos/{owner}/{repo}/issues/{issue_number}/timeline']['response']['data'][0];
7575
export type ListWorkflowRunsForRepo = Endpoints['GET /repos/{owner}/{repo}/actions/runs']['response']['data']['workflow_runs'];
76+
export type WorkflowRun = Endpoints['GET /repos/{owner}/{repo}/actions/runs']['response']['data']['workflow_runs'][0];
7677
}
7778

7879
export type Schema = { [key: string]: any, definitions: any[]; };

src/github/copilotRemoteAgent.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Logger from '../common/logger';
1313
import { GitHubRemote } from '../common/remote';
1414
import { CODING_AGENT, CODING_AGENT_AUTO_COMMIT_AND_PUSH, CODING_AGENT_ENABLED } from '../common/settingKeys';
1515
import { toOpenPullRequestWebviewUri } from '../common/uri';
16+
import { OctokitCommon } from './common';
1617
import { CopilotApi, RemoteAgentJobPayload } from './copilotApi';
1718
import { CopilotPRWatcher, CopilotStateModel } from './copilotPrWatcher';
1819
import { CredentialStore } from './credentials';
@@ -45,7 +46,6 @@ const CONTINUE_WITHOUT_PUSHING = vscode.l10n.t('Ignore changes');
4546

4647
export 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> {

src/view/sessionLogView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class SessionLogViewManager extends Disposable implements vscode.WebviewP
105105
}
106106
} catch (error) {
107107
Logger.error(`Failed to retrieve session logs: ${error}`, 'SessionLogViewManager');
108-
const url = await this.copilotAgentManager.getSessionUrlFromPullRequest(pullRequest.id);
108+
const url = await this.copilotAgentManager.getSessionUrlFromPullRequest(pullRequest);
109109
if (!url) {
110110
vscode.window.showErrorMessage(vscode.l10n.t('No sessions found for this pull request.'));
111111
return;

0 commit comments

Comments
 (0)