codeowners

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 10 Imported by: 0

README

co: code owners command-line tool

build build

A CLI for GitHub's CODEOWNERS file.

This repository is forked from https://github.com/hmarr/codeowners. This is the most correct implementation of Github's rules engine I've found. Other solutions (e.g., Gitlab) may have differences which may not be featured here.

Installation

Local Usage

You can download a binary from the releases page and put the co binary somewhere in your path.

Usage
co help

Usage:
  co [command]

Available Commands:
  diff        Print a unified diff of file ownership
  fmt         Normalize CODEOWNERS format
  help        Help about any command
  lint        Validate codeowners file
  version     Print code version
  who         List code owners for file(s)
  why         Show rule used for a file

Flags:
  -f, --file string   CODEOWNERS file path
  -h, --help          help for co

Use "co [command] --help" for more information about a command.

Documentation

Overview

Package codeowners needs documentation.

Index

Constants

View Source
const (
	// EmailOwner is the owner type for email addresses.
	EmailOwner string = "email"
	// TeamOwner is the owner type for GitHub teams.
	TeamOwner string = "team"
	// UsernameOwner is the owner type for GitHub usernames.
	UsernameOwner string = "username"
)

Variables

This section is empty.

Functions

func ConsolidateTree

func ConsolidateTree(tree *FileTree)

func LsFiles

func LsFiles(ref string) ([]string, error)

Types

type FileTree

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

func NewFileTree

func NewFileTree(rules []Rule) *FileTree

func (*FileTree) String

func (f *FileTree) String() string

String will print all rules in lexicographical order.

type Owner

type Owner struct {
	// Value is the name of the owner: the email addres, team name, or username.
	Value string
	// Type will be one of 'email', 'team', or 'username'.
	Type string
}

Owner represents an owner found in a rule.

func (Owner) String

func (o Owner) String() string

String returns a string representation of the owner. For email owners, it simply returns the email address. For user and team owners it prepends an '@' to the owner.

type Rule

type Rule struct {
	SourceLine int

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

Rule is a CODEOWNERS rule that maps a gitignore-style path pattern to a set of owners.

func LoadFile

func LoadFile(path string) ([]Rule, error)

LoadFile loads and parses a CODEOWNERS file at the path specified.

func LoadFileAtRef

func LoadFileAtRef(ref, path string) ([]Rule, error)

LoadFileAtRef loads and parses a CODEOWNERS file from a historical commit. If ref is an empty string, file will be read from disk.

func LoadFileFromStandardLocation

func LoadFileFromStandardLocation() ([]Rule, error)

LoadFileFromStandardLocation loads and parses a CODEOWNERS file at one of the standard locations for CODEOWNERS files (./, .github/, docs/). If run from a git repository, all paths are relative to the repository root.

func LoadFileFromStandardLocationAtRef

func LoadFileFromStandardLocationAtRef(ref string) ([]Rule, error)

func ParseFile

func ParseFile(f io.Reader) ([]Rule, error)

ParseFile parses a CODEOWNERS file, returning a set of rules.

func (*Rule) Match

func (r *Rule) Match(path string) (bool, error)

Match tests whether the provided matches the rule's pattern.

func (*Rule) RawPattern

func (r *Rule) RawPattern() string

RawPattern returns the rule's gitignore-style path pattern.

func (*Rule) String

func (r *Rule) String() string

type Ruleset

type Ruleset []Rule

Ruleset is a collection of CODEOWNERS rules.

func (Ruleset) Match

func (r Ruleset) Match(path string) (*Rule, error)

Match finds the last rule in the ruleset that matches the path provided. When determining the ownership of a file using CODEOWNERS, order matters, and the last matching rule takes precedence.

Directories

Path Synopsis
cmd
co command

Jump to

Keyboard shortcuts

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