Skip to content

Support for pull requests opened events from forked repositories#5536

Merged
xoxys merged 5 commits into
woodpecker-ci:mainfrom
henkka:bbdc-fix-fork-prs
Sep 28, 2025
Merged

Support for pull requests opened events from forked repositories#5536
xoxys merged 5 commits into
woodpecker-ci:mainfrom
henkka:bbdc-fix-fork-prs

Conversation

@henkka

@henkka henkka commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

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 (fromRef in Bitbucket terms) instead of the target repository (toRef in 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:

  • The target repository is the one configured in Woodpecker CI
  • Pull request builds should run in the context of the target repository
  • This aligns with how other forge integrations handle forked repository pull requests

@6543 6543 added bug Something isn't working forge/bitbucket bitbucket forge related labels Sep 22, 2025
@6543

6543 commented Sep 22, 2025

Copy link
Copy Markdown
Member

@henkka could you add an example webhook payload json into server/forge/bitbucketdatacenter/fixtures ?

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

@henkka

henkka commented Sep 22, 2025

Copy link
Copy Markdown
Contributor Author

sure, I'll take a look at it tomorrow :)

@6543

6543 commented Sep 23, 2025

Copy link
Copy Markdown
Member

thats nice ... i was just asking about json test dummy data but that refactor sure is welcome ;)

@henkka

henkka commented Sep 23, 2025

Copy link
Copy Markdown
Contributor Author

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

Comment thread server/forge/bitbucketdatacenter/parse.go Outdated
@henkka

henkka commented Sep 23, 2025

Copy link
Copy Markdown
Contributor Author

@henkka could you add an example webhook payload json into server/forge/bitbucketdatacenter/fixtures ?

@6543 This has been done now, the webhook payloads were fetched from our Bitbucket datacenter instance calling Woodpecker CI /api/hook and then scrubbed.

@codecov

codecov Bot commented Sep 23, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 51.72414% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 26.37%. Comparing base (0bd69e8) to head (58f72b0).
⚠️ Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
...r/forge/bitbucketdatacenter/bitbucketdatacenter.go 0.00% 9 Missing ⚠️
server/forge/bitbucketdatacenter/parse.go 75.00% 4 Missing and 1 partial ⚠️
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.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xoxys xoxys left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@xoxys

xoxys commented Sep 23, 2025

Copy link
Copy Markdown
Member

@langecode Would you like to take a look as well?

@xoxys xoxys changed the title fix(bitbucketdc): support for pull requests opened events from forked repositories Support for pull requests opened events from forked repositories Sep 23, 2025

@6543 6543 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks!

@qwerty287

Copy link
Copy Markdown
Contributor

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.

@xoxys xoxys merged commit 99dee09 into woodpecker-ci:main Sep 28, 2025
9 checks passed
@woodpecker-bot woodpecker-bot mentioned this pull request Sep 28, 2025
1 task
@henkka

henkka commented Oct 1, 2025

Copy link
Copy Markdown
Contributor Author

Sure, you can ping me as well :)

@henkka henkka deleted the bbdc-fix-fork-prs branch October 1, 2025 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working forge/bitbucket bitbucket forge related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants