fix(gh): fix re-run button on Pull Requests#2597
fix(gh): fix re-run button on Pull Requests#2597chmouel wants to merge 1 commit intotektoncd:mainfrom
Conversation
|
/gemini review |
There was a problem hiding this comment.
Pull request overview
This PR fixes GitHub check_run / check_suite “rerequested” handling for fork PRs where the webhook payload can have head_branch: null and an empty pull_requests list, by falling back to resolving the PR via commit SHA instead of misclassifying the event as a push.
Changes:
- Update GitHub payload parsing to resolve PR rerequests by commit SHA when
head_branchis missing. - Add unit tests covering the new SHA-resolution behavior and the error case when no PR is found.
- Extend the GitHub GHE e2e rerequest test to exercise the null-
head_branchcheck_runscenario; add a new JSON fixture.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
pkg/provider/github/parse_payload.go |
Adds SHA-based PR lookup fallback for rerequest events when head_branch is missing. |
pkg/provider/github/parse_payload_test.go |
Adds unit tests for null-head_branch rerequest behavior (success + failure). |
test/github_pullrequest_rerequest_test.go |
Adds an e2e scenario sending a check_run rerequest with null head_branch and empty PR list. |
test/fixtures/check_suite_rerequest_null_branch.json |
Adds a fixture representing a null-head_branch check_suite/check_run rerequest payload. |
Comments suppressed due to low confidence (1)
pkg/provider/github/parse_payload.go:495
- In the check_run rerequest fallback where this is treated as a push event,
runevent.TriggerTargetis never set (unlikehandleCheckSuites, which sets it to "push"). Downstream logic (e.g., changed-files fetching/switches on TriggerTarget) may treat an empty TriggerTarget as unknown and skip important behavior. Setrunevent.TriggerTarget = triggertype.Push(or "push") alongsiderunevent.EventType = "push"for consistency.
runevent.BaseBranch = runevent.HeadBranch
runevent.BaseURL = runevent.HeadURL
runevent.EventType = "push"
// we allow the rerequest user here, not the push user, i guess it's
// fine because you can't do a rereq without being a github owner?
runevent.Sender = event.GetSender().GetLogin()
v.userType = event.GetSender().GetType()
return runevent, nil
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Review from Gemini CodeI've taken a deep look at this pull request. Here is my assessment: The Problem: The Fix: Testing:
Conclusion: |
GitHub check_run and check_suite rerequests for fork PRs can have a null head_branch and an empty pull_requests list. PAC was falling back to treating these events as push events, causing the Re-run button on PRs to have no effect. When head_branch is null, fall back to looking up the associated PR by commit SHA before deciding the event type. If a PR is found, process as a PR rerequest. If not, return a clear error. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com> Assisted-by: Claude Sonnet 4.6 (via Claude Code) Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
98e1889 to
7c8d958
Compare
|
/test linters |
|
/cancel linters |
|
/retest |
| if len(event.GetCheckSuite().PullRequests) == 0 { | ||
| // If head_branch is null, try to find a PR by SHA before assuming push | ||
| if runevent.HeadBranch == "" && runevent.SHA != "" { | ||
| prs, err := v.getPullRequestsWithCommit(ctx, runevent.SHA, runevent.Organization, runevent.Repository, false) |
There was a problem hiding this comment.
it might be possible that there are multiple pull requests associated with the commit, so can you please research more how we can figure out that first PR is the one on which re-request is clicked?
| runevent.PullRequestNumber = prs[0].GetNumber() | ||
| runevent.TriggerTarget = triggertype.PullRequest | ||
| v.Logger.Infof("Rerun of all checks on PR %s/%s#%d has been requested (resolved from SHA)", runevent.Organization, runevent.Repository, runevent.PullRequestNumber) | ||
| return v.getPullRequest(ctx, runevent) |
There was a problem hiding this comment.
if we've fetched the PR from getPullRequestsWithCommit then we don't need to call getPullRequest again here because we have PR object and we have all the info. and also it will open the door for A Time-of-Check to Time-of-Use (TOCTOU) race condition attack.
| if len(event.GetCheckRun().GetCheckSuite().PullRequests) == 0 { | ||
| // If head_branch is null, try to find a PR by SHA before assuming push | ||
| if runevent.HeadBranch == "" && runevent.SHA != "" { | ||
| prs, err := v.getPullRequestsWithCommit(ctx, runevent.SHA, runevent.Organization, runevent.Repository, false) |
📝 Description of the Change
GitHub check_run and check_suite rerequests for fork PRs can have
a null head_branch and an empty pull_requests list. PAC was falling
back to treating these events as push events, causing the Re-run
button on PRs to have no effect.
When head_branch is null, fall back to looking up the associated PR
by commit SHA before deciding the event type. If a PR is found,
process as a PR rerequest. If not, return a clear error.
output.mp4
🔗 Linked Issue
Jira https://redhat.atlassian.net/browse/SRVKP-11161
🧪 Testing Strategy
🤖 AI Assistance
AI assistance can be used for various tasks, such as code generation,
documentation, or testing.
Please indicate whether you have used AI assistance
for this PR and provide details if applicable.
Important
Slop will be simply rejected, if you are using AI assistance you need to make sure you
understand the code generated and that it meets the project's standards. you
need at least know how to run the code and deploy it (if needed). See
startpaac to make it easy
to deploy and test your code changes.
If the majority of the code in this PR was generated by an AI, please add a
Co-authored-bytrailer to your commit message.For example:
Co-authored-by: Claude noreply@anthropic.com
✅ Submitter Checklist
fix:,feat:) matches the "Type of Change" I selected above.make testandmake lintlocally to check for and fix anyissues. For an efficient workflow, I have considered installing
pre-commit and running
pre-commit installtoautomate these checks.