codeowners

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsSlug added in v1.6.1

func ContainsSlug(slugs []Slug, target Slug) bool

ContainsSlug checks if a Slug is in a slice (case-insensitive).

func NormalizedStrings added in v1.6.1

func NormalizedStrings(slugs []Slug) []string

NormalizedStrings extracts normalized strings from Slug slice. Use for comparisons with legacy code, generic functions (Intersection, Filtered).

func OriginalStrings added in v1.6.1

func OriginalStrings(slugs []Slug) []string

OriginalStrings extracts original strings from Slug slice. Use at boundaries: API calls, comments, display.

Types

type CodeOwners

type CodeOwners interface {
	// SetAuthor sets the author of the PR
	SetAuthor(author string)

	// FileRequired returns a map of file names to their required reviewers
	FileRequired() map[string]ReviewerGroups

	// FileReviewers returns a map of file names to their required reviewers
	FileOptional() map[string]ReviewerGroups

	// AllRequired returns a list of the required reviewers for all files in the PR
	AllRequired() ReviewerGroups

	// AllOptional return a list of the optional reviewers for all files in the PR
	AllOptional() ReviewerGroups

	// UnownedFiles returns a list of files in the diff which are not
	UnownedFiles() []string

	// ApplyApprovals marks the given approvers as satisfied
	ApplyApprovals(approvers []Slug)
}

CodeOwners represents a collection of owned files, with reverse lookups for owners and reviewers

func New

func New(root string, files []DiffFile, fileReader FileReader, warningWriter io.Writer) (CodeOwners, error)

New creates a new CodeOwners object from a root path and a list of diff files If fileReader is nil, it will use the filesystem

type DiffFile

type DiffFile struct {
	FileName string
	Hunks    []HunkRange
}

type FileReader added in v1.6.0

type FileReader interface {
	ReadFile(path string) ([]byte, error)
	PathExists(path string) bool
}

FileReader defines an interface for reading files from different sources

type FileTestCases

type FileTestCases []*reviewerTest

func (FileTestCases) Len

func (ftc FileTestCases) Len() int

func (FileTestCases) Less

func (ftc FileTestCases) Less(i, j int) bool

func (FileTestCases) Swap

func (ftc FileTestCases) Swap(i, j int)

type FilesystemReader added in v1.6.0

type FilesystemReader struct{}

FilesystemReader implements FileReader for the local filesystem

func (*FilesystemReader) PathExists added in v1.6.0

func (f *FilesystemReader) PathExists(path string) bool

func (*FilesystemReader) ReadFile added in v1.6.0

func (f *FilesystemReader) ReadFile(path string) ([]byte, error)

type HunkRange

type HunkRange struct {
	Start int
	End   int
}

type ReviewerGroup

type ReviewerGroup struct {
	Names    []Slug
	Approved bool
}

Represents a group of ReviewerGroup, with a list of names and an approved status

func (*ReviewerGroup) ToCommentString

func (rg *ReviewerGroup) ToCommentString() string

type ReviewerGroupManager

type ReviewerGroupManager interface {
	ToReviewerGroup(names ...string) *ReviewerGroup
}

func NewReviewerGroupMemo

func NewReviewerGroupMemo() ReviewerGroupManager

type ReviewerGroupMemo

type ReviewerGroupMemo map[string]*ReviewerGroup

func (ReviewerGroupMemo) ToReviewerGroup

func (rgm ReviewerGroupMemo) ToReviewerGroup(names ...string) *ReviewerGroup

Create a new Reviewers, memoizing the Reviewers so it is only created once

type ReviewerGroups

type ReviewerGroups []*ReviewerGroup

func (ReviewerGroups) ContainsAny added in v1.6.1

func (rgs ReviewerGroups) ContainsAny(names []Slug) bool

ContainsAny returns true if any of the provided names (case-insensitive) are present in any of the reviewer groups

func (ReviewerGroups) FilterOut

func (rgs ReviewerGroups) FilterOut(names ...Slug) ReviewerGroups

func (ReviewerGroups) Flatten

func (rgs ReviewerGroups) Flatten() []Slug

func (ReviewerGroups) ToCommentString

func (rgs ReviewerGroups) ToCommentString(includeCheckbox bool) string

type Rules

type Rules struct {
	Fallback                *ReviewerGroup
	OwnerTests              FileTestCases
	AdditionalReviewerTests FileTestCases
	OptionalReviewerTests   FileTestCases
}

func Read

func Read(path string, reviewerGroupManager ReviewerGroupManager, fileReader FileReader, warningWriter io.Writer) Rules

Read the .codeowners file and return the fallback owner, ownership tests, and additional ownership tests If fileReader is nil, it will use the filesystem

type Slug added in v1.6.1

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

Slug represents a GitHub username or team name (handle) with case-insensitive semantics. It stores both the original representation (for display/API calls) and normalized form (for comparisons). The zero value is not valid - use NewSlug to construct.

GitHub uses "slug" as the canonical term for handles that work for both users and teams.

func FilterOutNames added in v1.6.1

func FilterOutNames(names []Slug, exclude []Slug) []Slug

FilterOutNames returns a new slice with names from 'names' that are NOT present in 'exclude' (case-insensitive comparison)

func NewSlug added in v1.6.1

func NewSlug(name string) Slug

NewSlug creates a Slug from a string, normalizing it for comparison. The original casing is preserved for display purposes.

func NewSlugs added in v1.6.1

func NewSlugs(names []string) []Slug

NewSlugs converts a slice of strings to Slugs.

func (Slug) Equals added in v1.6.1

func (s Slug) Equals(other Slug) bool

Equals performs case-insensitive comparison with another Slug.

func (Slug) EqualsString added in v1.6.1

func (s Slug) EqualsString(str string) bool

EqualsString performs case-insensitive comparison with a string. Provided for convenience during migration and at boundaries.

func (Slug) MarshalJSON added in v1.6.1

func (s Slug) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for GitHub API compatibility. Serializes as the original string to preserve case.

func (Slug) Normalized added in v1.6.1

func (s Slug) Normalized() string

Normalized returns the lowercase normalized form. Use this for map keys and comparisons with legacy code.

func (Slug) Original added in v1.6.1

func (s Slug) Original() string

Original returns the original string representation (preserves case). Use this for display, comments, API calls to GitHub.

func (Slug) String added in v1.6.1

func (s Slug) String() string

String returns the original representation for fmt.Printf, logging, etc.

Jump to

Keyboard shortcuts

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