Skip to content

Commit ded8c43

Browse files
committed
sessions list paging
1 parent a8ef4d9 commit ded8c43

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/github/copilotApi.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,9 @@ export class CopilotApi {
192192
return copilotSteps;
193193
}
194194

195-
public async getAllSessions(pullRequestId: number | undefined): Promise<SessionInfo[]> {
195+
public async getAllSessions(pullRequestId: number): Promise<SessionInfo[]> {
196196
const response = await this.makeApiCall(
197-
pullRequestId
198-
? `/agents/sessions/resource/pull/${pullRequestId}`
199-
: `/agents/sessions?page_size=100`,
197+
`/agents/sessions/resource/pull/${pullRequestId}`,
200198
{
201199
headers: {
202200
Authorization: `Bearer ${this.token}`,
@@ -210,6 +208,32 @@ export class CopilotApi {
210208
return sessions.sessions;
211209
}
212210

211+
public async getAllSessionsForAllRepositories(): Promise<SessionInfo[]> {
212+
let hasNextPage = false;
213+
const sessionInfos: SessionInfo[] = [];
214+
const page_size = 20;
215+
let page = 1;
216+
do {
217+
const response = await this.makeApiCall(
218+
`/agents/sessions?page_size=${page_size}&page_number=${page}`,
219+
{
220+
headers: {
221+
Authorization: `Bearer ${this.token}`,
222+
Accept: 'application/json',
223+
},
224+
});
225+
if (!response.ok) {
226+
throw new Error(`Failed to fetch sessions: ${response.statusText}`);
227+
}
228+
const sessions = await response.json();
229+
sessionInfos.push(...sessions.sessions);
230+
hasNextPage = sessions.sessions.length === page_size;
231+
page++;
232+
} while (hasNextPage);
233+
234+
return sessionInfos;
235+
}
236+
213237
public async getPullRequestFromSession(globalId): Promise<SessionPullRequestInfo | undefined> {
214238
try {
215239
const { data } = await this.graphql.query({

src/github/copilotRemoteAgent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ export class CopilotRemoteAgentManager extends Disposable {
882882
const currentRepositories = this.repositoriesManager.folderManagers.map(folder => folder.gitHubRepositories).flat();
883883

884884
this.codingAgentPRsPromise = this.codingAgentPRsPromise ?? new Promise<vscode.ChatSessionItem[]>(async (resolve) => {
885-
const sessions = await capi.getAllSessions(undefined);
885+
const sessions = await capi.getAllSessionsForAllRepositories();
886886
const sessionMap = new Map<string, SessionInfo[]>();
887887

888888
for (const session of sessions) {
@@ -952,13 +952,13 @@ export class CopilotRemoteAgentManager extends Disposable {
952952
});
953953

954954
resolve(filteredPRs);
955+
this.codingAgentPRsPromise = undefined;
955956
});
956957

957958
return this.codingAgentPRsPromise;
958959
} catch (error) {
959960
Logger.error(`Failed to provide coding agents information: ${error}`, CopilotRemoteAgentManager.ID);
960961
} finally {
961-
this.codingAgentPRsPromise = undefined;
962962
}
963963
return [];
964964
}

0 commit comments

Comments
 (0)