rerun-failed-checks.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env bash
  2. # Get the list of open pull requests authored by you
  3. prs=$(gh pr list --state open --author "${1:-@me}" --json number,title,url,createdAt --jq '.[] | "#\(.number) \(.title) (\(.createdAt | fromdateiso8601 | strftime("%Y-%m-%d")))"')
  4. # If there are no open PRs, exit
  5. if [ -z "$prs" ]; then
  6. echo "No open pull requests found."
  7. exit 0
  8. fi
  9. # Use fzf to select the PR
  10. selected_pr=$(echo "$prs" | fzf --prompt="Select PR: " --height 15 --border --ansi)
  11. if [ -z "$selected_pr" ]; then
  12. echo "No PR selected."
  13. exit 0
  14. fi
  15. # Extract the PR number from the selected PR
  16. pr_number=$(echo "$selected_pr" | awk '{print $1}')
  17. # Get the commit SHA associated with the selected PR
  18. commit_sha=$(gh pr view "$pr_number" --json headRefOid --jq '.headRefOid')
  19. # Get the run ID of the failed PR Entrypoint check
  20. failed_pr_run=$(gh run list --commit "$commit_sha" --workflow "PR Entrypoint" --json databaseId,status,conclusion --jq '.[] | select(.status == "completed" and (.conclusion == "failure" or .conclusion == "cancelled")) | .databaseId')
  21. # If there are no failed runs, exit
  22. if [ -z "$failed_pr_run" ]; then
  23. echo "No failed runs found for PR $pr_number."
  24. exit 0
  25. fi
  26. # Rerun all failed checks for the selected run
  27. echo "Rerunning failed checks for run ID: $failed_pr_run"
  28. gh run rerun "$failed_pr_run" --failed
  29. echo "Failed checks have been rerun for PR $pr_number, run ID $failed_pr_run."