zerogit

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ChangeContractVersion = "zero.changes.report.v1"
View Source
const RuntimeGo = "go"

Variables

This section is empty.

Functions

func GenerateMessage

func GenerateMessage(summary ChangeSummary) string

func ValidateMessage

func ValidateMessage(message string) error

Types

type ChangeSnapshot

type ChangeSnapshot struct {
	Contract  string       `json:"contract"`
	Runtime   string       `json:"runtime"`
	Root      string       `json:"root"`
	Branch    string       `json:"branch,omitempty"`
	Base      string       `json:"base,omitempty"`
	Commit    string       `json:"commit,omitempty"`
	Clean     bool         `json:"clean"`
	Files     []FileChange `json:"files"`
	DiffStat  string       `json:"diffStat,omitempty"`
	Diff      string       `json:"diff,omitempty"`
	Truncated bool         `json:"truncated,omitempty"`
	Events    []Event      `json:"events"`
}

func SnapshotFromSummary

func SnapshotFromSummary(summary ChangeSummary) ChangeSnapshot

type ChangeSummary

type ChangeSummary struct {
	Root      string       `json:"root"`
	Branch    string       `json:"branch,omitempty"`
	Base      string       `json:"base,omitempty"`
	Commit    string       `json:"commit,omitempty"`
	Clean     bool         `json:"clean"`
	Files     []FileChange `json:"files"`
	DiffStat  string       `json:"diffStat,omitempty"`
	Diff      string       `json:"diff,omitempty"`
	Truncated bool         `json:"truncated,omitempty"`
}

func Inspect

func Inspect(ctx context.Context, options InspectOptions) (ChangeSummary, error)

type CommandResult

type CommandResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

type CommitOptions

type CommitOptions struct {
	Cwd          string
	Message      string
	DryRun       bool
	MaxDiffBytes int
	RunGit       Runner
	RunGitEnv    EnvRunner
}

type CommitResult

type CommitResult struct {
	Root       string        `json:"root"`
	Message    string        `json:"message"`
	DryRun     bool          `json:"dryRun"`
	Committed  bool          `json:"committed"`
	CommitHash string        `json:"commitHash,omitempty"`
	Before     ChangeSummary `json:"before"`
}

func Commit

func Commit(ctx context.Context, options CommitOptions) (CommitResult, error)

type DiffStat

type DiffStat struct {
	FilesChanged int
	Insertions   int
	Deletions    int
}

DiffStat is the parsed summary line of a `git diff --stat` invocation. The summary line ("N files changed, A insertions(+), B deletions(-)") carries no secret-bearing tokens, so it is safe to parse from an already-redacted stat.

func ParseDiffStat

func ParseDiffStat(stat string) DiffStat

ParseDiffStat extracts file/insertion/deletion counts from the trailing summary line of a `git diff --stat` output, e.g. "3 files changed, 12 insertions(+), 4 deletions(-)". Missing insertion or deletion clauses default to zero, and any malformed input yields a zero-value DiffStat without panicking.

func (DiffStat) NetLOC

func (stat DiffStat) NetLOC() int

NetLOC reports insertions minus deletions. The value may be zero or negative when a change removes at least as many lines as it adds.

type EnvRunner

type EnvRunner func(context.Context, string, []string, ...string) (CommandResult, error)

type Event

type Event struct {
	Type      EventType `json:"type"`
	Runtime   string    `json:"runtime,omitempty"`
	Contract  string    `json:"contract,omitempty"`
	Root      string    `json:"root,omitempty"`
	Branch    string    `json:"branch,omitempty"`
	Commit    string    `json:"commit,omitempty"`
	Clean     bool      `json:"clean,omitempty"`
	FileCount int       `json:"fileCount,omitempty"`
	Path      string    `json:"path,omitempty"`
	Status    string    `json:"status,omitempty"`
	Staged    bool      `json:"staged,omitempty"`
	Unstaged  bool      `json:"unstaged,omitempty"`
	Untracked bool      `json:"untracked,omitempty"`
}

func EventsFromSummary

func EventsFromSummary(summary ChangeSummary) []Event

type EventType

type EventType string
const (
	EventChangeSummary EventType = "change_summary"
	EventFileChange    EventType = "file_change"
)

type FileChange

type FileChange struct {
	Path      string `json:"path"`
	Status    string `json:"status"`
	Staged    bool   `json:"staged,omitempty"`
	Unstaged  bool   `json:"unstaged,omitempty"`
	Untracked bool   `json:"untracked,omitempty"`
}

type InspectOptions

type InspectOptions struct {
	Cwd          string
	BaseRef      string
	MaxDiffBytes int
	RunGit       Runner
	RunGitEnv    EnvRunner
}

type Runner

type Runner func(context.Context, string, ...string) (CommandResult, error)

Jump to

Keyboard shortcuts

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