Simplify privateRepoPublicSourcegraph check
Created by: lguychard
requestGraphQL()
may be called recursively from performRequest()
when retrying with a different URL.
When this is done from the background script (!isInPage
), the second call would not be checked for privateRepoPublicSourcegraph()
, which is an issue because that second call usually is to the public Sourcegraph.
The duplicate calls were in place because isPrivateRepository()
relies on being executed in-page: see isPublicCodeHost
, which would fail to properly detect a public code host if executed from the background page, and checks on the DOM in isPrivateRepository()
itself.
This introduces the following changes:
- inject
privateRepository
as part of the request context in order to stop callingisPrivateRepository()
fromprivateRepoPublicSourcegraph()
- remove duplicate
privateRepoPublicSourcegraph()
check: we no longer depend on this check being done in-page.
I added some tests for requestGraphQL()
, made possible by optionally injecting ajaxRequest()
to provide a stub for rxjs.ajax()
. This is not the most elegant approach, but it at least allows to test the business logic in requestGraphQL()
. See the new tests examplifying the fallback to public sourcegraph when the repo is not found on a public instance, for example.
The test errors if the repository is private and the user is logged out of his private instance
would have failed prior to this fix.