-
Notifications
You must be signed in to change notification settings - Fork 131
feat(bitbucketdatacenter): Added support for pull request events merged, modified, and approved #2749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(bitbucketdatacenter): Added support for pull request events merged, modified, and approved #2749
Changes from all commits
bd95e51
d146363
516b17a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,7 +38,7 @@ func (v *Provider) Detect(req *http.Request, payload string, logger *zap.Sugared | |||||||||||||
|
|
||||||||||||||
| switch e := eventPayload.(type) { | ||||||||||||||
| case *types.PullRequestEvent: | ||||||||||||||
| if provider.Valid(event, []string{"pr:from_ref_updated", "pr:opened"}) { | ||||||||||||||
| if provider.Valid(event, []string{"pr:from_ref_updated", "pr:opened", "pr:merged", "pr:modified", "pr:reviewer:approved"}) { | ||||||||||||||
| return setLoggerAndProceed(true, "", nil) | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+41
to
43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| if provider.Valid(event, []string{"pr:from_ref_updated", "pr:opened", "pr:merged", "pr:modified", "pr:reviewer:approved"}) { | |
| return setLoggerAndProceed(true, "", nil) | |
| } | |
| if provider.Valid(event, []string{"pr:from_ref_updated", "pr:opened"}) { | |
| return setLoggerAndProceed(true, "", nil) | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of these events trigger a pipeline run unless they are configured to do so in the bitbucket datacenter repository as specified in the PaC documentation. The goal with this PR is to be able to trigger a build on merge without needing to create a second pipeline run (push event (repo:refs_changed)) as suggested by this comment. If the repository maintainer determines that the events merged, modified, or approved are desirable event to trigger a build, why should the maintainer be limited by the provider implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree with Gemini's comment here wrt pr:merged, this would introduce confusing behaviour for users who have separate PipelineRuns configured for pull_request and push (on main). When a PR is merged to main, Bitbucket DC fires both pr:merged and repo:refs_changed. With the current mapping, both would trigger pipelines: pr:merged would run all on-event: [pull_request] PipelineRuns, and repo:refs_changed would run all on-event: [push] PipelineRuns. Users end up with multiple, possibly redundant PipelineRuns for a single merge.
This also introduces problems when the source branch is deleted after merge. When the system fetches pipeline definitions from the PR's source branch (which is the normal pull_request code path), those definitions become unreachable after a merge and delete. The system silently does nothing, users won't know why their close-event pipeline never triggered.
pr:merged should be handled in its own block and mapped to triggertype.PullRequestClosed, which is what every other provider does:
- GitHub: action == "closed" --> PullRequestClosed
- Bitbucket Cloud: pullrequest:fulfilled --> PullRequestClosed
- GitLab: action == "close" --> PullRequestClosed
- Gitea: action == "closed" --> PullRequestClosed
The PullRequestClosed path (pipelineascode.go:L66-L81) skips normal matching entirely, it doesn't create new PipelineRuns, it only cancels in-progress ones for that PR. This is the semantics for a merge (close) event followed by all other providers.
As for pr:modified, I don't fully understand the requirement of supporting it since it looks like a metadata-only change event (title, description, target branch edits). If a PR title is updated while pipelines are running and cancel-in-progress is enabled, the running PipelineRuns would be cancelled and restarted from scratch due to the new pull_request event. Could you elaborate how this event helps in your use case?
pr:reviewer:approved would also have similar cancel-in-progress behaviour, an approval would cancel running CI and restart it, which seems counterproductive.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -107,7 +107,7 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http. | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| switch e := eventPayload.(type) { | ||||||||||||||||||||||||
| case *types.PullRequestEvent: | ||||||||||||||||||||||||
| if provider.Valid(eventType, []string{"pr:from_ref_updated", "pr:opened"}) { | ||||||||||||||||||||||||
| if provider.Valid(eventType, []string{"pr:from_ref_updated", "pr:opened", "pr:merged", "pr:modified", "pr:reviewer:approved"}) { | ||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Semantically speaking, |
||||||||||||||||||||||||
| processedEvent.TriggerTarget = triggertype.PullRequest | ||||||||||||||||||||||||
| processedEvent.EventType = triggertype.PullRequest.String() | ||||||||||||||||||||||||
| } else if provider.Valid(eventType, []string{"pr:comment:added", "pr:comment:edited"}) { | ||||||||||||||||||||||||
|
Comment on lines
+110
to
113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly to the detection logic, mapping these events to if provider.Valid(eventType, []string{"pr:from_ref_updated", "pr:opened"}) {
processedEvent.TriggerTarget = triggertype.PullRequest
processedEvent.EventType = triggertype.PullRequest.String()
} |
||||||||||||||||||||||||
|
|
@@ -232,7 +232,7 @@ func parsePayloadType(event string) (any, error) { | |||||||||||||||||||||||
| var localEvent string | ||||||||||||||||||||||||
| if strings.HasPrefix(event, "pr:") { | ||||||||||||||||||||||||
| if !provider.Valid(event, []string{ | ||||||||||||||||||||||||
| "pr:from_ref_updated", "pr:opened", "pr:comment:added", "pr:comment:edited", | ||||||||||||||||||||||||
| "pr:from_ref_updated", "pr:opened", "pr:comment:added", "pr:comment:edited", "pr:merged", "pr:modified", "pr:reviewer:approved", | ||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||
| return nil, fmt.Errorf("event \"%s\" is not supported", event) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
234
to
238
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since these events should not trigger pipeline runs, they should not be registered as supported pull request payload types here.
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
pr:mergedis being introduced, docs should note the dual-trigger situation: when a PR is merged, Bitbucket DC fires bothpr:mergedandrepo:refs_changed. Users who enable both webhooks should configure their PipelineRun annotations to match only the event type they need to avoid duplicate execution.