Skip to content

Commit 540c5aa

Browse files
authored
Support pagination in workflow runs (#7134)
* Support pagination in workflow runs * Missing updates
1 parent 92da29e commit 540c5aa

3 files changed

Lines changed: 36 additions & 18 deletions

File tree

src/github/copilotApi.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import JSZip from 'jszip';
88
import * as vscode from 'vscode';
99
import { AuthProvider } from '../common/authentication';
1010
import Logger from '../common/logger';
11-
import { Remote } from '../common/remote';
1211
import { OctokitCommon } from './common';
1312
import { CredentialStore } from './credentials';
1413
import { LoggingOctokit } from './loggingOctokit';
14+
import { PullRequestModel } from './pullRequestModel';
1515
import { hasEnterpriseUri } from './utils';
1616

1717
const LEARN_MORE_URL = 'https://docs.github.com/en/copilot/how-tos/agents/copilot-coding-agent';
@@ -109,18 +109,35 @@ export class CopilotApi {
109109
}
110110
}
111111

112-
public async getWorkflowRunsFromAction(remote: Remote): Promise<OctokitCommon.ListWorkflowRunsForRepo> {
113-
const runs = await this.octokit.api.actions.listWorkflowRunsForRepo(
114-
{
115-
owner: remote.owner,
116-
repo: remote.repositoryName,
117-
event: 'dynamic'
112+
public async getWorkflowRunsFromAction(pullRequest: PullRequestModel): Promise<OctokitCommon.ListWorkflowRunsForRepo> {
113+
const createdDate = new Date(pullRequest.createdAt);
114+
const created = `>=${createdDate.getFullYear()}-${String(createdDate.getMonth() + 1).padStart(2, '0')}-${String(createdDate.getDate()).padStart(2, '0')}`;
115+
const allRuns: any[] = [];
116+
let page = 1;
117+
let hasMore = true;
118+
const per_page = 100;
119+
while (hasMore) {
120+
const runs = await this.octokit.api.actions.listWorkflowRunsForRepo({
121+
owner: pullRequest.remote.owner,
122+
repo: pullRequest.remote.repositoryName,
123+
event: 'dynamic',
124+
created,
125+
per_page,
126+
page
127+
});
128+
if (runs.status !== 200) {
129+
throw new Error(`Failed to fetch workflow runs: ${runs.status}`);
130+
}
131+
if (Array.isArray(runs.data.workflow_runs)) {
132+
allRuns.push(...runs.data.workflow_runs);
133+
hasMore = runs.data.total_count > allRuns.length;
134+
page++;
135+
} else {
136+
hasMore = false;
118137
}
119-
);
120-
if (runs.status !== 200) {
121-
throw new Error(`Failed to fetch workflow runs: ${runs.status}`);
122138
}
123-
return runs.data.workflow_runs;
139+
// Return only the workflow_runs array for compatibility
140+
return allRuns as unknown as OctokitCommon.ListWorkflowRunsForRepo;
124141
}
125142

126143
public async getLogsFromZipUrl(logsUrl: string): Promise<string[]> {

src/github/copilotRemoteAgent.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ import { AuthProvider } from '../common/authentication';
99
import { COPILOT_LOGINS } from '../common/copilot';
1010
import { commands } from '../common/executeCommands';
1111
import { Disposable } from '../common/lifecycle';
12-
import { GitHubRemote, Remote } from '../common/remote';
12+
import Logger from '../common/logger';
13+
import { GitHubRemote } from '../common/remote';
1314
import { CODING_AGENT, CODING_AGENT_AUTO_COMMIT_AND_PUSH, CODING_AGENT_ENABLED } from '../common/settingKeys';
1415
import { toOpenPullRequestWebviewUri } from '../common/uri';
1516
import { CopilotApi, RemoteAgentJobPayload } from './copilotApi';
1617
import { CopilotPRWatcher, CopilotStateModel } from './copilotPrWatcher';
1718
import { CredentialStore } from './credentials';
1819
import { FolderRepositoryManager } from './folderRepositoryManager';
19-
import { RepositoriesManager } from './repositoriesManager';
2020
import { GitHubRepository } from './githubRepository';
21-
import Logger from '../common/logger';
21+
import { PullRequestModel } from './pullRequestModel';
22+
import { RepositoriesManager } from './repositoriesManager';
2223

2324
type RemoteAgentSuccessResult = { link: string; state: 'success'; number: number; webviewUri: vscode.Uri; llmDetails: string };
2425
type RemoteAgentErrorResult = { error: string; state: 'error' };
@@ -397,15 +398,15 @@ export class CopilotRemoteAgentManager extends Disposable {
397398
}
398399
}
399400

400-
async getSessionLogsFromAction(remote: Remote, pullRequestId: number) {
401+
async getSessionLogsFromAction(pullRequest: PullRequestModel) {
401402
const capi = await this.copilotApi;
402403
if (!capi) {
403404
return [];
404405
}
405-
const runs = await capi.getWorkflowRunsFromAction(remote);
406+
const runs = await capi.getWorkflowRunsFromAction(pullRequest);
406407
const padawanRuns = runs
407408
.filter(run => run.path && run.path.startsWith('dynamic/copilot-swe-agent'))
408-
.filter(run => run.pull_requests?.some(pr => pr.id === pullRequestId));
409+
.filter(run => run.pull_requests?.some(pr => pr.id === pullRequest.id));
409410

410411
const lastRun = this.getLatestRun(padawanRuns);
411412

src/lm/tools/activePullRequestTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class ActivePullRequestTool implements vscode.LanguageModelTool<FetchIssu
7373
model: vscode.LanguageModelChat,
7474
cancellationToken: vscode.CancellationToken
7575
) {
76-
const logs = await this.copilotRemoteAgentManager.getSessionLogsFromAction(pullRequest.remote, pullRequest.id);
76+
const logs = await this.copilotRemoteAgentManager.getSessionLogsFromAction(pullRequest);
7777
// Summarize the Copilot agent's thinking process using the model
7878
const messages = [
7979
vscode.LanguageModelChatMessage.Assistant('You are an expert summarizer. The following logs show the thinking process and performed actions of a GitHub Copilot agent that was in charge of working on the current pull request. Read the logs and always maintain the thinking process. You can remove information on the tool call results that you think are not necessary for building context.'),

0 commit comments

Comments
 (0)