Skip to content

Commit b751f2f

Browse files
cursoragentarmenzg
andcommitted
fix(gitlab): Fix search value and validation order bugs
- Fix search endpoint to return numeric project IDs instead of path_with_namespace to maintain backward compatibility with existing issue creation/linking flows - Move status validation before deletion of existing IntegrationExternalProject records to prevent data loss if validation fails Co-authored-by: Armen Zambrano G. <armenzg@users.noreply.github.com>
1 parent 3f8cf58 commit b751f2f

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/sentry/integrations/gitlab/integration.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,9 @@ def update_organization_config(self, data: MutableMapping[str, Any]) -> None:
353353
):
354354
raise IntegrationError("Resolve and unresolve status are required.")
355355

356-
data["sync_status_forward"] = bool(project_mappings)
357-
358-
IntegrationExternalProject.objects.filter(
359-
organization_integration_id=self.org_integration.id
360-
).delete()
361-
356+
# Validate status values before deleting existing records
357+
valid_statuses = {GitLabIssueStatus.OPENED.value, GitLabIssueStatus.CLOSED.value}
362358
for project_path, statuses in project_mappings.items():
363-
# Validate status values
364-
valid_statuses = {GitLabIssueStatus.OPENED.value, GitLabIssueStatus.CLOSED.value}
365359
if statuses["on_resolve"] not in valid_statuses:
366360
raise IntegrationError(
367361
f"Invalid resolve status: {statuses['on_resolve']}. Must be 'opened' or 'closed'."
@@ -371,6 +365,13 @@ def update_organization_config(self, data: MutableMapping[str, Any]) -> None:
371365
f"Invalid unresolve status: {statuses['on_unresolve']}. Must be 'opened' or 'closed'."
372366
)
373367

368+
data["sync_status_forward"] = bool(project_mappings)
369+
370+
IntegrationExternalProject.objects.filter(
371+
organization_integration_id=self.org_integration.id
372+
).delete()
373+
374+
for project_path, statuses in project_mappings.items():
374375
IntegrationExternalProject.objects.create(
375376
organization_integration_id=self.org_integration.id,
376377
external_id=project_path,

src/sentry/integrations/gitlab/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def handle_search_repositories(
7979
[
8080
{
8181
"label": project["name_with_namespace"],
82-
"value": project["path_with_namespace"],
82+
"value": project["id"],
8383
}
8484
for project in response
8585
]

0 commit comments

Comments
 (0)