Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
refactor(ci): extract run-fetching into reusable script with time-window filtering (#1302)
worktrunk-bot4ea395eec669
diff --git a/.github/scripts/list-recent-runs.sh b/.github/scripts/list-recent-runs.shnew file mode 100755index 000000000..9dbae47f1--- /dev/null+++ b/.github/scripts/list-recent-runs.sh@@ -0,0 +1,37 @@+#!/usr/bin/env bash+# Lists recently completed Claude CI runs.+#+# Fetches runs started in the past 3 hours, then filters to only those that+# are completed and whose updatedAt is within the past hour. This two-step+# approach is needed because `gh run list --created` filters by *start* time,+# not *end* time — a run started 2h ago may have just finished, and a run+# started 50min ago may still be running. See #1301 for details.+#+# Output: JSON array of {databaseId, conclusion, createdAt, updatedAt} objects.++set -euo pipefail++# Dynamically discover all claude-* workflows instead of maintaining a hardcoded list.+mapfile -t WORKFLOWS < <(gh workflow list --json name --jq '.[].name | select(startswith("claude-"))')++CREATED_SINCE=$(date -d '3 hours ago' +%Y-%m-%dT%H:%M:%S)+COMPLETED_AFTER=$(date -d '1 hour ago' +%s)++all_runs="[]"++for wf in "${WORKFLOWS[@]}"; do+ runs=$(gh run list \+ --workflow "${wf}" \+ --created ">=${CREATED_SINCE}" \+ --json databaseId,conclusion,createdAt,updatedAt \+ --limit 50 2>/dev/null || echo "[]")+ all_runs=$(echo "$all_runs" "$runs" | jq -s 'add')+done++# Filter: drop in-progress (empty conclusion), keep only recently finished+echo "$all_runs" | jq --argjson cutoff "$COMPLETED_AFTER" '+ [ .[]+ | select(.conclusion != null and .conclusion != "")+ | select((.updatedAt | fromdateiso8601) >= $cutoff)+ ]+'diff --git a/.github/workflows/claude-hourly-review-reviewers.yaml b/.github/workflows/claude-hourly-review-reviewers.yamlindex 8ab17cc1b..0eb096701 100644--- a/.github/workflows/claude-hourly-review-reviewers.yaml+++ b/.github/workflows/claude-hourly-review-reviewers.yaml@@ -54,15 +54,9 @@ jobs:## Step 1: Find recent Claude CI runs- Use `gh run list` to find all runs from Claude workflows in the past hour:+ Run `.github/scripts/list-recent-runs.sh` to get a JSON array of recently completed Claude CI runs (filters out in-progress runs and keeps only those that finished in the past hour — see script comments for details).- ```- for wf in claude-review claude-ci-fix claude-issue-triage claude-mention claude-renovate claude-hourly-review-reviewers claude-nightly-cleaner; do- gh run list --workflow "${wf}.yaml" --created ">=$(date -d '1 hour ago' +%Y-%m-%dT%H:%M:%S)" --json databaseId,conclusion,createdAt --limit 50- done- ```-- If no Claude CI runs occurred in the past hour, report "no runs to review" and exit.+ If the output is an empty array, report "no runs to review" and exit.## Step 2: Download session logs