Skip to content

Commit 59d1dd5

Browse files
refactor(code-review): Renames and moving files around
Renames the "code-review-local" things from "cli-bug-prediction" or "cli-pr-review"
1 parent 70f0142 commit 59d1dd5

File tree

7 files changed

+87
-85
lines changed

7 files changed

+87
-85
lines changed

src/sentry/api/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
OrganizationAuthTokenDetailsEndpoint,
1212
)
1313
from sentry.api.endpoints.organization_auth_tokens import OrganizationAuthTokensEndpoint
14-
from sentry.api.endpoints.organization_cli_bug_prediction import OrganizationCodeReviewLocalEndpoint
1514
from sentry.api.endpoints.organization_events_root_cause_analysis import (
1615
OrganizationEventsRootCauseAnalysisEndpoint,
1716
)
@@ -526,6 +525,7 @@
526525
ProjectRuleGroupHistoryIndexEndpoint,
527526
)
528527
from sentry.rules.history.endpoints.project_rule_stats import ProjectRuleStatsIndexEndpoint
528+
from sentry.seer.code_review.endpoints.code_review_local import OrganizationCodeReviewLocalEndpoint
529529
from sentry.seer.endpoints.group_ai_autofix import GroupAutofixEndpoint
530530
from sentry.seer.endpoints.group_ai_summary import GroupAiSummaryEndpoint
531531
from sentry.seer.endpoints.group_autofix_setup_check import GroupAutofixSetupCheck

src/sentry/api/endpoints/organization_cli_bug_prediction.py renamed to src/sentry/seer/code_review/endpoints/code_review_local.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
from sentry.api.api_publish_status import ApiPublishStatus
1313
from sentry.api.base import region_silo_endpoint
1414
from sentry.api.bases.organization import OrganizationEndpoint, OrganizationIntegrationsPermission
15-
from sentry.api.serializers.rest_framework.cli_bug_prediction import (
16-
CliBugPredictionRequestSerializer,
17-
)
1815
from sentry.models.organization import Organization
1916
from sentry.models.repository import Repository
20-
from sentry.seer.cli_bug_prediction import get_cli_bug_prediction_status, trigger_cli_bug_prediction
17+
from sentry.seer.code_review.endpoints.serializers.code_review_local import (
18+
CodeReviewLocalRequestSerializer,
19+
)
20+
from sentry.seer.code_review_local import get_code_review_local_status, trigger_code_review_local
2121
from sentry.utils import metrics
2222

2323
logger = logging.getLogger(__name__)
@@ -90,7 +90,7 @@ def post(self, request: Request, organization: Organization) -> Response:
9090
)
9191

9292
# Validate request
93-
serializer = CliBugPredictionRequestSerializer(data=request.data)
93+
serializer = CodeReviewLocalRequestSerializer(data=request.data)
9494
if not serializer.is_valid():
9595
return Response({"detail": serializer.errors}, status=400)
9696

@@ -137,7 +137,7 @@ def post(self, request: Request, organization: Organization) -> Response:
137137
user_name = request.user.username or getattr(request.user, "email", None) or str(user_id)
138138

