fix: populate DefaultBranch for incoming webhooks#2647
fix: populate DefaultBranch for incoming webhooks#2647theakshaypant merged 1 commit intotektoncd:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the GitHub provider to ensure the DefaultBranch is correctly populated for incoming webhooks. Since incoming webhooks lack a payload containing this information, the code now fetches it directly from the GitHub API when necessary. Corresponding test cases and mocks have been added to verify this behavior and ensure existing values are preserved. I have no feedback to provide.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2647 +/- ##
=======================================
Coverage 58.80% 58.80%
=======================================
Files 206 206
Lines 20296 20304 +8
=======================================
+ Hits 11935 11940 +5
- Misses 7589 7591 +2
- Partials 772 773 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
this lgtm but please consider adding a e2e test, |
Ok, will do 👼🏼 |
fad9fd0 to
d1ec2ef
Compare
Incoming webhooks bypass ParsePayload, which means the event's DefaultBranch field is never set. When pipelinerun_provenance is set to 'default_branch' on the Repository CR, GetTektonDir() uses the empty DefaultBranch as the git tree revision, causing a 404 from the GitHub API. Fix this by fetching the repository's default branch from the GitHub API in GetCommitInfo() when the event type is 'incoming' and DefaultBranch is empty. Also fix a pre-existing test gap: the 'error' test case in TestGithubGetCommitInfo was missing wantErr, and the test was not checking for err == nil on the success path. Fixes: tektoncd#2646
d1ec2ef to
fd69fa3
Compare
📝 Description of the Change
Incoming webhooks bypass
ParsePayload, which means the event'sDefaultBranchfield is never set. Whenpipelinerun_provenanceisset to
default_branchon the Repository CR,GetTektonDir()usesthe empty
DefaultBranchas the git tree revision, causing a 404from the GitHub API.
Root Cause
In
pkg/adapter/incoming.go, the event fields set for incoming webhooksinclude
HeadBranch,BaseBranch,URL, etc., butDefaultBranchisnever populated. For push/PR events, it comes from the webhook payload's
repository.default_branchfield viaParsePayload, but incomingwebhooks skip that code path entirely.
Fix
In
GetCommitInfo()(GitHub provider), when the event type isincomingand
DefaultBranchis empty, fetch the repository metadata from theGitHub API to populate it. This is the same approach used by the
Bitbucket Data Center provider.
Test Changes
DefaultBranchpopulationerrortest case was missingwantErrassert.NilErrorcheck on the success path🔗 Linked GitHub Issue
Fixes #2646
🧪 Testing Strategy
🤖 AI Assistance
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 any issues./kind bug