Skip to content

Commit 8733e2b

Browse files
committed
Fix listing artifacts
1 parent 801c541 commit 8733e2b

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

lib/github-api-client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Deno.test("listArtifacts success", async () => {
196196
};
197197

198198
mockFetcher.mockResponse(
199-
"https://api.github.com/repos/denoland/deno/actions/runs/123/artifacts",
199+
"https://api.github.com/repos/denoland/deno/actions/runs/123/artifacts?per_page=100&page=1",
200200
createMockResponse(mockData),
201201
);
202202

@@ -212,7 +212,7 @@ Deno.test("listArtifacts failure", async () => {
212212
const client = new RealGitHubApiClient(mockFetcher, "test-token");
213213

214214
mockFetcher.mockResponse(
215-
"https://api.github.com/repos/denoland/deno/actions/runs/123/artifacts",
215+
"https://api.github.com/repos/denoland/deno/actions/runs/123/artifacts?per_page=100&page=1",
216216
new Response(null, { status: 401, statusText: "Unauthorized" }),
217217
);
218218

lib/github-api-client.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,33 @@ export class RealGitHubApiClient {
136136
}
137137

138138
async listArtifacts(runId: number): Promise<Artifact[]> {
139-
const url =
140-
`https://api.github.com/repos/${OWNER}/${REPO}/actions/runs/${runId}/artifacts`;
141-
142-
const response = await this.#fileFetcher.get(url, this.#getHeaders());
139+
const allArtifacts: Artifact[] = [];
140+
const maxPages = 10;
143141

144-
if (!response.ok) {
145-
throw new Error(
146-
`Failed to list artifacts: ${response.status} ${response.statusText}`,
142+
for (let page = 1; page <= maxPages; page++) {
143+
const url = new URL(
144+
`https://api.github.com/repos/${OWNER}/${REPO}/actions/runs/${runId}/artifacts`,
147145
);
146+
url.searchParams.set("per_page", "100");
147+
url.searchParams.set("page", page.toString());
148+
149+
const response = await this.#fileFetcher.get(url, this.#getHeaders());
150+
151+
if (!response.ok) {
152+
throw new Error(
153+
`Failed to list artifacts: ${response.status} ${response.statusText}`,
154+
);
155+
}
156+
157+
const data: ArtifactsListResponse = await response.json();
158+
allArtifacts.push(...data.artifacts);
159+
160+
if (allArtifacts.length >= data.total_count) {
161+
break;
162+
}
148163
}
149164

150-
const data: ArtifactsListResponse = await response.json();
151-
return data.artifacts;
165+
return allArtifacts;
152166
}
153167

154168
async downloadArtifact(archiveDownloadUrl: string): Promise<Blob> {

0 commit comments

Comments
 (0)