codeowners

package
v1.20220411.3 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package codeowners includes github codeowners management utilities

Index

Constants

View Source
const (
	// DefaultPath is the default realized codeowners path.
	DefaultPath = "./.github/CODEOWNERS"
	// DefaultGithubURL is the default github url.
	DefaultGithubURL = "https://git.blendlabs.com"
	// DefaultGithubTokenEnvVar standardizes an environment variable
	// to read the github api token from.
	DefaultGithubTokenEnvVar = "GHE_TOKEN"
)
View Source
const (
	// OwnersFile is the per path owners file users can create.
	OwnersFile = ".codeowners"

	// OwnersFileHeader is the header that is prefixed to the generated
	// owners file.
	OwnersFileHeader = `` /* 365-byte string literal not displayed */

	// OwnersGoCommentPrefix is the prefix for owners hints within go files.
	OwnersGoCommentPrefix = "github:codeowner"
	// OwnersFileSourceComment is the owners file comment marking the beginning
	// of a section for a given source.
	OwnersFileSourceComment = "# source: "
	// OwnersFileSourceEndComment is the owners file comment marking the end
	// of a section for a given source.
	OwnersFileSourceEndComment = "# source-end: "
)

Variables

This section is empty.

Functions

func MakeRepositoryAbsolute

func MakeRepositoryAbsolute(repositoryRoot, path string) (string, error)

MakeRepositoryAbsolute make a path absolute.

Types

type Codeowners

type Codeowners struct {
	// Config holds the configuration opitons.
	Config

	// Stdout is the writer for Verbose and Debug output.
	// If it is unset, `os.Stdout` will be used.
	Stdout io.Writer
	// Stderr is the writer for Error output.
	// If it is unset, `os.Stderr` will be used.
	Stderr io.Writer
}

Codeowners holds the engine that generates and validates codeowners files.

func New

func New(options ...Option) *Codeowners

New creates a new copyright engine with a given set of config options.

func (Codeowners) Debugf

func (c Codeowners) Debugf(format string, args ...interface{})

Debugf writes to stdout if the `Debug` flag is true.

func (Codeowners) Generate

func (c Codeowners) Generate(ctx context.Context, root string, output io.Writer) error

Generate generates a codeowner file.

func (Codeowners) GenerateFile

func (c Codeowners) GenerateFile(ctx context.Context, root string) error

GenerateFile generates the file as nominated by the config path.

func (Codeowners) GetStderr

func (c Codeowners) GetStderr() io.Writer

GetStderr returns standard error.

func (Codeowners) GetStdout

func (c Codeowners) GetStdout() io.Writer

GetStdout returns standard out.

func (Codeowners) Validate

func (c Codeowners) Validate(ctx context.Context, input io.Reader) error

Validate validates a given codeowners file.

func (Codeowners) ValidateFile

func (c Codeowners) ValidateFile(ctx context.Context) error

ValidateFile validates the file as configured in the config field.

func (Codeowners) Verbosef

func (c Codeowners) Verbosef(format string, args ...interface{})

Verbosef writes to stdout if the `Verbose` flag is true.

type Config

type Config struct {
	// Path is the owners file path (typically `.github/CODEOWNERS`)
	Path string `yaml:"path"`
	// GithubURL is the url of the github instance to communicate with.
	GithubURL string `yaml:"githubURL"`
	// GithubToken is the authorization token used to communicate with github.
	GithubToken string `yaml:"githubToken"`

	// Quiet controls whether output is suppressed.
	Quiet *bool `yaml:"quiet"`
	// Verbose controls whether verbose output is shown.
	Verbose *bool `yaml:"verbose"`
	// Debug controls whether debug output is shown.
	Debug *bool `yaml:"debug"`
}

Config are the configuration options for the utility.

func (Config) DebugOrDefault

func (c Config) DebugOrDefault() bool

DebugOrDefault returns a value or a default.

func (Config) GithubURLOrDefault

func (c Config) GithubURLOrDefault() string

GithubURLOrDefault returns a value or a default.

func (Config) PathOrDefault

func (c Config) PathOrDefault() string

PathOrDefault is the path for the codeowners file or a default.

func (Config) QuietOrDefault

func (c Config) QuietOrDefault() bool

QuietOrDefault returns a value or a default.

func (Config) VerboseOrDefault

func (c Config) VerboseOrDefault() bool

VerboseOrDefault returns a value or a default.

type File

type File []Source

File is a collection of codeowner sources.

func Read

func Read(r io.Reader) (output File, err error)

Read reads a codeowners file.

func (File) WriteTo

func (f File) WriteTo(wr io.Writer) (total int64, err error)

WriteTo writes the file to a given writer.

type GithubClient

type GithubClient struct {
	Addr  string
	Token string
}

GithubClient is a client to make requests to github via the api.

func (GithubClient) CreateURL

func (ghc GithubClient) CreateURL(path string) string

CreateURL creates a fully qualified url with a given path.

func (GithubClient) Do

func (ghc GithubClient) Do(req *http.Request) (*http.Response, error)

Do performs a request.

func (GithubClient) Get

func (ghc GithubClient) Get(ctx context.Context, path string, output interface{}) error

Get makes a get request.

func (GithubClient) Post

func (ghc GithubClient) Post(ctx context.Context, path string, input, output interface{}) error

Post makes a post request.

func (GithubClient) TeamExists

func (ghc GithubClient) TeamExists(ctx context.Context, teamName string) error

TeamExists fetches a team and returns if that team exists or not.

func (GithubClient) UserExists

func (ghc GithubClient) UserExists(ctx context.Context, username string) error

UserExists fetches a user and returns if that user exists or not.

type Option

type Option func(*Codeowners)

Option mutates the Codeowners instance.

type Path

type Path struct {
	PathGlob string
	Owners   []string
}

Path is a path in the codeowners file.

func ParsePath

func ParsePath(pathLine string) (output Path, err error)

ParsePath parses a path line into a path and owners.

type Source

type Source struct {
	Source string
	Paths  []Path
}

Source is a set of ownership entries.

func ParseGoComments

func ParseGoComments(repoRoot, sourcePath, linePrefix string) (*Source, error)

ParseGoComments parses a files comments.

func ParseSource

func ParseSource(repoRoot, sourcePath string) (*Source, error)

ParseSource parses a source from a given path.

func (Source) WriteTo

func (s Source) WriteTo(wr io.Writer) (total int64, err error)

WriteTo writes the owners to a given file.

Jump to

Keyboard shortcuts

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