Skip to content

Commit 1518fa6

Browse files
committed
Filter by creation date
Fixes Codex-/return-dispatch#264
1 parent 5f52045 commit 1518fa6

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

dist/index.mjs

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ describe("API", () => {
358358
);
359359

360360
// Behaviour
361-
await expect(fetchWorkflowRunIds(0, branch)).resolves.toStrictEqual(
361+
await expect(fetchWorkflowRunIds(0, branch, Date.now())).resolves.toStrictEqual(
362362
mockData.workflow_runs.map((run) => run.id),
363363
);
364364

@@ -389,7 +389,7 @@ describe("API", () => {
389389
);
390390

391391
// Behaviour
392-
await expect(fetchWorkflowRunIds(0, branch)).rejects.toThrow(
392+
await expect(fetchWorkflowRunIds(0, branch, Date.now())).rejects.toThrow(
393393
`Failed to fetch Workflow runs, expected 200 but received ${errorStatus}`,
394394
);
395395

@@ -417,7 +417,7 @@ describe("API", () => {
417417
);
418418

419419
// Behaviour
420-
await expect(fetchWorkflowRunIds(0, branch)).resolves.toStrictEqual([]);
420+
await expect(fetchWorkflowRunIds(0, branch, Date.now())).resolves.toStrictEqual([]);
421421

422422
// Logging
423423
assertOnlyCalled(coreDebugLogMock);
@@ -453,7 +453,7 @@ describe("API", () => {
453453
);
454454

455455
// Behaviour
456-
await expect(fetchWorkflowRunIds(0, branch)).resolves.not.toThrow();
456+
await expect(fetchWorkflowRunIds(0, branch, Date.now())).resolves.not.toThrow();
457457
expect(parsedRef).toStrictEqual("master");
458458

459459
// Logging
@@ -490,7 +490,7 @@ describe("API", () => {
490490
);
491491

492492
// Behaviour
493-
await expect(fetchWorkflowRunIds(0, branch)).resolves.not.toThrow();
493+
await expect(fetchWorkflowRunIds(0, branch, Date.now())).resolves.not.toThrow();
494494
expect(parsedRef).toBeUndefined();
495495

496496
// Logging
@@ -527,7 +527,7 @@ describe("API", () => {
527527
);
528528

529529
// Behaviour
530-
await expect(fetchWorkflowRunIds(0, branch)).resolves.not.toThrow();
530+
await expect(fetchWorkflowRunIds(0, branch, Date.now())).resolves.not.toThrow();
531531
expect(parsedRef).toBeUndefined();
532532

533533
// Logging

src/api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,24 @@ export async function fetchWorkflowRunUrl(runId: number): Promise<string> {
158158
export async function fetchWorkflowRunIds(
159159
workflowId: number,
160160
branch: BranchNameResult,
161+
startTime: number,
161162
): Promise<number[]> {
162163
try {
163164
const useBranchFilter =
164165
!branch.isTag &&
165166
branch.branchName !== undefined &&
166167
branch.branchName !== "";
167168

169+
const startTimeDate = new Date();
170+
startTimeDate.setTime(startTime);
171+
const startTimeISO = startTimeDate.toISOString();
172+
168173
// https://docs.github.com/en/rest/actions/workflow-runs#list-workflow-runs-for-a-repository
169174
const response = await octokit.rest.actions.listWorkflowRuns({
170175
owner: config.owner,
171176
repo: config.repo,
172177
workflow_id: workflowId,
178+
created: '>' + startTimeISO,
173179
...(useBranchFilter
174180
? {
175181
branch: branch.branchName,

src/return-dispatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export async function getRunIdAndUrl({
151151

152152
// Get all runs for a given workflow ID
153153
const fetchWorkflowRunIds = await api.retryOrTimeout(
154-
() => api.fetchWorkflowRunIds(workflowId, branch),
154+
() => api.fetchWorkflowRunIds(workflowId, branch, startTime),
155155
retryTimeout,
156156
);
157157
if (!fetchWorkflowRunIds.success) {

0 commit comments

Comments
 (0)