-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable updating webhook events for published integration (#75903)
This PR enables updating events for published apps. There is a bug where we would prevent updating the webhook events because the scopes were out of order which actually turned out to be a blessing in disguise because the current implementation for updating the service hooks was not correct for published integrations which are installed by multiple integrations. As it happens, for that to work we have to update _every_ `ServiceHook` row that is attached to that integration. Because there could be thousands of them, I put that logic in a task because it would almost certainly time out if there are many installations. Note I still have to update the UI next so we allow updating the installation; right now the UI will prevent the update.
- Loading branch information
Showing
4 changed files
with
288 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from sentry.models.integrations.sentry_app_installation import SentryAppInstallation | ||
from sentry.sentry_apps.services.hook import hook_service | ||
|
||
|
||
def create_or_update_service_hooks_for_installation( | ||
installation: SentryAppInstallation, webhook_url: str, events: list[str] | ||
) -> None: | ||
""" | ||
This function creates or updates service hooks for a given Sentry app installation. | ||
It first attempts to update the webhook URL and events for existing service hooks. | ||
If no hooks are found and a webhook URL is provided, it creates a new service hook. | ||
Should only be called in the control silo | ||
""" | ||
hooks = hook_service.update_webhook_and_events( | ||
organization_id=installation.organization_id, | ||
application_id=installation.sentry_app.application_id, | ||
webhook_url=webhook_url, | ||
events=events, | ||
) | ||
if webhook_url and not hooks: | ||
# Note that because the update transaction is disjoint with this transaction, it is still | ||
# possible we redundantly create service hooks in the face of two concurrent requests. | ||
# If this proves a problem, we would need to add an additional semantic, "only create if does not exist". | ||
# But I think, it should be fine. | ||
hook_service.create_service_hook( | ||
application_id=installation.sentry_app.application_id, | ||
actor_id=installation.id, | ||
installation_id=installation.id, | ||
organization_id=installation.organization_id, | ||
project_ids=[], | ||
events=events, | ||
url=webhook_url, | ||
) |
This file contains 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