Skip to content

Conversation

@carlobeltrame
Copy link
Contributor

@carlobeltrame carlobeltrame commented Jun 17, 2025

Fixes #264
Also adds a filter event=workflow_dispatch to the workflow runs query. This should be safe and not a breaking change, since this action is only ever interested in the workflow_dispatched runs which it itself triggered.

This should reduce the required API calls by a lot, if there are a lot of workflow runs in the target repository.

Summary by CodeRabbit

  • New Features

    • Workflow run searches now include filtering to only show runs triggered after a specified start time and initiated by manual dispatch events.
  • Bug Fixes

    • Enhanced workflow run retrieval accuracy by applying filters based on creation time and event type.

@coderabbitai
Copy link

coderabbitai bot commented Jun 17, 2025

Walkthrough

The changes update the fetchWorkflowRunIds function and its usages to accept a startTimeISO parameter, which is used to filter GitHub workflow runs by creation time and event type. This timestamp filter is integrated into the API call and propagated through the relevant function calls and tests, ensuring consistent time-based filtering.

Changes

File(s) Change Summary
src/api.ts Updated fetchWorkflowRunIds to accept a startTimeISO parameter and use it as a created filter in the API call. Added event filter for "workflow_dispatch".
src/return-dispatch.ts Modified getRunIdAndUrl to convert startTime to ISO string and pass it to fetchWorkflowRunIds.
src/api.spec.ts Updated all test calls to fetchWorkflowRunIds to include the new startTimeISO argument. Adjusted expected debug logs to include creation time filter.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant return-dispatch.ts
    participant api.ts
    participant GitHubAPI

    Caller->>return-dispatch.ts: getRunIdAndUrl(workflowId, branch, startTime)
    return-dispatch.ts->>api.ts: fetchWorkflowRunIds(workflowId, branch, startTimeISO)
    api.ts->>GitHubAPI: listWorkflowRuns(created>=startTimeISO, event='workflow_dispatch', branch?)
    GitHubAPI-->>api.ts: Workflow runs data
    api.ts-->>return-dispatch.ts: Filtered workflow run IDs
    return-dispatch.ts-->>Caller: Run ID and URL
Loading

Assessment against linked issues

