| 47 | } |
| 48 | |
| 49 | async function fetchJobs( |
| 50 | owner: string, |
| 51 | repo: string, |
| 52 | runId: number, |
| 53 | ): Promise<WorkflowJob[]> { |
| 54 | const token = process.env.GITHUB_TOKEN?.trim(); |
| 55 | if (!token) { |
| 56 | throw new Error("GITHUB_TOKEN is required to call the GitHub API."); |
| 57 | } |
| 58 | |
| 59 | const request = octokitRequest.defaults({ |
| 60 | headers: { |
| 61 | authorization: `Bearer ${token}`, |
| 62 | "user-agent": "opencode-bench/job-url", |
| 63 | }, |
| 64 | }); |
| 65 | |
| 66 | const jobs: WorkflowJob[] = []; |
| 67 | const perPage = 100; |
| 68 | let page = 1; |
| 69 | |
| 70 | // GitHub caps pagination at 100 items per page. Loop until a page returns fewer rows. |
| 71 | while (true) { |
| 72 | const response = await request( |
| 73 | "GET /repos/{owner}/{repo}/actions/runs/{run_id}/jobs", |
| 74 | { |
| 75 | owner, |
| 76 | repo, |
| 77 | run_id: runId, |
| 78 | per_page: perPage, |
| 79 | page, |
| 80 | }, |
| 81 | ); |
| 82 | |
| 83 | const data = response.data as ListWorkflowJobsResponse; |
| 84 | const batch = data.jobs ?? []; |
| 85 | jobs.push(...batch); |
| 86 | |
| 87 | if (batch.length < perPage) { |
| 88 | break; |
| 89 | } |
| 90 | |
| 91 | page += 1; |
| 92 | } |
| 93 | |
| 94 | return jobs; |
| 95 | } |
| 96 | |
| 97 | async function main(): Promise<void> { |
| 98 | const repoSlug = process.env.GITHUB_REPOSITORY; |