Skip to content

Commit fef248e

Browse files
markstoryStephen Cefali
authored andcommitted
fix(github) Fix 404s not being handled in repository search (#14030)
fix(github) Fix 422s not being handled in repository search Fixes SENTRY-95M
1 parent 31ff333 commit fef248e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/sentry/integrations/github/search.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def get(self, request, organization, integration_id):
5252
except ApiError as err:
5353
if err.code == 403:
5454
return Response({'detail': 'Rate limit exceeded'}, status=429)
55+
if err.code == 422:
56+
return Response({
57+
'detail': 'Repositories could not be searched because they do not exist, or you do not have access to them.'
58+
}, status=404)
5559
raise
5660
return Response([{
5761
'label': i['name'],

tests/sentry/integrations/github/test_search.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,30 @@ def test_finds_repo_results(self):
143143
{'value': 'test/exhaust', 'label': 'exhaust'}
144144
]
145145

146+
@responses.activate
147+
def test_repo_search_validation_error(self):
148+
responses.add(
149+
responses.GET,
150+
self.base_url + '/search/repositories?q=org:test%20nope',
151+
json={
152+
'message': 'Validation Error',
153+
'errors': [
154+
{'message': 'Cannot search for that org'}
155+
]
156+
},
157+
status=422
158+
)
159+
resp = self.client.get(
160+
self.url,
161+
data={
162+
'field': 'repo',
163+
'query': 'nope',
164+
'repo': 'example',
165+
}
166+
)
167+
assert resp.status_code == 404
168+
assert 'detail' in resp.data
169+
146170
@responses.activate
147171
def test_finds_no_external_issues_results(self):
148172
responses.add(

0 commit comments

Comments
 (0)