Skip to content

Commit 4d3895d

Browse files
cursoragentarmenzg
andcommitted
Fix silent no-op on repository migration updates
Co-authored-by: Armen Zambrano G. <armenzg@users.noreply.github.com>
1 parent fc8b217 commit 4d3895d

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

src/sentry/integrations/api/endpoints/organization_repository_details.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,26 @@ def put(self, request: Request, organization: Organization, repo_id) -> Response
8181
update_kwargs["status"] = ObjectStatus.HIDDEN
8282
else:
8383
raise NotImplementedError
84-
if update_kwargs:
85-
old_status = repo.status
86-
with transaction.atomic(router.db_for_write(Repository)):
87-
repo.update(**update_kwargs)
88-
if (
89-
old_status == ObjectStatus.PENDING_DELETION
90-
and repo.status == ObjectStatus.ACTIVE
91-
):
92-
repo.reset_pending_deletion_field_names()
93-
repo.delete_pending_deletion_option()
94-
elif repo.status == ObjectStatus.HIDDEN and old_status != repo.status:
95-
repository_cascade_delete_on_hide.apply_async(kwargs={"repo_id": repo.id})
96-
97-
if repo.external_id and repo.provider:
98-
cleanup_seer_repository_preferences.apply_async(
99-
kwargs={
100-
"organization_id": repo.organization_id,
101-
"repo_external_id": repo.external_id,
102-
"repo_provider": repo.provider,
103-
}
104-
)
84+
if not update_kwargs:
85+
return Response({"detail": "No valid update fields were provided"}, status=400)
86+
87+
old_status = repo.status
88+
with transaction.atomic(router.db_for_write(Repository)):
89+
repo.update(**update_kwargs)
90+
if old_status == ObjectStatus.PENDING_DELETION and repo.status == ObjectStatus.ACTIVE:
91+
repo.reset_pending_deletion_field_names()
92+
repo.delete_pending_deletion_option()
93+
elif repo.status == ObjectStatus.HIDDEN and old_status != repo.status:
94+
repository_cascade_delete_on_hide.apply_async(kwargs={"repo_id": repo.id})
95+
96+
if repo.external_id and repo.provider:
97+
cleanup_seer_repository_preferences.apply_async(
98+
kwargs={
99+
"organization_id": repo.organization_id,
100+
"repo_external_id": repo.external_id,
101+
"repo_provider": repo.provider,
102+
}
103+
)
105104

106105
return Response(serialize(repo, request.user))
107106

tests/sentry/integrations/api/endpoints/test_organization_repository_details.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def test_put_hide_repo_with_commits(self, mock_cleanup_task: MagicMock) -> None:
323323
}
324324
)
325325

326-
def test_put_does_not_change_provider(self) -> None:
326+
def test_put_rejects_integration_id(self) -> None:
327327
self.login_as(user=self.user)
328328

329329
org = self.create_organization(owner=self.user, name="baz")
@@ -339,9 +339,10 @@ def test_put_does_not_change_provider(self) -> None:
339339
)
340340

341341
url = reverse("sentry-api-0-organization-repository-details", args=[org.slug, repo.id])
342-
response = self.client.put(url, data={"status": "visible", "integrationId": integration.id})
342+
response = self.client.put(url, data={"integrationId": integration.id})
343343

344-
assert response.status_code == 200
344+
assert response.status_code == 400
345+
assert response.data["detail"] == "No valid update fields were provided"
345346

346347
repo = Repository.objects.get(id=repo.id)
347348
assert repo.provider == "integrations:github"

0 commit comments

Comments
 (0)