Skip to content

Commit 496dd66

Browse files
committed
feat: use created from including start time (>=)
1 parent 66afbed commit 496dd66

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/api.spec.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ describe("API", () => {
326326
});
327327

328328
describe("fetchWorkflowRunIds", () => {
329+
const startTimeISO = "2025-06-17T22:24:23.238Z";
329330
const workflowIdCfg: ActionConfig = {
330331
token: "secret",
331332
ref: "/refs/heads/feature_branch",
@@ -359,7 +360,7 @@ describe("API", () => {
359360

360361
// Behaviour
361362
await expect(
362-
fetchWorkflowRunIds(0, branch, Date.now()),
363+
fetchWorkflowRunIds(0, branch, startTimeISO),
363364
).resolves.toStrictEqual(mockData.workflow_runs.map((run) => run.id));
364365

365366
// Logging
@@ -371,6 +372,7 @@ describe("API", () => {
371372
Repository: owner/repository
372373
Branch Filter: true (feature_branch)
373374
Workflow ID: 0
375+
Created: >=2025-06-17T22:24:23.238Z
374376
Runs Fetched: [0, 1, 2]"
375377
`,
376378
);
@@ -389,7 +391,9 @@ describe("API", () => {
389391
);
390392

391393
// Behaviour
392-
await expect(fetchWorkflowRunIds(0, branch, Date.now())).rejects.toThrow(
394+
await expect(
395+
fetchWorkflowRunIds(0, branch, startTimeISO),
396+
).rejects.toThrow(
393397
`Failed to fetch Workflow runs, expected 200 but received ${errorStatus}`,
394398
);
395399

@@ -418,7 +422,7 @@ describe("API", () => {
418422

419423
// Behaviour
420424
await expect(
421-
fetchWorkflowRunIds(0, branch, Date.now()),
425+
fetchWorkflowRunIds(0, branch, startTimeISO),
422426
).resolves.toStrictEqual([]);
423427

424428
// Logging
@@ -430,6 +434,7 @@ describe("API", () => {
430434
Repository: owner/repository
431435
Branch Filter: true (feature_branch)
432436
Workflow ID: 0
437+
Created: >=2025-06-17T22:24:23.238Z
433438
Runs Fetched: []"
434439
`,
435440
);
@@ -456,7 +461,7 @@ describe("API", () => {
456461

457462
// Behaviour
458463
await expect(
459-
fetchWorkflowRunIds(0, branch, Date.now()),
464+
fetchWorkflowRunIds(0, branch, startTimeISO),
460465
).resolves.not.toThrow();
461466
expect(parsedRef).toStrictEqual("master");
462467

@@ -469,6 +474,7 @@ describe("API", () => {
469474
Repository: owner/repository
470475
Branch Filter: true (master)
471476
Workflow ID: 0
477+
Created: >=2025-06-17T22:24:23.238Z
472478
Runs Fetched: []"
473479
`,
474480
);
@@ -495,7 +501,7 @@ describe("API", () => {
495501

496502
// Behaviour
497503
await expect(
498-
fetchWorkflowRunIds(0, branch, Date.now()),
504+
fetchWorkflowRunIds(0, branch, startTimeISO),
499505
).resolves.not.toThrow();
500506
expect(parsedRef).toBeUndefined();
501507

@@ -508,6 +514,7 @@ describe("API", () => {
508514
Repository: owner/repository
509515
Branch Filter: false (/refs/tags/1.5.0)
510516
Workflow ID: 0
517+
Created: >=2025-06-17T22:24:23.238Z
511518
Runs Fetched: []"
512519
`,
513520
);
@@ -534,7 +541,7 @@ describe("API", () => {
534541

535542
// Behaviour
536543
await expect(
537-
fetchWorkflowRunIds(0, branch, Date.now()),
544+
fetchWorkflowRunIds(0, branch, startTimeISO),
538545
).resolves.not.toThrow();
539546
expect(parsedRef).toBeUndefined();
540547

@@ -547,6 +554,7 @@ describe("API", () => {
547554
Repository: owner/repository
548555
Branch Filter: false (/refs/cake)
549556
Workflow ID: 0
557+
Created: >=2025-06-17T22:24:23.238Z
550558
Runs Fetched: []"
551559
`,
552560
);

src/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ export async function fetchWorkflowRunIds(
166166
branch.branchName !== undefined &&
167167
branch.branchName !== "";
168168

169-
const afterStartTime = ">" + new Date(startTime).toISOString();
169+
const createdFrom = ">=" + new Date(startTime).toISOString();
170170

171171
// https://docs.github.com/en/rest/actions/workflow-runs#list-workflow-runs-for-a-repository
172172
const response = await octokit.rest.actions.listWorkflowRuns({
173173
owner: config.owner,
174174
repo: config.repo,
175175
workflow_id: workflowId,
176-
created: afterStartTime,
176+
created: createdFrom,
177177
event: "workflow_dispatch",
178178
...(useBranchFilter
179179
? {
@@ -204,6 +204,7 @@ export async function fetchWorkflowRunIds(
204204
` Repository: ${config.owner}/${config.repo}\n` +
205205
` Branch Filter: ${branchMsg}\n` +
206206
` Workflow ID: ${workflowId}\n` +
207+
` Created: ${createdFrom}\n` +
207208
` Runs Fetched: [${runIds.join(", ")}]`,
208209
);
209210

0 commit comments

Comments
 (0)