fix: recover fork PR re-runs when GitHub omits PR metadata#2655
fix: recover fork PR re-runs when GitHub omits PR metadata#2655chmouel wants to merge 1 commit intotektoncd:mainfrom
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2655 +/- ##
==========================================
+ Coverage 58.85% 58.94% +0.08%
==========================================
Files 204 204
Lines 20149 20193 +44
==========================================
+ Hits 11859 11903 +44
Misses 7525 7525
Partials 765 765 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces a fallback mechanism to resolve pull requests by SHA when the standard commit API fails, which is particularly useful for fork PRs. It also adds logic to extract pull request information directly from the check_run event. Feedback focuses on ensuring consistency and handling ambiguity when multiple pull requests might match a single SHA or check run, suggesting the use of existing helper functions to validate that only a single open pull request is processed.
3282631 to
212adf3
Compare
|
tested on dogfooding as working |
5f94900 to
8a5873e
Compare
|
|
||
| // ListPullRequestsWithCommit may return no matches for fork PR commits. | ||
| v.Logger.Infof("No PR found via commits API for SHA %s, falling back to open PR listing", runevent.SHA) | ||
| return v.findOpenPullRequestBySHA(ctx, runevent.Organization, runevent.Repository, runevent.SHA) |
There was a problem hiding this comment.
can we call the findOpenPullRequestBySHA only if its fork because if its not fork and there is no matching PRs as well then it would be just redundant API calls! (hint: event.pull_request.head.fork)
| // If we don't have a pull_request in this it probably mean a push | ||
| if len(event.GetCheckRun().GetCheckSuite().PullRequests) == 0 { | ||
| if len(event.GetCheckRun().PullRequests) > 0 { | ||
| runevent.PullRequestNumber = event.GetCheckRun().PullRequests[0].GetNumber() |
There was a problem hiding this comment.
is it certain here that first PR would be the exact PR where rerun is made?
There was a problem hiding this comment.
there is no guarantee enough to keep using PullRequests[0] blindly, so I added a small guard for this path.
check_run.pull_requests now fails fast if GitHub gives us more than one associated PR in the webhook payload instead of guessing.
There was a problem hiding this comment.
check_run.pull_requests now fails fast if GitHub gives us more than one associated PR in the webhook payload instead of guessing.
you're going to add or you did it? I don't see anything?
8a5873e to
c6a4c49
Compare
When someone clicks Re-run on a Pipelines as Code check for a pull request coming from a fork, GitHub can leave out the usual pull request details in the webhook payload. That left PAC with no obvious way to tell which pull request the check belonged to, so the re-run stopped with an error instead of starting again. This change teaches PAC to keep looking in a more practical way. If the first GitHub API says it cannot find the pull request for the commit, PAC now lists open pull requests in the repository and matches the one whose head commit SHA is the same. In simple terms: when GitHub does not hand us the answer directly, we now look through the open pull requests and find the one built from that exact commit. The change also checks pull request data attached directly to the check_run event before falling back to SHA-based lookup, and the tests now cover both the new fork pull request path and the empty-result error cases. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
c6a4c49 to
6ecab48
Compare
| if len(checkSuite.PullRequests) > 0 { | ||
| runevent.PullRequestNumber = checkSuite.PullRequests[0].GetNumber() | ||
| runevent.TriggerTarget = triggertype.PullRequest | ||
| v.Logger.Infof("Recheck of PR %s/%s#%d has been requested", runevent.Organization, runevent.Repository, runevent.PullRequestNumber) | ||
| return v.getPullRequest(ctx, runevent) | ||
| } |
There was a problem hiding this comment.
| if len(checkSuite.PullRequests) > 0 { | |
| runevent.PullRequestNumber = checkSuite.PullRequests[0].GetNumber() | |
| runevent.TriggerTarget = triggertype.PullRequest | |
| v.Logger.Infof("Recheck of PR %s/%s#%d has been requested", runevent.Organization, runevent.Repository, runevent.PullRequestNumber) | |
| return v.getPullRequest(ctx, runevent) | |
| } |
There was a problem hiding this comment.
you can delete this as you're already doing this on line 557 below
When GitHub receives a Re-run request for a Pipelines as Code check tied to a pull request from a fork, the webhook payload can omit the usual pull request metadata. PAC could already recover by looking up pull requests for the head SHA, but fork PRs still failed when GitHub's
commits/{sha}/pullsAPI returned no matches.This change makes rerequest handling more resilient and keeps the selection rules safe:
📝 Description of the Change
Improve GitHub rerequest PR resolution so fork pull requests can be recovered safely even when GitHub omits PR metadata or the commit lookup API returns no match.
🔗 Linked GitHub Issue
Not linked.
🧪 Testing Strategy
Ran:
go test ./pkg/provider/github🤖 AI Assistance
AI assistance was used to help draft and refine the code change, tests, and PR description. The resulting changes were reviewed and validated with the package test run above.
✅ 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.