Objective Addressed Explanation
Pass startTime from getRunIdAndUrl to fetchWorkflowRunIds and use as API created filter (#264)
Ensure only workflow runs after startTime and with workflow_dispatch event are fetched (#264)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Poem

A hop, a skip, a timely leap,
Now workflows filter what they reap.
With startTime passed and queries neat,
Only fresh runs do we greet!
The code now bounds with rabbit glee—
Precise, efficient, bug-free!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 66afbed and 96e779d.

⛔ Files ignored due to path filters (1)
  • dist/index.mjs is excluded by !**/dist/**
📒 Files selected for processing (3)
  • src/api.spec.ts (12 hunks)
  • src/api.ts (2 hunks)
  • src/return-dispatch.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/return-dispatch.ts
  • src/api.spec.ts
  • src/api.ts
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/api.ts (2)

161-172: Prefer passing a Date object instead of a raw epoch number

startTime is accepted as a number, converted back to Date, and immediately transformed into ISO.
Exposing the parameter as a Date:

-export async function fetchWorkflowRunIds(
-  workflowId: number,
-  branch: BranchNameResult,
-  startTime: number,
+export async function fetchWorkflowRunIds(
+  workflowId: number,
+  branch: BranchNameResult,
+  startTime: Date,

would make the intent explicit, remove the extra setTime indirection, and avoid accidental misuse with non-epoch numbers.

-const startTimeDate = new Date();
-startTimeDate.setTime(startTime);
-const startTimeISO = startTimeDate.toISOString();
+const startTimeISO = startTime.toISOString();

169-172: Redundant object creation

new Date(); startTimeDate.setTime(startTime) costs an allocation and does nothing if the caller already ensures a valid epoch.
If you keep the numeric parameter, replace the block with:

const startTimeISO = new Date(startTime).toISOString();
src/return-dispatch.ts (1)

152-156: Variable name shadows the imported function, hampers readability

const fetchWorkflowRunIds = await api.retryOrTimeout(/* … */);

The local constant now shares the exact name of the imported api.fetchWorkflowRunIds, forcing readers to parse scopes to understand which one is being used.
Consider renaming to something like workflowRunIdsResult (or simply runIdsResult) to avoid shadowing.

-const fetchWorkflowRunIds = await api.retryOrTimeout(
+const runIdsResult = await api.retryOrTimeout(
     () => api.fetchWorkflowRunIds(workflowId, branch, startTime),
     retryTimeout,
   );
-if (!fetchWorkflowRunIds.success) {
+if (!runIdsResult.success) {
src/api.spec.ts (1)

360-363: Use a fixed timestamp in tests for determinism & clearer intent

Date.now() is evaluated at call-time, so each expectation uses a slightly different value.
It isn’t an issue today because the mock ignores the parameter, but if you later assert on created or snapshot requests, millisecond drift will break tests.

-const now = Date.now();
-await expect(fetchWorkflowRunIds(0, branch, Date.now())).resolves…
+const now = 1_689_000_000_000; // arbitrary, fixed
+await expect(fetchWorkflowRunIds(0, branch, now)).resolves…

Apply once in a beforeEach and reuse the constant across assertions.

Also applies to: 391-394, 419-422, 455-457, 492-495, 529-532

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f52045 and d49bf80.

⛔ Files ignored due to path filters (1)
  • dist/index.mjs is excluded by !**/dist/**
📒 Files selected for processing (3)
  • src/api.spec.ts (6 hunks)
  • src/api.ts (1 hunks)
  • src/return-dispatch.ts (1 hunks)
🔇 Additional comments (1)
src/api.ts (1)

178-180: Verify the format expected by the Octokit created filter

The code sends created: '>' + startTimeISO.
Octokit/GitHub currently accept exact timestamps (e.g. 2024-06-01T12:00:00Z) without comparison operators, and the use of a leading > is only documented for the Search API, not for the Actions list-runs endpoint.

Please double-check that the produced request actually filters anything and doesn’t 400 / silently ignore the parameter.

@carlobeltrame carlobeltrame force-pushed the filter-workflow-runs branch from d49bf80 to 6b7c495 Compare June 17, 2025 14:22
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/api.ts (2)

169-170: Minor micro-optimisation: avoid intermediate string concatenation
'>' can be prefixed in the template literal itself for marginally clearer intent.

-const afterStartTime = ">" + new Date(startTime).toISOString();
+const afterStartTime = `>${new Date(startTime).toISOString()}`;

172-178: Use the workflow-scoped endpoint to reduce payload and remove unused parameter
octokit.rest.actions.listWorkflowRuns is a repository-wide endpoint.
Because workflow_id is supplied, the more specific listWorkflowRunsForWorkflow endpoint is a better fit; it is documented to accept event, created, etc., and avoids returning runs from other workflows in edge cases where the repo-wide endpoint silently ignores workflow_id.

-const response = await octokit.rest.actions.listWorkflowRuns({
+const response = await octokit.rest.actions.listWorkflowRunsForWorkflow({
   owner: config.owner,
   repo: config.repo,
   workflow_id: workflowId,
   created: afterStartTime,
   event: "workflow_dispatch",

This change tightens the query scope and may further cut API traffic.
Please verify other call-sites compile after the rename.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b7c495 and 66afbed.

📒 Files selected for processing (2)
  • src/api.spec.ts (6 hunks)
  • src/api.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/api.spec.ts

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.91%. Comparing base (5f52045) to head (96e779d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #294      +/-   ##
==========================================
+ Coverage   96.88%   96.91%   +0.03%     
==========================================
  Files           6        6              
  Lines         577      583       +6     
  Branches      112      112              
==========================================
+ Hits          559      565       +6     
  Misses         17       17              
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Owner

@Codex- Codex- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you!

@Codex- Codex- merged commit 5210b85 into Codex-:main Jun 17, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

improvement on getRunIdAndUrl

3 participants