Do not show the "View file" button if repo is private but instance is public
Created by: lguychard
Fixes #3065 (closed)
I originally started this branch to work on #3072 (closed), but realised that the solution to that was more complex than anticipated, because since extensions must work on private code, we can't just nuke hover/codeintel functionality if the repo doesn't exist on the Sourcegraph instance.
In any case, the changes I started allowed me to fix #3065 (closed), and also to deduplicate a lot of code in the browser extension:
- It was previously up to
CodeViewSpec.resolveFileInfo()
to callensureRevisionsAreCloned()
, making sure the code view's revision(s) existed on the Sourcegraph instance. This was error-prone - in several instances,ensureRevisionsAreCloned()
was not called. - Some instances of
CodeViewSpec.resolveFileInfo()
would also fetch the file contents, but the downstream code would assume that the file contents needed to be fetched anyway. - I made sure that
ensureRevisionsAreCloned()
andfetchFileContents()
were only called once per code view, in thecodeViews
observable.
With ensureRevisionsAreCloned()
now being reliably called for every code view, I added FileInfo.privateRepoPublicSourcegraph
, and used it to hide the "View File" button when the repo doesn't exist on the public sourcegraph instance. With a private Sourcegraph instance, ensureRevisionsAreCloned()
will throw if the revision doesn't exist, and the code view event won't be emitted.