Skip to content

Commit

Permalink
Merge pull request #225 from tchssk/jobs-took-paginate
Browse files Browse the repository at this point in the history
Properly handle pagination of job and took
  • Loading branch information
8398a7 authored Sep 24, 2022
2 parents e080ee3 + 88c313b commit 555420c
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,21 @@ export class FieldFactory {
}

private async took(): Promise<string> {
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,
},
(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) {
process.env.AS_TOOK = this.jobIsNotFound;
return this.jobIsNotFound;
Expand Down Expand Up @@ -140,14 +147,21 @@ export class FieldFactory {

private async job(): Promise<string> {
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,
},
(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) {
process.env.AS_JOB = this.jobIsNotFound;
return this.jobIsNotFound;
Expand Down

0 comments on commit 555420c

Please sign in to comment.