From 6b830fda40d1dd50d33d11e40839ce5e1dfd4d94 Mon Sep 17 00:00:00 2001 From: Taichi Sasaki Date: Tue, 20 Sep 2022 17:29:43 +0900 Subject: [PATCH 1/2] Properly handle pagination of job and took --- src/fields.ts | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/fields.ts b/src/fields.ts index 37123889..d8e2ce77 100644 --- a/src/fields.ts +++ b/src/fields.ts @@ -103,14 +103,15 @@ export class FieldFactory { } private async took(): Promise { - const resp = await this.octokit?.rest.actions.listJobsForWorkflowRun({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.runId, - }); - const currentJob = resp?.data.jobs.find(job => - this.isCurrentJobName(job.name), + const jobs = await this.octokit?.paginate( + this.octokit?.rest.actions.listJobsForWorkflowRun, + { + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.runId, + }, ); + const currentJob = jobs.find(job => this.isCurrentJobName(job.name)); if (currentJob === undefined) { process.env.AS_TOOK = this.jobIsNotFound; return this.jobIsNotFound; @@ -140,14 +141,15 @@ export class FieldFactory { private async job(): Promise { const { owner } = context.repo; - const resp = await this.octokit?.rest.actions.listJobsForWorkflowRun({ - owner, - repo: context.repo.repo, - run_id: context.runId, - }); - const currentJob = resp?.data.jobs.find(job => - this.isCurrentJobName(job.name), + const jobs = await this.octokit?.paginate( + this.octokit?.rest.actions.listJobsForWorkflowRun, + { + owner, + repo: context.repo.repo, + run_id: context.runId, + }, ); + const currentJob = jobs.find(job => this.isCurrentJobName(job.name)); if (currentJob === undefined) { process.env.AS_JOB = this.jobIsNotFound; return this.jobIsNotFound; From 88c313b5bf256c77e450a6f274cc5358f5f0999f Mon Sep 17 00:00:00 2001 From: Taichi Sasaki Date: Wed, 21 Sep 2022 20:10:14 +0900 Subject: [PATCH 2/2] Add response map function --- src/fields.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/fields.ts b/src/fields.ts index d8e2ce77..d0584a35 100644 --- a/src/fields.ts +++ b/src/fields.ts @@ -110,6 +110,12 @@ export class FieldFactory { repo: context.repo.repo, run_id: context.runId, }, + (response, done) => { + if (response.data.find(job => this.isCurrentJobName(job.name))) { + done(); + } + return response.data; + }, ); const currentJob = jobs.find(job => this.isCurrentJobName(job.name)); if (currentJob === undefined) { @@ -148,6 +154,12 @@ export class FieldFactory { repo: context.repo.repo, run_id: context.runId, }, + (response, done) => { + if (response.data.find(job => this.isCurrentJobName(job.name))) { + done(); + } + return response.data; + }, ); const currentJob = jobs.find(job => this.isCurrentJobName(job.name)); if (currentJob === undefined) {