-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(code-review): Handle auto enable code review on repoCreated #104666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
5205e70
38e7084
a7175c1
32a483d
adc5dfb
fb4bcc0
a7331b7
231ce86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,13 @@ | |
|
|
||
| from django.contrib.postgres.fields.array import ArrayField | ||
| from django.db import models | ||
| from django.db.models.signals import pre_delete | ||
| from django.db.models.signals import post_save, pre_delete | ||
| from django.utils import timezone | ||
|
|
||
| from sentry.backup.dependencies import NormalizedModelName, get_model_name | ||
| from sentry.backup.sanitize import SanitizableField, Sanitizer | ||
| from sentry.backup.scopes import RelocationScope | ||
| from sentry.constants import ObjectStatus | ||
| from sentry.constants import DEFAULT_CODE_REVIEW_TRIGGERS, ObjectStatus | ||
| from sentry.db.models import ( | ||
| BoundedBigIntegerField, | ||
| BoundedPositiveIntegerField, | ||
|
|
@@ -24,6 +24,8 @@ | |
| rename_on_pending_deletion, | ||
| reset_pending_deletion_field_names, | ||
| ) | ||
| from sentry.models.options.organization_option import OrganizationOption | ||
| from sentry.models.repositorysettings import RepositorySettings | ||
| from sentry.organizations.services.organization.service import organization_service | ||
| from sentry.signals import pending_delete | ||
| from sentry.users.services.user import RpcUser | ||
|
|
@@ -186,3 +188,40 @@ def handle_exception(e): | |
| sender=Repository, | ||
| weak=False, | ||
| ) | ||
|
|
||
|
|
||
| def handle_auto_enable_code_review(instance: Repository) -> None: | ||
| """ | ||
| When a new repository is created, auto enable code review if applicable. | ||
| """ | ||
|
|
||
| SUPPORTED_PROVIDERS = {"integrations:github"} | ||
|
|
||
| if instance.provider not in SUPPORTED_PROVIDERS: | ||
| return | ||
|
|
||
| if OrganizationOption.objects.get_value( | ||
| organization=instance.organization_id, | ||
| key="sentry:auto_enable_code_review", | ||
| default=False, | ||
| ): | ||
| triggers = OrganizationOption.objects.get_value( | ||
| organization=instance.organization_id, | ||
| key="sentry:default_code_review_triggers", | ||
| default=[], | ||
| ) | ||
|
||
| if not isinstance(triggers, list): | ||
| triggers = DEFAULT_CODE_REVIEW_TRIGGERS | ||
|
|
||
| RepositorySettings.objects.get_or_create( | ||
| repository_id=instance.id, | ||
| defaults={"enabled_code_review": True, "code_review_triggers": triggers}, | ||
| ) | ||
|
|
||
|
|
||
| def on_repository_created(sender, instance, created, **kwargs): | ||
| if created: | ||
| handle_auto_enable_code_review(instance) | ||
|
|
||
|
|
||
| post_save.connect(on_repository_created, sender=Repository, weak=False) | ||
|
||
Uh oh!
There was an error while loading. Please reload this page.