Documentation
¶
Overview ¶
Package gogit provides generic, dependency-light Git ergonomics by shelling out to the git CLI: repository discovery, commit-log parsing with trailers and change stats, and repository metadata (branch, origin URL).
It is the base layer for higher-level tools — the gitscan CLI (cmd/gitscan) and domain collectors such as OmniDevX — in the same way github.com/grokify/gogithub underlies GitHub integrations.
Index ¶
- Variables
- func AIToolByEmail(email string) string
- func Discover(roots []string, maxDepth int) ([]string, error)
- func IsRepo(path string) bool
- func NormalizeRemoteURL(remote string) string
- type AIAttribution
- type AIModel
- type AIProvider
- type Commit
- type ConventionalCommit
- type LogOptions
- type ProgressFunc
- type Repo
- func (r *Repo) Branch(ctx context.Context) (string, error)
- func (r *Repo) Log(ctx context.Context, opts LogOptions) ([]Commit, error)
- func (r *Repo) OriginURL(ctx context.Context) (string, error)
- func (r *Repo) Path() string
- func (r *Repo) Tags(ctx context.Context) ([]string, error)
- func (r *Repo) TagsWithDates(ctx context.Context) (map[string]time.Time, error)
- type RepoResult
- type Signature
- type Trailer
Constants ¶
This section is empty.
Variables ¶
var KnownAIProviders = []AIProvider{ { Name: "Claude Code", Provider: "anthropic", Emails: []string{"noreply@anthropic.com"}, }, { Name: "GitHub Copilot", Provider: "github", Emails: []string{"noreply@github.com", "copilot@github.com"}, }, { Name: "Gemini CLI", Provider: "google", Emails: []string{ "218195315+gemini-cli@users.noreply.github.com", "176961590+gemini-code-assist[bot]@users.noreply.github.com", "gemini-cli-agent@google.com", "gemini@google.com", }, }, { Name: "Cursor", Provider: "cursor", Emails: []string{"ai@cursor.sh", "cursor@cursor.sh"}, }, { Name: "Aider", Provider: "aider", Emails: []string{"aider@aider.chat"}, }, }
KnownAIProviders lists recognized AI coding assistants and their co-author signatures. This is the canonical registry; consumers should use AIProviderByEmail rather than maintaining separate lists.
Functions ¶
func AIToolByEmail ¶ added in v0.6.0
AIToolByEmail returns the tool name matching a co-author email, or "" when the email is not a known AI signature. This is a convenience wrapper around AIProviderByEmail for callers that only need the name.
func Discover ¶
Discover walks each root up to maxDepth directory levels (1 = direct children) and returns paths that are git repositories. Discovery does not descend into repositories, so nested checkouts and vendored trees are not double-counted.
func NormalizeRemoteURL ¶
NormalizeRemoteURL converts a git remote URL to a canonical host/path repository identifier:
https://github.com/x/y.git → github.com/x/y git@github.com:x/y.git → github.com/x/y ssh://git@github.com/x/y → github.com/x/y
An empty input returns "".
Types ¶
type AIAttribution ¶ added in v0.6.0
type AIAttribution struct {
IsAIAuthored bool `json:"isAiAuthored"`
Tools []string `json:"tools,omitempty"`
Models []AIModel `json:"models,omitempty"`
HumanAuthors []Signature `json:"humanAuthors,omitempty"`
}
AIAttribution holds the result of analyzing a commit for AI authorship.
func AnalyzeAuthorship ¶ added in v0.6.0
func AnalyzeAuthorship(c Commit) AIAttribution
AnalyzeAuthorship examines a commit's co-author trailers and returns a complete attribution breakdown: which AI tools contributed, what models were used, and which human co-authors were present.
type AIModel ¶ added in v0.6.0
type AIModel struct {
Provider string `json:"provider"`
Model string `json:"model"`
Name string `json:"name"`
}
AIModel holds a parsed AI model identity from a co-author trailer.
func ParseAIModel ¶ added in v0.6.0
ParseAIModel extracts the AI model from a co-author signature's name and email. Returns nil if the signature is not from a known AI provider or the model cannot be determined.
Examples:
"Claude Sonnet 5 <noreply@anthropic.com>" → {Provider: "anthropic", Model: "sonnet-5", Name: "Claude Sonnet 5"}
"Claude Opus 4.6 <noreply@anthropic.com>" → {Provider: "anthropic", Model: "opus-4.6", Name: "Claude Opus 4.6"}
"github-actions[bot] <noreply@github.com>" → {Provider: "github", Model: "", Name: "github-actions[bot]"}
type AIProvider ¶ added in v0.6.0
type AIProvider struct {
// Name is the display name, e.g. "Claude Code".
Name string
// Provider is the canonical provider slug, e.g. "anthropic".
Provider string
// Emails are known co-author addresses. Entries of the form
// "<id>+<slug>@users.noreply.github.com" also match any address with
// the same "+<slug>@users.noreply.github.com" suffix.
Emails []string
}
AIProvider identifies an AI coding assistant provider.
func AIProviderByEmail ¶ added in v0.6.0
func AIProviderByEmail(email string) *AIProvider
AIProviderByEmail returns the AI provider matching a co-author email, or nil when the email is not a known AI signature. Matching is case-insensitive and supports GitHub noreply suffix forms with variable user-ID prefixes.
type Commit ¶
type Commit struct {
Hash string `json:"hash"`
Author Signature `json:"author"`
AuthorDate time.Time `json:"authorDate"`
Committer Signature `json:"committer"`
CommitDate time.Time `json:"commitDate"`
Subject string `json:"subject"`
Trailers []Trailer `json:"trailers,omitempty"`
Insertions int `json:"insertions"`
Deletions int `json:"deletions"`
FilesChanged int `json:"filesChanged"`
}
Commit is one parsed log entry. Bodies are not extracted — subjects and trailers cover attribution and classification needs; consumers that need full messages can run git directly.
func (Commit) ParseConventional ¶ added in v0.6.0
func (c Commit) ParseConventional() *ConventionalCommit
ParseConventional parses this commit's subject as a conventional commit. Returns nil if the subject does not match.
func (Commit) TrailerValue ¶ added in v0.6.0
TrailerValue returns the first trailer value matching the given key (case-insensitive), or "" if not found.
func (Commit) TrailerValues ¶ added in v0.6.0
TrailerValues returns all trailer values matching the given key (case-insensitive).
type ConventionalCommit ¶ added in v0.6.0
type ConventionalCommit struct {
Type string `json:"type"`
Scope string `json:"scope,omitempty"`
Breaking bool `json:"breaking"`
Subject string `json:"subject"`
}
ConventionalCommit holds parsed conventional commit components.
func ParseConventionalCommit ¶ added in v0.6.0
func ParseConventionalCommit(subject string) *ConventionalCommit
ParseConventionalCommit parses the subject line of a conventional commit. Returns nil if the subject does not match the pattern.
type LogOptions ¶
type LogOptions struct {
// Since and Until bound the commit date (half-open in practice: git
// treats both bounds inclusively at second resolution).
Since time.Time
Until time.Time
// SinceCommit limits output to commits reachable from HEAD but not
// from the given commit SHA (i.e., "sha..HEAD"). Used for incremental
// ingestion with high-water marks.
SinceCommit string
// Author filters by author name or email (git regex semantics).
Author string
// NoMerges excludes merge commits.
NoMerges bool
// MaxCount caps the number of commits returned (0 = unlimited).
MaxCount int
// IncludeStats adds per-commit insertions/deletions/files-changed via
// --numstat. Costs proportionally more; leave false when not needed.
IncludeStats bool
// Reverse returns commits in chronological order (oldest first)
// instead of the default newest-first.
Reverse bool
}
LogOptions filters a commit-log query. Zero values leave a filter unset.
type ProgressFunc ¶ added in v0.6.0
ProgressFunc is called during parallel operations with progress updates.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo is a handle to a local git repository.
func (*Repo) Log ¶
Log returns commits matching opts, newest first (git log order) unless Reverse is set.
func (*Repo) OriginURL ¶
OriginURL returns the raw URL of the "origin" remote, or "" when no origin is configured.
type RepoResult ¶ added in v0.6.0
RepoResult holds the outcome of a parallel operation on one repository.
func RunAll ¶ added in v0.6.0
func RunAll[T any](ctx context.Context, paths []string, fn func(ctx context.Context, repo *Repo) (T, error), workers int) []RepoResult[T]
RunAll executes fn on each repository path in parallel, returning results in the same order as paths. Workers controls concurrency; 0 defaults to GOMAXPROCS. If ctx is cancelled, in-flight operations finish but queued ones are skipped.
func RunAllPaths ¶ added in v0.6.0
func RunAllPaths[T any](ctx context.Context, paths []string, fn func(ctx context.Context, path string) (T, error), workers int) []RepoResult[T]
RunAllPaths executes fn on each path in parallel without requiring a git repository. This is the lower-level variant for operations that manage their own Repo lifecycle or work on non-repo directories.
func RunAllWithProgress ¶ added in v0.6.0
func RunAllWithProgress[T any](ctx context.Context, paths []string, fn func(ctx context.Context, repo *Repo) (T, error), workers int, progress ProgressFunc) []RepoResult[T]
RunAllWithProgress is like RunAll but reports progress via a callback.