Skip to content

repo-updater: Use URI field as fallback for repos.GetByName

Administrator requested to merge core/name-alias into master

Created by: keegancsmith

External tools (such as the browser extension, language extensions, editor extensions) compute the Sourcegraph repository name using the repository's hostname and path. For example github.com/gorilla/mux. However, if an administrator configures an external service with the non-default repositoryPathPattern the name on Sourcegraph the name of a repository on Sourcegraph will not match with the externally computed name.

This commit will store the default name in the unused URI field on the repo table. When the frontend is looking up a repository by name, it will now fallback to the default name (the URI column) to find a repository. This magically makes most external tools just work. Additionally the frontend has redirect logic where if a repository path does not equal its name, it is redirected.

There are cases where extension relies on the name to be the default name. For example the go language server uses the name as the default root go package path. To fix this use-case we will need to extend the extension to pass on the URI field of the repo. However, things like fetching the file contents will still work, so if the root path is found in other ways (such as parsing a config file or import package doc) it will still work.

The initial implementation of this feature returned errors indicating the correct name to use. However, that would require every client to handle that case. Instead this implementation works as expected, and in a few cases requires some clients to support this model. Note: the clients that need updating are no more broken than before, and generally work better now.

The URI field was picked since this is what its original value was. Additionally it is an unused field. I considered giving it a new name, but prefered consistency between the name in the database and the name in the code.

Test plan: Tested locally. Once on dogfood we will do plenty of follow up testing to ensure extensions and other integrations work.

Part of https://github.com/sourcegraph/sourcegraph/issues/462

Merge request reports

Loading