Code ownership: Parse GitHub style code owners file to get ownership information
Created by: philipp-spiess
Closes #39158 (closed) Closes #39159 (closed)
This PR adds support for reading the GitHub style code owner specs from repositories to infer code ownership information automatically. To do that, we add a new dependency: https://github.com/hmarr/codeowners (MIT license so I don't see any legal issues).
Here's a bullet point recap of what changes we can find here:
- I've added a new
codeownership.Ruleset
type that currently is a proxy to thecodeowners.Ruleset
(from the new dependency). This allows us to expose a nice API but also will make it easier to later add other ways to get the code ownership mapping: E.g. we may want to fetch data rules from our postgres database instead. - We have a new method to create a ruleset based on querying the gitserver for a specific repo at a specific revision. This will download a static number of blobs that are allowed code owner locations (The plugin also supports GitLab style code owners so I've added the
.gitlab
path) - In the filter job, we create a new
map
so that we only have to create thecodeowners.Ruleset
for a specific repo once per search. So if one repo returns 100 results, we only have one ruleset. - When a code ownership mapping was found, we test the result paths against the mapping. If the owners contain the owner we need to include, we keep the result, otherwise we drop it.
- I added a new test for the filter job.
- I also migrated the filter job test to use
autogold
while at it. - I added a feature flag to gate out the work.
Test plan
I added a new test that mocks git server to return a specified code owners file. I've also tested it by running sg start
.
α sourcegraph (ps/code-ownership-query-codeowners-file-for-ownership-info)✗ go test github.com/sourcegraph/sourcegraph/internal/search/codeownership
ok github.com/sourcegraph/sourcegraph/internal/search/codeownership 1.448s