Sourcegraph DocsSourcegraph Docs
Changelog↗
Theme
  1. Docs
  2. code-ownership

Code ownership

Code ownership is aimed at helping find the right person and team to contact, for any question, at any time.

Concepts

Owner: An owner is defined as a person in Sourcegraph.

A person can be:

  • a Sourcegraph user which we were able to resolve from the CODEOWNERS handle or email, in which case we link to their profile.
  • an unknown user for which we were unable to resolve a profile, in which case we will return the CODEOWNERS data we have.

Code ownership

Code ownership is set via the CODEOWNERS format.

Limitations

  • The feature has not been fully validated to work well on large repositories or large CODEOWNERS rulesets. This is a future area of improvement, but please contact us if you run into issues.

Browsing ownership

The ownership information is available for browsing once ownership data is available through a CODEOWNERS file.

When displaying a source file, there is an "Ownership" button at the bottom. Clicking it will open the "Ownership" panel. The button appears only in repositories that have a CODEOWNERS file.

File view with the ownership tab selected in the bottom panel

Ownership search

Searching for files with owners

Code ownership is a first-class citizen in search. Ownership can be either a query input or a search result:

PredicateKeepsExample
file:has.owner(...)Results owned by the given ownerrepo:^github\.com/grafana/grafana$ file:has.owner(grafana/data-sources-plugins) azure count:10
-file:has.owner(...)Results not owned by the given ownerrepo:^github\.com/grafana/grafana$ -file:has.owner(grafana/data-sources-plugins) azure count:10
file:has.owner()Files that have an ownerrepo:^github\.com/grafana/grafana$ file:has.owner() azure count:10
-file:has.owner()Files without an ownerrepo:^github\.com/grafana/grafana$ -file:has.owner() azure count:10

Write the owner as the complete username, team name, or email address from the CODEOWNERS file. The leading @ is optional.

When performing a search, the select:file.owners predicate returns the owners of the search results. For example, to find the owners of Go files in the pkg/tsdb/azuremonitor/ directory:

repo:^github\.com/grafana/grafana$ file:^pkg/tsdb/azuremonitor/ lang:go select:file.owners count:50

Find commits in a release for a given owner

With type:commit, file:has.owner(...) matches commits that changed files owned by the given owner. For example, to find the commits between versions v12.4.13 and v12.4.14 that changed files owned by the grafana/grafana-frontend-platform team:

repo:^github\.com/grafana/grafana$@v12.4.14:^v12.4.13 type:commit file:has.owner(grafana/grafana-frontend-platform)

Further reading

In order to learn more please check out our references:

  • CODEOWNERS format - Guide to using the CODEOWNERS file format to define ownership
Previous
Code Monitoring
Next
The CODEOWNERS format

On this page

  1. Code ownership

    1. Concepts
    1. Code ownership
    1. Limitations
    1. Browsing ownership
    1. Ownership search
    1. Further reading

Edit this page on GitHub
View as Markdown