Skip to content

Commit

Permalink
Take queued runs into account on wait
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvaro Bautista committed Jan 21, 2021
1 parent 8db075d commit b010239
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion __tests__/wait.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ describe("wait", () => {
status: "in_progress",
html_url: "3",
},
{
id: 4,
status: "queued",
html_url: "4",
},
];
// Give the current run an id that makes it the last in the queue.
input.runId = inProgressRuns.length + 1;
Expand All @@ -160,7 +165,7 @@ describe("wait", () => {
const mockedRunsFunc = jest.fn();
mockedRunsFunc
.mockReturnValueOnce(Promise.resolve(inProgressRuns.slice(0)))
.mockReturnValueOnce(Promise.resolve(inProgressRuns.slice(0, 2)))
.mockReturnValueOnce(Promise.resolve(inProgressRuns.slice(0, 3)))
.mockReturnValueOnce(Promise.resolve(inProgressRuns))
// Finally return just the run that was queued _after_ the "input" run.
.mockReturnValue(
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export class OctokitGitHub implements GitHub {
owner,
repo,
workflow_id,
status: "in_progress",
};

if (branch) {
Expand Down
1 change: 1 addition & 0 deletions src/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class Waiter implements Wait {
this.workflowId
);
const previousRuns = runs
.filter((run) => ["in_progress", "queued"].includes(run.status))
.filter((run) => run.id < this.input.runId)
.sort((a, b) => b.id - a.id);
if (!previousRuns || !previousRuns.length) {
Expand Down

0 comments on commit b010239

Please sign in to comment.