Help us shape the future of Go! Take the 2026 Go Developer Survey

codeowners

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package codeowners reads a CODEOWNERS file the way GitHub or GitLab reads it and answers who owns a set of paths. It is pure: the caller reads the file.

Only owners a forge can be asked to review as are kept: a @username, or a team or group as @org/team, read on GitLab as GitLab's ReferenceExtractor reads them. Email owners, GitLab's @@role owners and any other shape are dropped, since nothing here can turn them into a reviewer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Locations

func Locations(dialect Dialect) []string

Locations are where dialect looks for the file, in the order it looks: the first one present is the file.

Types

type Dialect

type Dialect int

Dialect is which forge's CODEOWNERS rules a file is read by.

const (
	// GitHub has one list of rules, the last match wins, and a pattern holding a
	// slash is anchored to the repository root.
	GitHub Dialect = iota
	// GitLab adds sections, each with its own last match and default owners,
	// and !pattern exclusions; a pattern repeated in a section keeps only its
	// later line. The lines before the first header are the section named
	// codeowners. A pattern matches the whole path, as GitLab's fnmatch does:
	// an unanchored one at any depth, and only one ending in a slash covers a
	// directory's contents, so docs and /docs name a file and docs/* a
	// directory's direct children.
	GitLab
)

type File

type File struct {
	// contains filtered or unexported fields
}

File is a parsed CODEOWNERS file. The zero File owns nothing.

func Parse

func Parse(content string, dialect Dialect) File

Parse reads content as dialect reads it. A line the dialect cannot read is skipped, as the forge skips it, rather than failing the whole file.

func (File) OwnersOf

func (f File) OwnersOf(paths []string) Owners

OwnersOf is who owns any of paths: per path, every section's last matching rule, unless an exclusion in that section matches it.

type Owners

type Owners struct {
	Users []string
	Teams []string
}

Owners are the people and the teams that own some paths, each listed once in the order first seen. A team is org/team (GitLab: group/subgroup). On GitLab a top-level group is written @group, just as a user is, so a bare name is in Users and the forge resolves it to a user or, failing that, a group.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL