-
Notifications
You must be signed in to change notification settings - Fork 177
fix(scripts): query workflow runs by branch name instead of pull_requests field #3794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,12 +197,15 @@ AUTH_HEADER="Authorization: token $GITHUB_TOKEN" | |
|
|
||
| echo "Fetching workflow runs for PR #$PR_NUMBER..." | ||
|
|
||
| # Fetch the most recent workflow run for this PR (regardless of overall conclusion) | ||
| # Get the branch name for this PR | ||
| BRANCH=$(gh pr view "$PR_NUMBER" --json headRefName -q '.headRefName') | ||
|
|
||
| # Fetch the most recent workflow run for this PR's branch | ||
| RUN_ID=$(curl -sf -H "$AUTH_HEADER" \ | ||
| "https://api.github.com/repos/$REPO/actions/runs?event=push&per_page=100" \ | ||
| | jq -r --arg PR "$PR_NUMBER" --arg WF "$WORKFLOW_FILE" ' | ||
| "https://api.github.com/repos/$REPO/actions/runs?per_page=100" \ | ||
| | jq -r --arg BRANCH "$BRANCH" --arg WF "$WORKFLOW_FILE" ' | ||
|
Comment on lines
204
to
+206
|
||
| [.workflow_runs[] | ||
| | select(.pull_requests[]?.number == ($PR|tonumber)) | ||
| | select(.head_branch == $BRANCH) | ||
| | select(.path == (".github/workflows/" + $WF)) | ||
|
Comment on lines
+206
to
209
|
||
| ] | ||
| | sort_by(.run_number) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gh pr viewhere relies on the current directory’s repo context, but the script’s API calls are hard-coded to$REPO. If someone runs this from a fork/other checkout,ghmay fetch the wrong PR (or fail), producing an incorrectBRANCH. Pass--repo "$REPO"and add a small guard thatBRANCHis non-empty/non-null before continuing.