Skip to content

Commit f43dd7c

Browse files
fix(ai-code-review): Add on_new_commit flag
1 parent 2233b18 commit f43dd7c

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

src/sentry/features/temporary.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def register_temporary_features(manager: FeatureManager) -> None:
7878
manager.add("organizations:chonk-ui-feedback", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
7979
# Enables Codecov UI
8080
manager.add("organizations:codecov-ui", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
81+
# Enable Prevent AI code review to run per commit
82+
manager.add("organizations:code-review-run-per-commit", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=False)
8183
# Enables Prevent Test Analytics
8284
manager.add("organizations:prevent-test-analytics", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
8385
# Enable the improved command menu (Cmd+K)

src/sentry/overwatch/endpoints/overwatch_rpc.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from sentry.models.organization import Organization
2626
from sentry.models.repository import Repository
2727
from sentry.prevent.models import PreventAIConfiguration
28-
from sentry.prevent.types.config import PREVENT_AI_CONFIG_DEFAULT
28+
from sentry.prevent.types.config import PREVENT_AI_CONFIG_DEFAULT, PREVENT_AI_CONFIG_DEFAULT_V1
2929
from sentry.silo.base import SiloMode
3030

3131
logger = logging.getLogger(__name__)
@@ -154,7 +154,13 @@ def get(self, request: Request) -> Response:
154154
integration_id=github_org_integrations[0].integration_id,
155155
).first()
156156

157-
response_data: dict[str, Any] = deepcopy(PREVENT_AI_CONFIG_DEFAULT)
157+
organization = Organization.objects.filter(id=sentry_org_id).first()
158+
159+
default_config = PREVENT_AI_CONFIG_DEFAULT
160+
if features.has("organizations:code-review-run-per-commit", organization):
161+
default_config = PREVENT_AI_CONFIG_DEFAULT_V1
162+
163+
response_data: dict[str, Any] = deepcopy(default_config)
158164
if config:
159165
response_data["organization"] = config.data
160166

src/sentry/prevent/endpoints/pr_review_github_config.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from rest_framework.request import Request
66
from rest_framework.response import Response
77

8-
from sentry import audit_log
8+
from sentry import audit_log, features
99
from sentry.api.api_owners import ApiOwner
1010
from sentry.api.api_publish_status import ApiPublishStatus
1111
from sentry.api.base import region_silo_endpoint
@@ -15,7 +15,11 @@
1515
from sentry.integrations.types import IntegrationProviderSlug
1616
from sentry.models.organization import Organization
1717
from sentry.prevent.models import PreventAIConfiguration
18-
from sentry.prevent.types.config import ORG_CONFIG_SCHEMA, PREVENT_AI_CONFIG_DEFAULT
18+
from sentry.prevent.types.config import (
19+
ORG_CONFIG_SCHEMA,
20+
PREVENT_AI_CONFIG_DEFAULT,
21+
PREVENT_AI_CONFIG_DEFAULT_V1,
22+
)
1923

2024

2125
class PreventAIConfigPermission(OrganizationPermission):
@@ -59,7 +63,11 @@ def get(
5963
integration_id=github_org_integrations[0].integration_id,
6064
).first()
6165

62-
response_data: dict[str, Any] = deepcopy(PREVENT_AI_CONFIG_DEFAULT)
66+
default_config = PREVENT_AI_CONFIG_DEFAULT
67+
if features.has("organizations:code-review-run-per-commit", organization):
68+
default_config = PREVENT_AI_CONFIG_DEFAULT_V1
69+
70+
response_data: dict[str, Any] = deepcopy(default_config)
6371
if config:
6472
response_data["organization"] = config.data
6573

src/sentry/prevent/types/config.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,40 @@
125125
},
126126
"organization": {},
127127
}
128+
129+
PREVENT_AI_CONFIG_DEFAULT_V1 = {
130+
"schema_version": "v1",
131+
"default_org_config": {
132+
"org_defaults": {
133+
"bug_prediction": {
134+
"enabled": True,
135+
"sensitivity": "medium",
136+
"triggers": {
137+
"on_command_phrase": True,
138+
"on_ready_for_review": True,
139+
# v1 default enables on_new_commit
140+
"on_new_commit": True,
141+
},
142+
},
143+
"test_generation": {
144+
"enabled": True,
145+
"triggers": {
146+
"on_command_phrase": True,
147+
"on_ready_for_review": False,
148+
"on_new_commit": False,
149+
},
150+
},
151+
"vanilla": {
152+
"enabled": True,
153+
"sensitivity": "medium",
154+
"triggers": {
155+
"on_command_phrase": True,
156+
"on_ready_for_review": False,
157+
"on_new_commit": False,
158+
},
159+
},
160+
},
161+
"repo_overrides": {},
162+
},
163+
"organization": {},
164+
}

0 commit comments

Comments
 (0)