Skip to content

Commit 0f9daa9

Browse files
authored
Move use of listWorkflowRunsForRepo into GitHubRepository and use restPaginate (#7155)
Fixes #7154
1 parent 80b4f44 commit 0f9daa9

File tree

3 files changed

+15
-34
lines changed

3 files changed

+15
-34
lines changed

src/github/copilotApi.ts

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

1715
const LEARN_MORE_URL = 'https://docs.github.com/en/copilot/how-tos/agents/copilot-coding-agent';
@@ -109,37 +107,6 @@ export class CopilotApi {
109107
}
110108
}
111109

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;
137-
}
138-
}
139-
// Return only the workflow_runs array for compatibility
140-
return allRuns as unknown as OctokitCommon.ListWorkflowRunsForRepo;
141-
}
142-
143110
public async getLogsFromZipUrl(logsUrl: string): Promise<string[]> {
144111
const logsZip = await fetch(logsUrl, {
145112
headers: {

src/github/copilotRemoteAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export class CopilotRemoteAgentManager extends Disposable {
416416
if (!capi) {
417417
return;
418418
}
419-
const runs = await capi.getWorkflowRunsFromAction(pullRequest);
419+
const runs = await pullRequest.githubRepository.getWorkflowRunsFromAction(pullRequest.createdAt);
420420
const padawanRuns = runs
421421
.filter(run => run.path && run.path.startsWith('dynamic/copilot-swe-agent'))
422422
.filter(run => run.pull_requests?.some(pr => pr.id === pullRequest.id));

src/github/githubRepository.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,20 @@ export class GitHubRepository extends Disposable {
850850
}
851851
}
852852

853+
public async getWorkflowRunsFromAction(fromDate: string): Promise<OctokitCommon.ListWorkflowRunsForRepo> {
854+
const { octokit, remote } = await this.ensure();
855+
const createdDate = new Date(fromDate);
856+
const created = `>=${createdDate.getFullYear()}-${String(createdDate.getMonth() + 1).padStart(2, '0')}-${String(createdDate.getDate()).padStart(2, '0')}`;
857+
const allRuns = await restPaginate<typeof octokit.api.actions.listWorkflowRunsForRepo, OctokitCommon.ListWorkflowRunsForRepo[0]>(octokit.api.actions.listWorkflowRunsForRepo, {
858+
owner: remote.owner,
859+
repo: remote.repositoryName,
860+
event: 'dynamic',
861+
created
862+
});
863+
864+
return allRuns;
865+
}
866+
853867
async fork(): Promise<string | undefined> {
854868
try {
855869
Logger.debug(`Fork repository`, this.id);

0 commit comments

Comments
 (0)