Skip to content

Commit

Permalink
fix: handle fetching the URL for a job that instantly completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Codex- committed Jan 29, 2024
1 parent e08375f commit fa8fb2d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 3 additions & 3 deletions dist/index.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,23 @@ describe("API", () => {
expect(url).toStrictEqual(mockData.jobs[0]?.html_url);
});

it("should return the url for an completed workflow run given a run ID", async () => {
inProgressMockData.jobs[0].status = "completed";

vi.spyOn(
mockOctokit.rest.actions,
"listJobsForWorkflowRun",
).mockReturnValue(
Promise.resolve({
data: inProgressMockData,
status: 200,
}),
);

const url = await getWorkflowRunActiveJobUrl(123456);
expect(url).toStrictEqual(mockData.jobs[0]?.html_url);
});

it("should throw if a non-200 status is returned", async () => {
const errorStatus = 401;
vi.spyOn(
Expand Down
6 changes: 3 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ export async function getWorkflowRunActiveJobUrl(
try {
const response = await getWorkflowRunJobs(runId);
const fetchedInProgressJobs = response.data.jobs.filter(
(job) => job.status === "in_progress",
(job) => job.status === "in_progress" || job.status === "completed",
);

core.debug(
`Fetched Jobs for Run:\n` +
` Repository: ${config.owner}/${config.repo}\n` +
` Run ID: ${config.runId}\n` +
` Jobs (in_progress): [${fetchedInProgressJobs.map(
(job) => job.name,
` Jobs: [${fetchedInProgressJobs.map(
(job) => `${job.name} (${job.status})`,
)}]`,
);

Expand Down

0 comments on commit fa8fb2d

Please sign in to comment.