Skip to content

Commit 70f0142

Browse files
some fixes from testing locally the sentry --> seer connection
1 parent f117f34 commit 70f0142

2 files changed

Lines changed: 55 additions & 17 deletions

File tree

src/sentry/api/endpoints/organization_cli_bug_prediction.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,18 @@ def post(self, request: Request, organization: Organization) -> Response:
100100
commit_message = validated_data.get("commit_message")
101101

102102
# Resolve repository
103+
# Repository names in the database are stored as "owner/name" (e.g., "getsentry/sentry")
104+
full_repo_name = f"{repo_data['owner']}/{repo_data['name']}"
103105
try:
104106
repository = self._resolve_repository(
105107
organization=organization,
106-
repo_name=repo_data["name"],
108+
repo_name=full_repo_name,
107109
repo_provider=repo_data["provider"],
108110
)
109111
except Repository.DoesNotExist:
110112
return Response(
111113
{
112-
"detail": f"Repository {repo_data['owner']}/{repo_data['name']} not found. "
114+
"detail": f"Repository {full_repo_name} not found. "
113115
"Please ensure the repository is connected to Sentry via an integration."
114116
},
115117
status=404,
@@ -159,15 +161,35 @@ def post(self, request: Request, organization: Organization) -> Response:
159161
return Response(
160162
{"detail": "Code review service is temporarily unavailable"}, status=503
161163
)
162-
except ValueError:
164+
except ValueError as e:
163165
logger.exception(
164166
"code_review_local.trigger.error",
165167
extra={
166168
"organization_id": organization.id,
167169
"user_id": request.user.id,
170+
"error": str(e),
168171
},
169172
)
173+
# Include the error message from Seer if available
174+
error_msg = str(e)
175+
if "Seer error" in error_msg:
176+
return Response({"detail": error_msg}, status=502)
170177
return Response({"detail": "Failed to start code review analysis"}, status=502)
178+
except Exception as e:
179+
# Catch-all for unexpected errors
180+
logger.exception(
181+
"code_review_local.trigger.unexpected_error",
182+
extra={
183+
"organization_id": organization.id,
184+
"user_id": request.user.id,
185+
"error_type": type(e).__name__,
186+
"error": str(e),
187+
},
188+
)
189+
return Response(
190+
{"detail": f"Unexpected error during code review: {type(e).__name__}"},
191+
status=500,
192+
)
171193

172194
run_id = trigger_response["run_id"]
173195

@@ -262,8 +284,14 @@ def _resolve_repository(
262284
Raises:
263285
Repository.DoesNotExist: If repository not found
264286
"""
287+
# Map simple provider names to integration provider names
288+
# Repositories created via integrations use "integrations:github" format
289+
provider_variants = [repo_provider]
290+
if not repo_provider.startswith("integrations:"):
291+
provider_variants.append(f"integrations:{repo_provider}")
292+
265293
return Repository.objects.get(
266-
organization_id=organization.id, name=repo_name, provider=repo_provider
294+
organization_id=organization.id, name=repo_name, provider__in=provider_variants
267295
)
268296

269297
def _poll_seer_for_results(

src/sentry/seer/cli_bug_prediction.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ def trigger_cli_bug_prediction(
5555
MaxRetryError: If max retries exceeded
5656
ValueError: If response is invalid
5757
"""
58-
body_dict = {
59-
"repo_provider": repo_provider,
60-
"repo_owner": repo_owner,
61-
"repo_name": repo_name,
62-
"repo_external_id": repo_external_id,
63-
"base_commit_sha": base_commit_sha,
58+
body_dict: dict[str, Any] = {
59+
"repo": {
60+
"provider": repo_provider,
61+
"owner": repo_owner,
62+
"name": repo_name,
63+
"external_id": repo_external_id,
64+
"base_commit_sha": base_commit_sha,
65+
},
6466
"diff": diff,
6567
"organization_id": organization_id,
6668
"organization_slug": organization_slug,
@@ -100,16 +102,24 @@ def trigger_cli_bug_prediction(
100102
raise
101103

102104
if response.status >= 400:
105+
# Try to extract error message from Seer's response
106+
error_detail = ""
107+
try:
108+
error_data = json.loads(response.data)
109+
error_detail = error_data.get("detail", error_data.get("message", str(error_data)))
110+
except (JSONDecodeError, TypeError):
111+
error_detail = response.data.decode("utf-8") if response.data else "Unknown error"
112+
103113
logger.error(
104114
"seer.cli_bug_prediction.trigger.error",
105115
extra={
106116
"organization_id": organization_id,
107117
"user_id": user_id,
108118
"status_code": response.status,
109-
"response_data": response.data,
119+
"error_detail": error_detail,
110120
},
111121
)
112-
raise ValueError(f"Seer returned error status: {response.status}")
122+
raise ValueError(f"Seer error ({response.status}): {error_detail}")
113123

114124
try:
115125
response_data = json.loads(response.data)
@@ -164,11 +174,11 @@ def get_cli_bug_prediction_status(run_id: int) -> dict[str, Any]:
164174
logger.debug("seer.cli_bug_prediction.status.check", extra={"run_id": run_id})
165175

166176
try:
167-
# Use POST with run_id in body for status check (Seer pattern)
168-
response = make_signed_seer_api_request(
169-
connection_pool=seer_cli_bug_prediction_connection_pool,
170-
path=f"/v1/automation/codegen/cli-bug-prediction/{run_id}",
171-
body=json.dumps({"run_id": run_id}).encode("utf-8"),
177+
# Seer status endpoint uses GET method
178+
response = seer_cli_bug_prediction_connection_pool.urlopen(
179+
"GET",
180+
f"/v1/automation/codegen/cli-bug-prediction/{run_id}",
181+
headers={"content-type": "application/json;charset=utf-8"},
172182
timeout=5,
173183
)
174184
except (TimeoutError, MaxRetryError):

0 commit comments

Comments
 (0)