go-codeowners – github.com/hairyhenderson/go-codeowners Index | Examples | Files

package codeowners

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

Index

Examples

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

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

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

Example

Code:

{
	c, _ := FromFile(cwd())
	fmt.Println(c.Patterns[0])
	// Output:
	// *	@hairyhenderson
}

Output:

*	@hairyhenderson

func FromFileWithFS

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

Code:

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

	c, _ := FromFileWithFS(fsys, ".")
	fmt.Println(c.Patterns[0])
	// Output:
	// *	@hairyhenderson
}

Output:

*	@hairyhenderson

func FromReader

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

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

Example

Code:

{
	reader := strings.NewReader(sample2)
	c, _ := FromReader(reader, "")
	fmt.Println(c.Patterns[0])
	// Output:
	// *	@hairyhenderson
}

Output:

*	@hairyhenderson

func NewCodeowners

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

Code:

{
	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
}

Output:

Owner #0 is @hairyhenderson

Source Files

codeowners.go

Version
v0.5.0
Published
Jun 27, 2024
Platform
darwin/amd64
Imports
10 packages
Last checked
now

Tools for package owners.