@@ -22,16 +22,16 @@ def test_get_prevent_github_repos_empty(self):
22
22
23
23
assert response .data == {"orgRepos" : []}
24
24
25
- @patch ("sentry.prevent.endpoints.organization_github_repos.requests.post " )
26
- def test_get_prevent_github_repos_with_integration (self , mock_requests_post ):
25
+ @patch ("sentry.prevent.endpoints.organization_github_repos.make_signed_seer_api_request " )
26
+ def test_get_prevent_github_repos_with_integration (self , mock_make_seer_request ):
27
27
"""Test that the endpoint returns GitHub org data when integrations exist"""
28
28
self .login_as (user = self .user )
29
29
30
30
# Mock the Seer API response (empty response since we're just testing Sentry integration)
31
31
mock_response = Mock ()
32
- mock_response .raise_for_status . return_value = None
32
+ mock_response .status = 200
33
33
mock_response .json .return_value = {"integrated_repos" : {}}
34
- mock_requests_post .return_value = mock_response
34
+ mock_make_seer_request .return_value = mock_response
35
35
36
36
# Create a GitHub integration
37
37
integration = self .create_integration (
@@ -74,8 +74,8 @@ def test_get_prevent_github_repos_with_integration(self, mock_requests_post):
74
74
assert repo_data ["hasGhAppSeerBySentry" ] is False
75
75
assert "id" not in repo_data # Verify id is not in response
76
76
77
- @patch ("sentry.prevent.endpoints.organization_github_repos.requests.post " )
78
- def test_get_prevent_github_repos_with_seer_integration (self , mock_requests_post ):
77
+ @patch ("sentry.prevent.endpoints.organization_github_repos.make_signed_seer_api_request " )
78
+ def test_get_prevent_github_repos_with_seer_integration (self , mock_make_seer_request ):
79
79
"""Test that repos from both Sentry and Seer are merged correctly"""
80
80
self .login_as (user = self .user )
81
81
@@ -104,7 +104,7 @@ def test_get_prevent_github_repos_with_seer_integration(self, mock_requests_post
104
104
105
105
# Mock the Seer API response
106
106
mock_response = Mock ()
107
- mock_response .raise_for_status . return_value = None
107
+ mock_response .status = 200
108
108
mock_response .json .return_value = {
109
109
"integrated_repos" : {
110
110
"test-org" : [
@@ -113,7 +113,7 @@ def test_get_prevent_github_repos_with_seer_integration(self, mock_requests_post
113
113
]
114
114
}
115
115
}
116
- mock_requests_post .return_value = mock_response
116
+ mock_make_seer_request .return_value = mock_response
117
117
118
118
response = self .get_success_response (self .organization .slug )
119
119
@@ -139,23 +139,23 @@ def test_get_prevent_github_repos_with_seer_integration(self, mock_requests_post
139
139
assert seer_only_repo_data ["hasGhAppSeerBySentry" ] is True
140
140
141
141
# Verify the Seer API was called correctly
142
- mock_requests_post .assert_called_once ()
143
- call_args = mock_requests_post .call_args
142
+ mock_make_seer_request .assert_called_once ()
143
+ call_args = mock_make_seer_request .call_args
144
144
145
- request_body = orjson .loads (call_args [1 ]["data " ])
145
+ request_body = orjson .loads (call_args [1 ]["body " ])
146
146
assert request_body ["organization_names" ] == ["test-org" ]
147
147
assert request_body ["provider" ] == "github"
148
148
149
- @patch ("sentry.prevent.endpoints.organization_github_repos.requests.post " )
150
- def test_get_prevent_github_repos_multiple_orgs (self , mock_requests_post ):
149
+ @patch ("sentry.prevent.endpoints.organization_github_repos.make_signed_seer_api_request " )
150
+ def test_get_prevent_github_repos_multiple_orgs (self , mock_make_seer_request ):
151
151
"""Test that multiple GitHub orgs are handled"""
152
152
self .login_as (user = self .user )
153
153
154
154
# Mock empty Seer response
155
155
mock_response = Mock ()
156
- mock_response .raise_for_status . return_value = None
156
+ mock_response .status = 200
157
157
mock_response .json .return_value = {"integrated_repos" : {}}
158
- mock_requests_post .return_value = mock_response
158
+ mock_make_seer_request .return_value = mock_response
159
159
160
160
# Create two GitHub integrations
161
161
integration1 = self .create_integration (
@@ -209,16 +209,16 @@ def test_get_prevent_github_repos_multiple_orgs(self, mock_requests_post):
209
209
assert len (orgs_by_name ["github-org-2" ]["repos" ]) == 1
210
210
assert orgs_by_name ["github-org-2" ]["repos" ][0 ]["name" ] == "repo2"
211
211
212
- @patch ("sentry.prevent.endpoints.organization_github_repos.requests.post " )
213
- def test_get_prevent_github_repos_multiple_repos_same_org (self , mock_requests_post ):
212
+ @patch ("sentry.prevent.endpoints.organization_github_repos.make_signed_seer_api_request " )
213
+ def test_get_prevent_github_repos_multiple_repos_same_org (self , mock_make_seer_request ):
214
214
"""Test that multiple repositories for the same GitHub organization are all returned"""
215
215
self .login_as (user = self .user )
216
216
217
217
# Mock empty Seer response
218
218
mock_response = Mock ()
219
- mock_response .raise_for_status . return_value = None
219
+ mock_response .status = 200
220
220
mock_response .json .return_value = {"integrated_repos" : {}}
221
- mock_requests_post .return_value = mock_response
221
+ mock_make_seer_request .return_value = mock_response
222
222
223
223
# Create one GitHub integration
224
224
integration = self .create_integration (
@@ -268,3 +268,44 @@ def test_get_prevent_github_repos_multiple_repos_same_org(self, mock_requests_po
268
268
# Verify all three repos are present
269
269
repo_names = {repo ["name" ] for repo in github_org ["repos" ]}
270
270
assert repo_names == {"repo1" , "repo2" , "repo3" }
271
+
272
+ @patch ("sentry.prevent.endpoints.organization_github_repos.make_signed_seer_api_request" )
273
+ def test_get_prevent_github_repos_seer_error (self , mock_make_seer_request ):
274
+ """Test that the endpoint gracefully handles Seer API errors"""
275
+ self .login_as (user = self .user )
276
+
277
+ # Mock Seer API returning an error
278
+ mock_response = Mock ()
279
+ mock_response .status = 500
280
+ mock_make_seer_request .return_value = mock_response
281
+
282
+ # Create a GitHub integration and repo
283
+ integration = self .create_integration (
284
+ organization = self .organization ,
285
+ provider = "github" ,
286
+ name = "test-github-org" ,
287
+ external_id = "123456" ,
288
+ metadata = {"account_id" : "987654" },
289
+ )
290
+
291
+ project = self .create_project (organization = self .organization )
292
+ self .create_repo (
293
+ project = project ,
294
+ name = "test-github-org/test-repo" ,
295
+ provider = "integrations:github" ,
296
+ integration_id = integration .id ,
297
+ external_id = "111222" ,
298
+ )
299
+
300
+ # Should still return Sentry repos even if Seer fails
301
+ response = self .get_success_response (self .organization .slug )
302
+
303
+ assert len (response .data ["orgRepos" ]) == 1
304
+ github_org = response .data ["orgRepos" ][0 ]
305
+ assert github_org ["name" ] == "test-github-org"
306
+ assert len (github_org ["repos" ]) == 1
307
+
308
+ repo_data = github_org ["repos" ][0 ]
309
+ assert repo_data ["name" ] == "test-repo"
310
+ assert repo_data ["hasGhAppSentryIo" ] is True
311
+ assert repo_data ["hasGhAppSeerBySentry" ] is False
0 commit comments