Skip to content

fix(github) Fix 404s not being handled in repository search #14030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/sentry/integrations/github/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def get(self, request, organization, integration_id):
except ApiError as err:
if err.code == 403:
return Response({'detail': 'Rate limit exceeded'}, status=429)
if err.code == 422:
return Response({
'detail': 'Repositories could not be searched because they do not exist, or you do not have access to them.'
}, status=404)
raise
return Response([{
'label': i['name'],
Expand Down
24 changes: 24 additions & 0 deletions tests/sentry/integrations/github/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,30 @@ def test_finds_repo_results(self):
{'value': 'test/exhaust', 'label': 'exhaust'}
]

@responses.activate
def test_repo_search_validation_error(self):
responses.add(
responses.GET,
self.base_url + '/search/repositories?q=org:test%20nope',
json={
'message': 'Validation Error',
'errors': [
{'message': 'Cannot search for that org'}
]
},
status=422
)
resp = self.client.get(
self.url,
data={
'field': 'repo',
'query': 'nope',
'repo': 'example',
}
)
assert resp.status_code == 404
assert 'detail' in resp.data

@responses.activate
def test_finds_no_external_issues_results(self):
responses.add(
Expand Down