Documentation
¶
Overview ¶
Package suspect finds the commits most likely to have introduced an error: the commits of a release's range that touched the files the error was raised from. It is the local half of `forge obs issue <id>`: the control plane knows which release an issue first appeared in and what range that release deployed, but only the developer's checkout has the history.
It reads the checkout with git and nothing else. Outside a checkout, or where the history is shallow, it returns an error the caller reports as a note and degrades to an empty list; it never invents a commit.
Index ¶
Constants ¶
const DefaultMax = 20
DefaultMax bounds the commits Find returns: with no release range known, the last 20 commits touching the culprit file.
Variables ¶
var ErrNoFiles = errors.New("none of the culprit files is tracked in this checkout")
ErrNoFiles says none of the culprit files is tracked in this checkout, so there is no history to search.
var ErrNotCheckout = errors.New("not inside a git checkout")
ErrNotCheckout says the directory is not inside a git work tree (or git is not installed).
Functions ¶
func CulpritFile ¶
CulpritFile is the file of an issue's culprit ("<file> in <function>"), or "" when the culprit is a function alone.
func Match ¶
Match maps reported file paths to tracked ones: a path that is tracked as given, or else the one tracked path it ends with at a directory boundary (the longest, so "internal/a/x.go" beats "a/x.go"). A bare file name matches only exactly. The result is sorted by first appearance and has no repeats.
func ParseRange ¶
ParseRange splits a "<from>..<to>" commit range. ok is false for anything else, including a side that is not a hex object name: the range arrives from a server and is passed to git, so only a plain commit id is accepted.
Types ¶
type Commit ¶
type Commit struct {
SHA string
Subject string
Author string
Time time.Time
// Files are the culprit files the commit touched, repo-relative.
Files []string
// PR is the pull request the commit was merged as, parsed from a "(#123)"
// squash subject; 0 when the subject names none.
PR int
}
Commit is one suspect commit.
type Finder ¶
type Finder struct {
Dir string
}
Finder lists suspect commits from the git checkout around Dir.
func (Finder) Find ¶
Find lists the commits in commitRange ("<from>..<to>", or "" for the history of HEAD) that touched any of files, newest first. files are the paths the error reported, which are usually build paths ("/app/internal/x/y.go", "github.com/acme/app/internal/x/y.go"): each is matched to the tracked file it ends with.