Closed j04n-f closed 3 months ago
We found the issue. The Pull Request hook parser is using the destination information, it should use the source:
diff --git a/server/forge/bitbucket/convert.go b/server/forge/bitbucket/convert.go
index af573cbff..e64522f94 100644
--- a/server/forge/bitbucket/convert.go
+++ b/server/forge/bitbucket/convert.go
@@ -170,14 +170,14 @@ func convertPullHook(from *internal.PullRequestHook) *model.Pipeline {
return &model.Pipeline{
Event: event,
- Commit: from.PullRequest.Dest.Commit.Hash,
- Ref: fmt.Sprintf("refs/heads/%s", from.PullRequest.Dest.Branch.Name),
+ Commit: from.PullRequest.Source.Commit.Hash,
+ Ref: fmt.Sprintf("refs/heads/%s", from.PullRequest.Source.Branch.Name),
Refspec: fmt.Sprintf("%s:%s",
from.PullRequest.Source.Branch.Name,
from.PullRequest.Dest.Branch.Name,
),
ForgeURL: from.PullRequest.Links.HTML.Href,
- Branch: from.PullRequest.Dest.Branch.Name,
+ Branch: from.PullRequest.Source.Branch.Name,
Message: from.PullRequest.Desc,
Avatar: from.Actor.Links.Avatar.Href,
Author: from.Actor.Login,
Once this is fixed, another issue happens related to how the pipeline pulls the code:
+ git init -b ${Branch}
Initialized empty Git repository in /woodpecker/src/bitbucket.org/**
+ git config --global --replace-all safe.directory /woodpecker/src/bitbucket.org/***
+ git remote add origin https://bitbucket.org/**
+ git fetch --no-tags --depth=1 --filter=tree:0 origin +${Commit}: # Full SHA required
From https://bitbucket.org/**
* branch ${Commit} -> FETCH_HEAD # Full SHA required
+ git reset --hard -q ${Commit} # Full SHA required
The problem is that the Bitbucket Webhooks are not consistent. The pull request update webhook returns a short SHA, not the full one: https://jira.atlassian.com/browse/BCLOUD-21201.
We can change the plugin-git
to ensure it always uses the full SHA: git rev-parse 3cdd5d
-> 3cdd5d19178a54d2e51b5098d43b57571241d0ab
WDYT @qwerty287 ? We can create the PRs.
If that fixes the issues, yes, just open the PRs! :)
The clone step should checkout the pull request branch
Agree.
and (Woodpecker should) use the pull request workflow
Disagree. Everyone can do anything with your pipeline, including secrets.
Disagree. Everyone can do anything with your pipeline, including secrets.
No, it should use the PR ones. Currently this is the behavior for all forges and this issue is just about bitbucket, so this is just a bug and the PR one should be used.
However, not running the PR configuration has some disadvantages as you can't test your workflows anymore. You should use protected repos to prevent attacks like this (and yes, this feature needs more improvements to be more flexible).
Jenkins, GitHub and GitLab use the Pull Request branch workflows. Imaging you added a required input to your tests and the Pull Request runs the default branch workflow, it will fail. You will have to merge your changes without testing them.
You are right:
Disagree. Everyone can do anything with your pipeline, including secrets.
They mitigate this issues adding access and execution policies to the workflows (e.g. who can run them or who has access to the secrets).
qwerty
(thanks for clarification)So, sorry to bother this thread, go ahead and fix the bug :)
@qwerty287 @6543 Whenever you have a moment, can you review https://github.com/woodpecker-ci/plugin-git/pull/160? This is the last PR to close this issue. Thanks!
https://github.com/woodpecker-ci/plugin-git/pull/161 -> 2.5.2 is available
Pull Request integration for BB is working as expected now. Thanks!
Component
server
Describe the bug
Goal
Run formatters and tests after pushing a new commit to a pull request.
Forge
Bitbucket Cloud
Issue
The clone step checkouts the default branch and uses the default branch workflow. It should checkout the pull request branch and use the pull request workflow.
Workflow
Logs
Additional Information
pullrequest:updated
, it was not enabled by default. Probably because it is not selected by default when Woodpecker creates the webhook: https://github.com/woodpecker-ci/woodpecker/blob/d6e3ebf051a978702b46f67327ac7b44c761978e/server/forge/bitbucket/bitbucket.go#L316Steps to reproduce
pullrequest:updated
clone: git: image: woodpeckerci/plugin-git settings: partial: false
steps: echo: image: ubuntu commands:
clone: git: image: woodpeckerci/plugin-git settings: partial: false
steps: echo: image: ubuntu commands:
Expected behavior
The clone step should checkout the Pull Request workflow and code instead of checking out the default branch.
System Info
Additional context
No response
Validations
next
version already [https://woodpecker-ci.org/faq#which-version-of-woodpecker-should-i-use]