pattern

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pattern implements GitHub CODEOWNERS pattern matching.

CODEOWNERS patterns follow "most of the same rules used in gitignore files" (GitHub docs), with three documented exceptions: no `!` negation, no `[ ]` character ranges, and no `\#` escaping of a leading hash. Square brackets are literal characters. Matching is case-sensitive (S-6).

The matching logic is ported from hmarr/codeowners (match.go), MIT License, Copyright (c) 2020 Harry Marr — the actively maintained reference implementation whose semantics are differentially tested against GitHub's observed behavior. The vendored corpus in testdata/patterns.json comes from the same project. Local divergences from the port, both deliberate:

  • Compile rejects patterns starting with `!` (GitHub: negation "doesn't work"; a mutation tool must never accept or emit one).
  • Compile rejects empty patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pattern

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

Pattern is a compiled CODEOWNERS pattern.

func Compile

func Compile(patternStr string) (*Pattern, error)

Compile parses a CODEOWNERS pattern.

func (*Pattern) Match

func (p *Pattern) Match(testPath string) bool

Match reports whether the repo-relative path (forward slashes, no leading slash) matches the pattern. Paths name tracked FILES; a pattern matching a directory matches the files beneath it per the rules encoded here.

func (*Pattern) String

func (p *Pattern) String() string

String returns the original pattern text.

Jump to

Keyboard shortcuts

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