sourcegraph/schema/localgit.schema.json
Felix Kling f8f54f95ab
app: Dedicated local repo external service (#51805)
This commit introduces a dedicated external service (configuration) for
local repositories.

Until now we've piggybacked on OTHER, but that's been more of a
workaround by using a "magic value" in the `repos` field, and restricts
us to the configuration options provided by OTHER.

Having a dedicated external service lets us (more easily)...

- define configuration options useful for local repositories. This
commit allows associating a "group" with a path/pattern to make it
possible for users to resolve repo name conflicts.
- more easily configure the backend to use `file:` URLs to access the
repo. This means we don't need `servegit` anymore to expose git repos on
a local port, simplifying the overall architecture.

---

The implementation was inspired by OTHER and the `servegit` package. It
works as follows:

On startup the `localcodhost` service reads the
`~/.config/sourcegraph-sp/repos.json` config file to create a local
external service configuration (`LocalExternalService`). The structure
of the configuration file is something like

```
{ 
  "repos": [
    {"pattern": "glob/pattern/*", "group": "<group-name>"}
  ]
}
```

where `<group-name>` is optional and can be used to namespace
repositories from different directories.
I'm reusing the service ID that had been used for autogenerated repo
syncing via servegit.

This configuration is eventually passed to `LocalSource`, which resolves
the glob patterns when listing the available repositories.

As can be seen in `clone_url.go` we simply create `file:///` URLs for
LOCAL repositories, which avoids needing to run another HTTP service to
access the files.

---

Notes:

- This is a first step. I expect that we'll extend the configuration as
needed but we should strive to keep it as simple as possible.
- Eventually the service should re-read the configuration from disk.
- We have to decide whether configuring local repos from the setup
wizard will update the config file or simply create separate
configurations (either should be fine).
- I haven't removed the `servegit` service just yet so that the existing
app setup experience will continue to work.
- Any good ideas for testing this, especially the file system
interaction?


## Test plan

- Create the `repos` file in the apps config directory.
- When the sourcegraph app is started from the terminal, the terminal
output will list which repos have been found.
- Local repositories are visible in the repositories tab.
2023-06-07 15:14:36 +02:00

33 lines
929 B
JSON

{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "localgit.schema.json#",
"title": "LocalGitExternalService",
"description": "Configuration for integration local Git repositories.",
"allowComments": true,
"type": "object",
"additionalProperties": false,
"required": [],
"properties": {
"repos": {
"title": "List of paths/patterns to Git repos.",
"type": "array",
"items": {
"type": "object",
"title": "LocalGitRepoPattern",
"additionalProperties": false,
"description:": "Glob pattern.",
"properties": {
"pattern": {
"type": "string",
"examples": ["path/to/my/repo", "path/to/my/repo.git/"]
},
"group": {
"type": "string",
"description:": "The group all repsitories matching the pattern should be associated with."
}
}
}
}
}
}