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, all deliberate:
- Compile rejects patterns starting with `!` (GitHub: negation "doesn't work"; a mutation tool must never accept or emit one).
- Compile rejects patterns starting with `\#` (S-2/S-6: GitHub honors no `\#` escape — a line starting with `#` is always a comment, so the rule would be dead there; same standard as `!`). Only the LEADING position is special-cased: a mid-pattern `#` needs no escape at all, so `\#` after the first character keeps the oracle's literal-`#` meaning.
- Compile rejects empty patterns.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶ added in v0.0.4
Contains reports whether every path matching `inner` also matches `outer` — containment of the pattern LANGUAGES, not of their match sets over some snapshot of a file tree. Callers use it to decide whether editing a rule in place can affect anything outside an operation's scope, and a CODEOWNERS rule governs files that do not exist yet, so a tree-based answer is an accident of what happens to be committed today.
Contains is SOUND but deliberately incomplete: it never reports true for a pair where containment fails, and answers false whenever it cannot prove the containment. Callers must treat false as "unknown", not as "disjoint".
Paths are repo-relative FILE paths (see Match), so a pattern ending in `/**` is taken to require at least one further segment.
Types ¶
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
Pattern is a compiled CODEOWNERS pattern.