@@ -190,14 +190,16 @@ def test_put_cancel_deletion(self):
190
190
organization_id = org .id , key = build_pending_deletion_key (repo )
191
191
).exists ()
192
192
193
- def test_put_hide_repo (self ):
193
+ @patch ("sentry.tasks.seer.cleanup_seer_repository_preferences.apply_async" )
194
+ def test_put_hide_repo (self , mock_cleanup_task ):
194
195
self .login_as (user = self .user )
195
196
196
197
org = self .create_organization (owner = self .user , name = "baz" )
197
198
198
199
repo = Repository .objects .create (
199
200
name = "uuid-name" ,
200
201
external_id = "uuid-external-id" ,
202
+ provider = "github" ,
201
203
organization_id = org .id ,
202
204
status = ObjectStatus .ACTIVE ,
203
205
)
@@ -210,12 +212,22 @@ def test_put_hide_repo(self):
210
212
repo = Repository .objects .get (id = repo .id )
211
213
assert repo .status == ObjectStatus .HIDDEN
212
214
213
- def test_put_hide_repo_with_commits (self ):
215
+ # Verify the cleanup task was called
216
+ mock_cleanup_task .assert_called_once_with (
217
+ kwargs = {
218
+ "organization_id" : org .id ,
219
+ "repo_external_id" : "uuid-external-id" ,
220
+ "repo_provider" : "github" ,
221
+ }
222
+ )
223
+
224
+ @patch ("sentry.tasks.seer.cleanup_seer_repository_preferences.apply_async" )
225
+ def test_put_hide_repo_with_commits (self , mock_cleanup_task ):
214
226
self .login_as (user = self .user )
215
227
216
228
org = self .create_organization (owner = self .user , name = "baz" )
217
229
repo = Repository .objects .create (
218
- name = "example" , organization_id = org .id , external_id = "abc123"
230
+ name = "example" , organization_id = org .id , external_id = "abc123" , provider = "github"
219
231
)
220
232
Commit .objects .create (repository_id = repo .id , key = "a" * 40 , organization_id = org .id )
221
233
@@ -229,6 +241,15 @@ def test_put_hide_repo_with_commits(self):
229
241
assert repo .status == ObjectStatus .HIDDEN
230
242
assert len (Commit .objects .filter (repository_id = repo .id )) == 0
231
243
244
+ # Verify the cleanup task was called
245
+ mock_cleanup_task .assert_called_once_with (
246
+ kwargs = {
247
+ "organization_id" : org .id ,
248
+ "repo_external_id" : "abc123" ,
249
+ "repo_provider" : "github" ,
250
+ }
251
+ )
252
+
232
253
def test_put_bad_integration_org (self ):
233
254
self .login_as (user = self .user )
234
255
@@ -260,3 +281,109 @@ def test_put_bad_integration_id(self):
260
281
assert response .status_code == 400
261
282
assert response .data == {"integrationId" : ["A valid integer is required." ]}
262
283
assert Repository .objects .get (id = repo .id ).name == "example"
284
+
285
+ @patch ("sentry.tasks.seer.cleanup_seer_repository_preferences.apply_async" )
286
+ def test_put_hide_repo_triggers_cleanup (self , mock_cleanup_task ):
287
+ """Test that hiding a repository triggers Seer cleanup task."""
288
+ self .login_as (user = self .user )
289
+
290
+ org = self .create_organization (owner = self .user , name = "baz" )
291
+ repo = Repository .objects .create (
292
+ name = "example-repo" ,
293
+ external_id = "github-123" ,
294
+ provider = "github" ,
295
+ organization_id = org .id ,
296
+ status = ObjectStatus .ACTIVE ,
297
+ )
298
+
299
+ url = reverse ("sentry-api-0-organization-repository-details" , args = [org .slug , repo .id ])
300
+ response = self .client .put (url , data = {"status" : "hidden" })
301
+
302
+ assert response .status_code == 200
303
+
304
+ repo = Repository .objects .get (id = repo .id )
305
+ assert repo .status == ObjectStatus .HIDDEN
306
+
307
+ # Verify the cleanup task was called with correct parameters
308
+ mock_cleanup_task .assert_called_once_with (
309
+ kwargs = {
310
+ "organization_id" : org .id ,
311
+ "repo_external_id" : "github-123" ,
312
+ "repo_provider" : "github" ,
313
+ }
314
+ )
315
+
316
+ @patch ("sentry.tasks.seer.cleanup_seer_repository_preferences.apply_async" )
317
+ def test_put_hide_repo_no_cleanup_when_null_fields (self , mock_cleanup_task ):
318
+ """Test that hiding a repository with null external_id/provider does not trigger Seer cleanup."""
319
+ self .login_as (user = self .user )
320
+
321
+ org = self .create_organization (owner = self .user , name = "baz" )
322
+ repo = Repository .objects .create (
323
+ name = "example-repo" ,
324
+ external_id = None , # No external_id
325
+ provider = None , # No provider
326
+ organization_id = org .id ,
327
+ status = ObjectStatus .ACTIVE ,
328
+ )
329
+
330
+ url = reverse ("sentry-api-0-organization-repository-details" , args = [org .slug , repo .id ])
331
+ response = self .client .put (url , data = {"status" : "hidden" })
332
+
333
+ assert response .status_code == 200
334
+
335
+ repo = Repository .objects .get (id = repo .id )
336
+ assert repo .status == ObjectStatus .HIDDEN
337
+
338
+ # Verify the cleanup task was NOT called
339
+ mock_cleanup_task .assert_not_called ()
340
+
341
+ @patch ("sentry.tasks.seer.cleanup_seer_repository_preferences.apply_async" )
342
+ def test_put_hide_repo_no_cleanup_when_external_id_null (self , mock_cleanup_task ):
343
+ """Test that hiding a repository with null external_id does not trigger Seer cleanup."""
344
+ self .login_as (user = self .user )
345
+
346
+ org = self .create_organization (owner = self .user , name = "baz" )
347
+ repo = Repository .objects .create (
348
+ name = "example-repo" ,
349
+ external_id = None , # No external_id
350
+ provider = "github" ,
351
+ organization_id = org .id ,
352
+ status = ObjectStatus .ACTIVE ,
353
+ )
354
+
355
+ url = reverse ("sentry-api-0-organization-repository-details" , args = [org .slug , repo .id ])
356
+ response = self .client .put (url , data = {"status" : "hidden" })
357
+
358
+ assert response .status_code == 200
359
+
360
+ repo = Repository .objects .get (id = repo .id )
361
+ assert repo .status == ObjectStatus .HIDDEN
362
+
363
+ # Verify the cleanup task was NOT called
364
+ mock_cleanup_task .assert_not_called ()
365
+
366
+ @patch ("sentry.tasks.seer.cleanup_seer_repository_preferences.apply_async" )
367
+ def test_put_hide_repo_no_cleanup_when_provider_null (self , mock_cleanup_task ):
368
+ """Test that hiding a repository with null provider does not trigger Seer cleanup."""
369
+ self .login_as (user = self .user )
370
+
371
+ org = self .create_organization (owner = self .user , name = "baz" )
372
+ repo = Repository .objects .create (
373
+ name = "example-repo" ,
374
+ external_id = "github-123" ,
375
+ provider = None , # No provider
376
+ organization_id = org .id ,
377
+ status = ObjectStatus .ACTIVE ,
378
+ )
379
+
380
+ url = reverse ("sentry-api-0-organization-repository-details" , args = [org .slug , repo .id ])
381
+ response = self .client .put (url , data = {"status" : "hidden" })
382
+
383
+ assert response .status_code == 200
384
+
385
+ repo = Repository .objects .get (id = repo .id )
386
+ assert repo .status == ObjectStatus .HIDDEN
387
+
388
+ # Verify the cleanup task was NOT called
389
+ mock_cleanup_task .assert_not_called ()
0 commit comments