suspect

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

View Source
const DefaultMax = 20

DefaultMax bounds the commits Find returns: with no release range known, the last 20 commits touching the culprit file.

Variables

View Source
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.

View Source
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

func CulpritFile(culprit string) string

CulpritFile is the file of an issue's culprit ("<file> in <function>"), or "" when the culprit is a function alone.

func Match

func Match(tracked, reported []string) []string

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

func ParseRange(s string) (from, to string, ok bool)

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

func (f Finder) Find(ctx context.Context, commitRange string, files []string) ([]Commit, error)

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.

Jump to

Keyboard shortcuts

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