ref(integrations): Move webhook creation to post-create hook#112699
Merged
ref(integrations): Move webhook creation to post-create hook#112699
Conversation
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.
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
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.
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.
… 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>
cmanallen
approved these changes
Apr 13, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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.