139139
try:
140-
trigger_response = trigger_cli_bug_prediction(
140+
trigger_response = trigger_code_review_local(
141141
repo_provider=repo_data["provider"],
142142
repo_owner=repo_data["owner"],
143143
repo_name=repo_data["name"],
@@ -291,7 +291,9 @@ def _resolve_repository(
291291
provider_variants.append(f"integrations:{repo_provider}")
292292

293293
return Repository.objects.get(
294-
organization_id=organization.id, name=repo_name, provider__in=provider_variants
294+
organization_id=organization.id,
295+
name=repo_name,
296+
provider__in=provider_variants,
295297
)
296298

297299
def _poll_seer_for_results(
@@ -331,7 +333,7 @@ def _poll_seer_for_results(
331333
)
332334

333335
try:
334-
response = get_cli_bug_prediction_status(run_id)
336+
response = get_code_review_local_status(run_id)
335337
except (UrllibTimeoutError, MaxRetryError):
336338
# If status check times out, wait and retry
337339
logger.warning(

src/sentry/api/serializers/rest_framework/cli_bug_prediction.py renamed to src/sentry/seer/code_review/endpoints/serializers/code_review_local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def validate_base_commit_sha(self, value):
1616
return value
1717

1818

19-
class CliBugPredictionRequestSerializer(serializers.Serializer):
19+
class CodeReviewLocalRequestSerializer(serializers.Serializer):
2020
repository = RepositoryInfoSerializer(required=True)
2121
diff = serializers.CharField(required=True, max_length=500_000)
2222
current_branch = serializers.CharField(required=False, max_length=255)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
)
1919

2020

21-
def trigger_cli_bug_prediction(
21+
def trigger_code_review_local(
2222
repo_provider: str,
2323
repo_owner: str,
2424
repo_name: str,
@@ -156,12 +156,12 @@ def trigger_cli_bug_prediction(
156156
return response_data
157157

158158

159-
def get_cli_bug_prediction_status(run_id: int) -> dict[str, Any]:
159+
def get_code_review_local_status(run_id: int) -> dict[str, Any]:
160160
"""
161161
Get the status of a CLI bug prediction run.
162162
163163
Args:
164-
run_id: The Seer run ID from trigger_cli_bug_prediction
164+
run_id: The Seer run ID from trigger_code_review_local
165165
166166
Returns:
167167
dict with "status" key and optionally "predictions" and "diagnostics"

tests/sentry/api/endpoints/test_organization_cli_bug_prediction.py renamed to tests/sentry/seer/code_review/endpoints/test_code_review_local.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
@pytest.mark.django_db
11-
class OrganizationCliBugPredictionTest(APITestCase):
11+
class OrganizationCodeReviewLocalTest(APITestCase):
1212
endpoint = "sentry-api-0-organization-code-review-local"
1313
method = "post"
1414

@@ -18,7 +18,7 @@ def setUp(self):
1818
self.project = self.create_project(organization=self.organization)
1919
self.repository = self.create_repo(
2020
project=self.project,
21-
name="test-repo",
21+
name="getsentry/test-repo",
2222
provider="github",
2323
external_id="12345",
2424
)
@@ -36,8 +36,8 @@ def setUp(self):
3636
self.login_as(user=self.user)
3737

3838
@with_feature("organizations:code-review-local")
39-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
40-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
39+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
40+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
4141
def test_happy_path(self, mock_status, mock_trigger):
4242
"""Test successful prediction request"""
4343
mock_trigger.return_value = {"run_id": 123, "status": "pending"}
@@ -176,7 +176,7 @@ def test_repository_not_found(self):
176176
assert "not found" in response.data["detail"]
177177

178178
@with_feature("organizations:code-review-local")
179-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
179+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
180180
def test_seer_trigger_timeout(self, mock_trigger):
181181
"""Test handling of Seer trigger timeout"""
182182
from urllib3.exceptions import TimeoutError
@@ -192,7 +192,7 @@ def test_seer_trigger_timeout(self, mock_trigger):
192192
assert "unavailable" in response.data["detail"]
193193

194194
@with_feature("organizations:code-review-local")
195-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
195+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
196196
def test_seer_trigger_error(self, mock_trigger):
197197
"""Test handling of Seer trigger error"""
198198
mock_trigger.side_effect = ValueError("Seer error")
@@ -203,12 +203,12 @@ def test_seer_trigger_error(self, mock_trigger):
203203
status_code=502,
204204
)
205205

206-
assert "Failed" in response.data["detail"]
206+
assert "error" in response.data["detail"].lower()
207207

208208
@with_feature("organizations:code-review-local")
209-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
210-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
211-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.time")
209+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
210+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
211+
@patch("sentry.seer.code_review.endpoints.code_review_local.time")
212212
def test_seer_polling_timeout(self, mock_time_module, mock_status, mock_trigger):
213213
"""Test handling of polling timeout"""
214214
mock_trigger.return_value = {"run_id": 123, "status": "pending"}
@@ -234,8 +234,8 @@ def fake_time():
234234
assert "exceeded maximum processing time" in response.data["detail"]
235235

236236
@with_feature("organizations:code-review-local")
237-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
238-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
237+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
238+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
239239
def test_seer_error_base_commit_not_found(self, mock_status, mock_trigger):
240240
"""Test mapping of base commit not found error"""
241241
mock_trigger.return_value = {"run_id": 123, "status": "pending"}
@@ -253,8 +253,8 @@ def test_seer_error_base_commit_not_found(self, mock_status, mock_trigger):
253253
assert "pushed to the remote" in response.data["detail"]
254254

255255
@with_feature("organizations:code-review-local")
256-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
257-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
256+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
257+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
258258
def test_seer_error_diff_too_large(self, mock_status, mock_trigger):
259259
"""Test mapping of diff too large error"""
260260
mock_trigger.return_value = {"run_id": 123, "status": "pending"}
@@ -272,8 +272,8 @@ def test_seer_error_diff_too_large(self, mock_status, mock_trigger):
272272
assert "500KB" in response.data["detail"]
273273

274274
@with_feature("organizations:code-review-local")
275-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
276-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
275+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
276+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
277277
def test_seer_error_too_many_files(self, mock_status, mock_trigger):
278278
"""Test mapping of too many files error"""
279279
mock_trigger.return_value = {"run_id": 123, "status": "pending"}
@@ -291,8 +291,8 @@ def test_seer_error_too_many_files(self, mock_status, mock_trigger):
291291
assert "50 files" in response.data["detail"]
292292

293293
@with_feature("organizations:code-review-local")
294-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
295-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
294+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
295+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
296296
def test_seer_error_clone_failed(self, mock_status, mock_trigger):
297297
"""Test mapping of repository clone failed error"""
298298
mock_trigger.return_value = {"run_id": 123, "status": "pending"}
@@ -310,8 +310,8 @@ def test_seer_error_clone_failed(self, mock_status, mock_trigger):
310310
assert "permissions" in response.data["detail"]
311311

312312
@with_feature("organizations:code-review-local")
313-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
314-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
313+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
314+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
315315
def test_seer_error_unknown(self, mock_status, mock_trigger):
316316
"""Test mapping of unknown Seer error"""
317317
mock_trigger.return_value = {"run_id": 123, "status": "pending"}
@@ -358,8 +358,8 @@ def test_rate_limit_org(self, mock_is_limited):
358358
assert "Organization rate limit exceeded" in response.data["detail"]
359359

360360
@with_feature("organizations:code-review-local")
361-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
362-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
361+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
362+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
363363
def test_optional_fields(self, mock_status, mock_trigger):
364364
"""Test that optional fields are not required"""
365365
mock_trigger.return_value = {"run_id": 123, "status": "pending"}

tests/sentry/api/test_cli_bug_prediction_integration.py renamed to tests/sentry/seer/code_review/test_code_review_local_integration.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
@pytest.mark.django_db
10-
class CliBugPredictionIntegrationTest(APITestCase):
10+
class CodeReviewLocalIntegrationTest(APITestCase):
1111
"""
1212
Integration tests for CLI bug prediction end-to-end flow.
1313
@@ -23,7 +23,7 @@ def setUp(self):
2323
self.project = self.create_project(organization=self.organization)
2424
self.repository = self.create_repo(
2525
project=self.project,
26-
name="test-repo",
26+
name="getsentry/test-repo",
2727
provider="github",
2828
external_id="12345",
2929
)
@@ -39,8 +39,8 @@ def setUp(self):
3939
self.login_as(user=self.user)
4040

4141
@with_feature("organizations:code-review-local")
42-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
43-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
42+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
43+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
4444
def test_end_to_end_single_poll(self, mock_status, mock_trigger):
4545
"""Test end-to-end flow with immediate completion"""
4646
mock_trigger.return_value = {"run_id": 123, "status": "pending"}
@@ -75,8 +75,8 @@ def test_end_to_end_single_poll(self, mock_status, mock_trigger):
7575
assert len(response.data["predictions"]) == 1
7676

7777
@with_feature("organizations:code-review-local")
78-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
79-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
78+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
79+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
8080
@patch("time.sleep")
8181
def test_end_to_end_multiple_polls(self, mock_sleep, mock_status, mock_trigger):
8282
"""Test end-to-end flow with multiple polling cycles"""
@@ -120,8 +120,8 @@ def test_end_to_end_multiple_polls(self, mock_sleep, mock_status, mock_trigger):
120120
assert response.data["predictions"][0]["severity"] == "high"
121121

122122
@with_feature("organizations:code-review-local")
123-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
124-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
123+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
124+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
125125
@patch("time.sleep")
126126
def test_status_check_network_error_recovery(self, mock_sleep, mock_status, mock_trigger):
127127
"""Test that network errors during status check are retried"""
@@ -152,8 +152,8 @@ def test_status_check_network_error_recovery(self, mock_sleep, mock_status, mock
152152
assert response.data["status"] == "completed"
153153

154154
@with_feature("organizations:code-review-local")
155-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
156-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
155+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
156+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
157157
def test_empty_predictions_response(self, mock_status, mock_trigger):
158158
"""Test handling of completed status with no predictions"""
159159
mock_trigger.return_value = {"run_id": 999, "status": "pending"}
@@ -175,8 +175,8 @@ def test_empty_predictions_response(self, mock_status, mock_trigger):
175175
assert response.data["diagnostics"]["files_analyzed"] == 5
176176

177177
@with_feature("organizations:code-review-local")
178-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
179-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
178+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
179+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
180180
@patch("time.sleep")
181181
def test_multiple_predictions(self, mock_sleep, mock_status, mock_trigger):
182182
"""Test handling of multiple predictions in response"""
@@ -222,8 +222,8 @@ def test_multiple_predictions(self, mock_sleep, mock_status, mock_trigger):
222222
assert response.data["predictions"][2]["severity"] == "low"
223223

224224
@with_feature("organizations:code-review-local")
225-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
226-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
225+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
226+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
227227
@patch("time.sleep")
228228
def test_seer_state_transition_pending_to_completed(
229229
self, mock_sleep, mock_status, mock_trigger
@@ -250,8 +250,8 @@ def test_seer_state_transition_pending_to_completed(
250250
assert response.data["status"] == "completed"
251251

252252
@with_feature("organizations:code-review-local")
253-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
254-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
253+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
254+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
255255
@patch("time.sleep")
256256
def test_seer_state_transition_with_in_progress(self, mock_sleep, mock_status, mock_trigger):
257257
"""Test state transition: pending -> in_progress -> completed"""
@@ -277,8 +277,8 @@ def test_seer_state_transition_with_in_progress(self, mock_sleep, mock_status, m
277277
assert response.data["status"] == "completed"
278278

279279
@with_feature("organizations:code-review-local")
280-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.trigger_cli_bug_prediction")
281-
@patch("sentry.api.endpoints.organization_cli_bug_prediction.get_cli_bug_prediction_status")
280+
@patch("sentry.seer.code_review.endpoints.code_review_local.trigger_code_review_local")
281+
@patch("sentry.seer.code_review.endpoints.code_review_local.get_code_review_local_status")
282282
def test_diagnostics_included_in_response(self, mock_status, mock_trigger):
283283
"""Test that diagnostics are properly included in response"""
284284
mock_trigger.return_value = {"run_id": 444, "status": "pending"}

0 commit comments

Comments
 (0)