Skip to content

fix: populate DefaultBranch for incoming webhooks#2647

Merged
theakshaypant merged 1 commit intotektoncd:mainfrom
vdemeester:fix-incoming-default-branch
Apr 8, 2026
Merged

fix: populate DefaultBranch for incoming webhooks#2647
theakshaypant merged 1 commit intotektoncd:mainfrom
vdemeester:fix-incoming-default-branch

Conversation

@vdemeester
Copy link
Copy Markdown
Member

@vdemeester vdemeester commented Apr 7, 2026

📝 Description of the Change

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.

Root Cause

In pkg/adapter/incoming.go, the event fields set for incoming webhooks
include HeadBranch, BaseBranch, URL, etc., but DefaultBranch is
never populated. For push/PR events, it comes from the webhook payload's
repository.default_branch field via ParsePayload, but incoming
webhooks skip that code path entirely.

Fix

In GetCommitInfo() (GitHub provider), when the event type is incoming
and DefaultBranch is empty, fetch the repository metadata from the
GitHub API to populate it. This is the same approach used by the
Bitbucket Data Center provider.

Test Changes

  • Added test cases for incoming webhook DefaultBranch population
  • Fixed pre-existing test gap: the error test case was missing wantErr
  • Added assert.NilError check on the success path

🔗 Linked GitHub Issue

Fixes #2646

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

🤖 AI Assistance

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

Co-authored-by: Claude noreply@anthropic.com

✅ Submitter Checklist

  • 📖 My commit messages are clear, informative, and follow the project's How to write a git commit message guide.
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • ♽ I have run make test and make lint locally to check for and fix any issues.
  • 📖 I have added or updated documentation for any user-facing changes.
  • 🧪 I have added sufficient unit tests for my code changes.
  • 🐛 I have added end-to-end tests where feasible.
  • 🔍 I have addressed any CI test flakiness or provided a clear reason to bypass it.

/kind bug

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 7, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.80%. Comparing base (a8db555) to head (fd69fa3).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/provider/github/github.go 62.50% 2 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chmouel
Copy link
Copy Markdown
Member

chmouel commented Apr 7, 2026

this lgtm but please consider adding a e2e test,

@vdemeester
Copy link
Copy Markdown
Member Author

this lgtm but please consider adding a e2e test,

Ok, will do 👼🏼

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
@zakisk zakisk force-pushed the fix-incoming-default-branch branch from d1ec2ef to fd69fa3 Compare April 7, 2026 18:15
@theakshaypant theakshaypant merged commit a387d41 into tektoncd:main Apr 8, 2026
13 checks passed
@vdemeester vdemeester deleted the fix-incoming-default-branch branch April 8, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

incoming webhook: pipelinerun_provenance default_branch fails because DefaultBranch is never set

5 participants