feat: handle repo rename webhooks for Bitbucket and Bitbucket Server#884
feat: handle repo rename webhooks for Bitbucket and Bitbucket Server#884drazisil-codecov wants to merge 1 commit into
Conversation
Triggers a sync when a repo is renamed, reducing the window where a stale slug could be claimed by another repo. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6900986. Configure here.
| PULL_REQUEST_REJECTED = "pullrequest:rejected" | ||
| PULL_REQUEST_FULFILLED = "pullrequest:fulfilled" | ||
| REPO_PUSH = "repo:push" | ||
| REPO_UPDATED = "repo:updated" |
There was a problem hiding this comment.
Bitbucket Cloud repo:updated not in webhook subscription list
High Severity
REPO_UPDATED is added as a constant and a handler is wired up, but it's never added to subscribed_events. More critically, WEBHOOK_EVENTS["bitbucket"] in apps/worker/services/repository.py also omits repo:updated. This means Bitbucket Cloud is never told to deliver repo:updated events, so the new handler will never fire. Bitbucket Server works because repo:modified was already present in both lists before this PR.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 6900986. Configure here.
| sync_repos=True, | ||
| using_integration=True, | ||
| ) | ||
| return Response() |
There was a problem hiding this comment.
GitHub-specific using_integration=True breaks Bitbucket sync task
High Severity
Both new handlers pass using_integration=True to TaskService().refresh(), but the downstream sync_repos task documents this flag as "specific to GitHub users." When True, it calls sync_repos_using_integration() which invokes list_repos_using_installation_generator() — a method only implemented on the GitHub adapter, not on the Bitbucket or Bitbucket Server adapters. This will cause an AttributeError at runtime when the sync task executes.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 6900986. Configure here.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #884 +/- ##
=======================================
Coverage 92.26% 92.26%
=======================================
Files 1307 1307
Lines 48014 48027 +13
Branches 1632 1632
=======================================
+ Hits 44298 44311 +13
Misses 3407 3407
Partials 309 309
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |


Summary
repo:updated(Bitbucket Cloud) andrepo:modified(Bitbucket Server) webhook eventsTaskService().refresh()on rename, reducing the window where a stale slug could be claimed by another repoSecurity concern addressed (per Michelle's review of #883)
The slug staleness window after a rename could allow a different workspace to register a repo under the old slug. This is mitigated by:
Tests cover both the sync trigger and the UUID-based lookup under a slug collision scenario.
Test plan
test_repo_updated_triggers_sync—repo:updatedcallsTaskService.refreshwith correct argstest_repo_updated_lookup_by_uuid_not_slug— sync is triggered for the correct repo even when another workspace has registered a repo with the old nametest_repo_modified_triggers_sync— same for Bitbucket Serverrepo:modifiedtest_repo_modified_lookup_by_service_id_not_slug— same slug collision test for Bitbucket Server🤖 Generated with Claude Code
Note
Medium Risk
Adds new webhook event handling that triggers
TaskService.refresh, which can change sync behavior and increase background task load for Bitbucket/Bitbucket Server installations. Logic is straightforward but touches webhook routing and repo identification, so regressions could affect integrations.Overview
Adds support for Bitbucket Cloud
repo:updatedand Bitbucket Serverrepo:modifiedwebhooks and routes them to a new handler that callsTaskService().refresh(sync_repos=True)to promptly resync repositories after renames.Extends test coverage to ensure these rename events trigger a refresh and that repo lookup is resilient under slug-collision scenarios (verifying identification by UUID/service_id rather than repo name).
Reviewed by Cursor Bugbot for commit 6900986. Bugbot is set up for automated code reviews on this repo. Configure here.