codeowners

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: MIT Imports: 10 Imported by: 10

README

Go Reference Build

go-codeowners

A package that finds and parses CODEOWNERS files.

Features:

  • operates on local repos
  • doesn't require a cloned repo (i.e. doesn't need a .git directory to be present at the repo's root)
  • can be called from within a repo (doesn't have to be at the root)
  • will find CODEOWNERS files in all documented locations: the repo's root, docs/, and .github/ (or .gitlab/ for GitLab repos)

Usage

go get -u github.com/hairyhenderson/go-codeowners

To find the owner of the README.md file:

import "github.com/hairyhenderson/go-codeowners"

func main() {
	c, _ := FromFile(cwd())
	owners := c.Owners("README.md")
	for i, o := range owners {
		fmt.Printf("Owner #%d is %s\n", i, o)
	}
}

See the docs for more information.

License

The MIT License

Copyright (c) 2018-2023 Dave Henderson

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codeowner

type Codeowner struct {
	Pattern string

	Owners []string
	// contains filtered or unexported fields
}

Codeowner - owners for a given pattern

func NewCodeowner

func NewCodeowner(pattern string, owners []string) (Codeowner, error)

NewCodeowner -

func (Codeowner) String

func (c Codeowner) String() string

type Codeowners

type Codeowners struct {
	Patterns []Codeowner
	// contains filtered or unexported fields
}

Codeowners - patterns/owners mappings for the given repo

func FromFile added in v0.3.0

func FromFile(path string) (*Codeowners, error)

FromFile creates a Codeowners from the path to a local file. Consider using FromFileWithFS instead.

Example
c, _ := FromFile(cwd())
fmt.Println(c.Patterns[0])
Output:

*	@hairyhenderson

func FromFileWithFS added in v0.3.0

func FromFileWithFS(fsys fs.FS, path string) (*Codeowners, error)

FromFileWithFS creates a Codeowners from the path to a file relative to the given filesystem.

Example
// open filesystem rooted at current working directory
fsys := os.DirFS(cwd())

c, _ := FromFileWithFS(fsys, ".")
fmt.Println(c.Patterns[0])
Output:

*	@hairyhenderson

func FromReader added in v0.3.0

func FromReader(r io.Reader, repoRoot string) (*Codeowners, error)

FromReader creates a Codeowners from a given Reader instance and root path.

Example
reader := strings.NewReader(sample2)
c, _ := FromReader(reader, "")
fmt.Println(c.Patterns[0])
Output:

*	@hairyhenderson

func NewCodeowners deprecated

func NewCodeowners(path string) (*Codeowners, error)

Deprecated: Use FromFile instead.

func (*Codeowners) Owners

func (c *Codeowners) Owners(path string) []string

Owners - return the list of code owners for the given path (within the repo root)

Example
c, _ := FromFile(cwd())
owners := c.Owners("README.md")
for i, o := range owners {
	fmt.Printf("Owner #%d is %s\n", i, o)
}
Output:

Owner #0 is @hairyhenderson

Jump to

Keyboard shortcuts

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