Skip to content

ref(integrations): Move webhook creation to post-create hook#112699

Merged
wedamija merged 3 commits intomasterfrom
danf/repo-sync-webhook-creation
Apr 13, 2026
Merged

ref(integrations): Move webhook creation to post-create hook#112699
wedamija merged 3 commits intomasterfrom
danf/repo-sync-webhook-creation

Conversation

@wedamija
Copy link
Copy Markdown
Member

build_repository_config for GitLab, Bitbucket, and Bitbucket Server created webhooks eagerly before checking if the repo already existed in Sentry. This blocked adding those providers to the repo sync task, since it would create webhooks for every repo on every sync run.

This introduces on_create_repository hook that fires only after a repo is actually persisted. Webhooks are now created at the right time and skipped if the repo already has one. This unblocks adding all remaining SCM providers to the periodic sync.

build_repository_config for GitLab, Bitbucket, and Bitbucket Server created webhooks eagerly before checking if the repo already existed in Sentry. This blocked adding those providers to the repo sync task, since it would create webhooks for every repo on every sync run.

This introduces on_create_repository hook that fires only after a repo is actually persisted. Webhooks are now created at the right time and skipped if the repo already has one. This unblocks adding all remaining SCM providers to the periodic sync.
@wedamija wedamija requested a review from a team April 10, 2026 18:10
@wedamija wedamija requested review from a team as code owners April 10, 2026 18:10
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 10, 2026
Comment thread src/sentry/plugins/providers/integration_repository.py
Copy link
Copy Markdown
Contributor

@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 prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Config overwrite defeats webhook_id guard check
    • Modified _update_repository to preserve existing webhook_id before applying new config, preventing duplicate webhook creation.
  • ✅ Fixed: Existing repo update silently loses webhook_id reference
    • Added webhook_id preservation in create_repository's existing repo update path to prevent KeyError on deletion.

Create PR

Or push these changes by commenting:

@cursor push 00ccd942f5
Preview (00ccd942f5)
diff --git a/src/sentry/plugins/providers/integration_repository.py b/src/sentry/plugins/providers/integration_repository.py
--- a/src/sentry/plugins/providers/integration_repository.py
+++ b/src/sentry/plugins/providers/integration_repository.py
@@ -192,8 +192,11 @@
             if repositories:
                 # We anticipate to only update one repository, but we update any duplicates as well.
                 for repo in repositories:
+                    existing_webhook_id = repo.config.get("webhook_id") if repo.config else None
                     for field_name, field_value in repo_update_params.items():
                         setattr(repo, field_name, field_value)
+                    if existing_webhook_id:
+                        repo.config["webhook_id"] = existing_webhook_id
                     repository_service.update_repository(
                         organization_id=organization.id,
                         update=repo,
@@ -206,8 +209,11 @@
     def _update_repository(self, repo: RpcRepository, config: RepositoryConfig):
         repo.status = ObjectStatus.ACTIVE
 
+        existing_webhook_id = repo.config.get("webhook_id") if repo.config else None
         for field_name, field_value in config.items():
             setattr(repo, field_name, field_value)
+        if existing_webhook_id and "config" in config:
+            repo.config["webhook_id"] = existing_webhook_id
         return repo
 
     def _update_repositories(

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 28d149d. Configure here.

Comment thread src/sentry/plugins/providers/integration_repository.py
Comment thread src/sentry/plugins/providers/integration_repository.py
… webhook_id

When updating existing repositories, config was being fully replaced
with the output of build_repository_config which no longer includes
webhook_id. This would wipe the existing webhook reference, causing
on_create_repository to create duplicate webhooks and on_delete_repository
to fail with a missing key.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wedamija wedamija merged commit 3d7ef01 into master Apr 13, 2026
57 checks passed
@wedamija wedamija deleted the danf/repo-sync-webhook-creation branch April 13, 2026 17:24
wedamija added a commit that referenced this pull request Apr 13, 2026
build_repository_config for GitLab, Bitbucket, and Bitbucket Server created webhooks eagerly before checking if the repo already existed in Sentry. This blocked adding those providers to the repo sync task, since it would create webhooks for every repo on every sync run.

This introduces on_create_repository hook that fires only after a repo is actually persisted. Webhooks are now created at the right time and skipped if the repo already has one. This unblocks adding all remaining SCM providers to the periodic sync.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants