Skip to content

feat: handle repo rename webhooks for Bitbucket and Bitbucket Server#884

Open
drazisil-codecov wants to merge 1 commit into
mainfrom
feat/bitbucket-repo-renamed-webhook
Open

feat: handle repo rename webhooks for Bitbucket and Bitbucket Server#884
drazisil-codecov wants to merge 1 commit into
mainfrom
feat/bitbucket-repo-renamed-webhook

Conversation

@drazisil-codecov
Copy link
Copy Markdown
Contributor

@drazisil-codecov drazisil-codecov commented Apr 23, 2026

Summary

Security 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:

  1. Triggering an immediate sync on rename so Codecov updates the slug quickly
  2. Webhook lookup uses UUID / service_id (not slug), so even during the staleness window the original repo's webhooks are correctly routed

Tests cover both the sync trigger and the UUID-based lookup under a slug collision scenario.

Test plan

  • test_repo_updated_triggers_syncrepo:updated calls TaskService.refresh with correct args
  • test_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 name
  • test_repo_modified_triggers_sync — same for Bitbucket Server repo:modified
  • test_repo_modified_lookup_by_service_id_not_slug — same slug collision test for Bitbucket Server
  • All 24 existing Bitbucket/Bitbucket Server webhook tests still pass

🤖 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:updated and Bitbucket Server repo:modified webhooks and routes them to a new handler that calls TaskService().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.

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>
@drazisil-codecov drazisil-codecov marked this pull request as ready for review April 23, 2026 14:20
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ 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"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6900986. Configure here.

sync_repos=True,
using_integration=True,
)
return Response()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6900986. Configure here.

@sentry
Copy link
Copy Markdown
Contributor

sentry Bot commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.26%. Comparing base (1f0784c) to head (6900986).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

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           
Flag Coverage Δ
apiunit 96.35% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-notifications
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant