Support for pull requests opened events from forked repositories#5536
Conversation
|
@henkka could you add an example webhook payload json into If you dont want to write parsing tests, thats ok we just currently have non fixtures for BB-DC to begin with :/ for examples: https://github.com/woodpecker-ci/woodpecker/tree/main/server/forge/bitbucket/fixtures & https://github.com/woodpecker-ci/woodpecker/blob/main/server/forge/bitbucket/parse_test.go |
|
sure, I'll take a look at it tomorrow :) |
|
thats nice ... i was just asking about json test dummy data but that refactor sure is welcome ;) |
I decided it's easier to unit test the parsing logic if I'll extract the logic to its own function, but due to time constraints I didn't have time to write the tests (with the bitbucket webhook payloads) just yet. I'll try to get back to this later today |
for easier testing
351095e to
ad81b54
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5536 +/- ##
==========================================
+ Coverage 26.34% 26.37% +0.02%
==========================================
Files 405 406 +1
Lines 29031 29041 +10
==========================================
+ Hits 7649 7659 +10
+ Misses 20683 20682 -1
- Partials 699 700 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@langecode Would you like to take a look as well? |
|
I think we can also merge this now, and maybe, if that's fine for you @henkka: could we request you as well to check out bitbucket dc changes? No one of the maintainers has access to an instance. |
|
Sure, you can ping me as well :) |
Problem
When Bitbucket Data Center sends webhooks for pull requests from forked repositories to the /api/hook endpoint, Woodpecker CI returns a 400 error with the message "failure to parse hook".
Root Cause
The error occurs in the webhook handler https://github.com/woodpecker-ci/woodpecker/blob/main/server/forge/bitbucketdatacenter/bitbucketdatacenter.go#L499-L502 because Woodpecker CI incorrectly reads repository details from the pull request's source repository (
fromRefin Bitbucket terms) instead of the target repository (toRefin Bitbucket terms).For forked repositories, the source repository may not be accessible or configured in Woodpecker CI, causing the parsing to fail.
Webhook example payload available in https://confluence.atlassian.com/bitbucketserver/event-payload-938025882.html#Eventpayload-pr-opened
Solution
This change modifies the webhook handler to always read repository details from the pull request's target repository - the repository where the pull request will be merged. This ensures consistency since: