Skip to content

Commit

Permalink
fix: bitbucket pullrequest updates don't update preview deployments b…
Browse files Browse the repository at this point in the history
…y replacing repo:push with pullrequest:updated in bitbucket webhook hander

Bitbucket's repo:push webhook doesn't provide the destination branch name in new commits, 
which prevents Coolify from finding the correct application to update preview deployments. 
By switching to pullrequest:updated and only processing updates due to new commits, 
we can reliably get the correct branch name that matches the Coolify application, 
ensuring preview deployments are properly updated.

- Remove repo:push event handling in favor of pullrequest:updated
- Add check to ignore PR updates not related to new commits
- Update handled_events collection to reflect new webhook strategy

Closes coollabsio#2793
  • Loading branch information
IARayan authored Feb 1, 2025
1 parent a768761 commit 054dba4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions app/Http/Controllers/Webhook/Bitbucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ public function manual(Request $request)
$headers = $request->headers->all();
$x_bitbucket_token = data_get($headers, 'x-hub-signature.0', '');
$x_bitbucket_event = data_get($headers, 'x-event-key.0', '');
$handled_events = collect(['repo:push', 'pullrequest:created', 'pullrequest:rejected', 'pullrequest:fulfilled']);
$handled_events = collect(['pullrequest:updated', 'pullrequest:created', 'pullrequest:rejected', 'pullrequest:fulfilled']);
if (! $handled_events->contains($x_bitbucket_event)) {
return response([
'status' => 'failed',
'message' => 'Nothing to do. Event not handled.',
]);
}
if ($x_bitbucket_event === 'repo:push') {
$branch = data_get($payload, 'push.changes.0.new.name');
$full_name = data_get($payload, 'repository.full_name');
$commit = data_get($payload, 'push.changes.0.new.target.hash');
if (! $branch) {
if ($x_bitbucket_event === 'pullrequest:updated') {
if (!data_get($payload, 'changes.source.commit.hash')) {
return response([
'status' => 'failed',
'message' => 'Nothing to do. No branch found in the request.',
'status' => 'ignored',
'message' => 'Nothing to do. The PR update is not due to a new commit.',
]);
}
$branch = data_get($payload, 'pullrequest.destination.branch.name');
$full_name = data_get($payload, 'repository.full_name');
$commit = data_get($payload, 'pullrequest.source.commit.hash');
}
if ($x_bitbucket_event === 'pullrequest:created' || $x_bitbucket_event === 'pullrequest:rejected' || $x_bitbucket_event === 'pullrequest:fulfilled') {
$branch = data_get($payload, 'pullrequest.destination.branch.name');
Expand Down

0 comments on commit 054dba4

Please sign in to comment.