history

package
v0.0.0-...-a003286 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package history provides git history analysis and contributor statistics.

This package analyzes git commit history to extract insights such as contributor statistics, commit frequency, and file change patterns.

Features

  • Contributor statistics (commits, lines added/removed)
  • Commit frequency analysis
  • File evolution tracking
  • Blame analysis

Usage

analyzer := history.NewAnalyzer(repoPath)
stats, err := analyzer.ContributorStats()

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyHistory indicates repository has no commit history.
	ErrEmptyHistory = errors.New("repository has no commit history")

	// ErrInvalidDateRange indicates invalid date range (since > until).
	ErrInvalidDateRange = errors.New("invalid date range (since > until)")

	// ErrFileNotFound indicates file not found in repository history.
	ErrFileNotFound = errors.New("file not found in repository history")

	// ErrInvalidFormat indicates invalid output format.
	ErrInvalidFormat = errors.New("invalid output format")

	// ErrNoContributors indicates no contributors found.
	ErrNoContributors = errors.New("no contributors found")

	// ErrInvalidAuthor indicates invalid author name or email.
	ErrInvalidAuthor = errors.New("invalid author name or email")

	// ErrInvalidBranch indicates invalid branch name.
	ErrInvalidBranch = errors.New("invalid branch name")
)

Functions

This section is empty.

Types

type AnalyzeOptions

type AnalyzeOptions struct {
	Since      time.Time
	Until      time.Time
	Branch     string
	Author     string
	MaxCommits int
}

AnalyzeOptions configures history analysis.

type BlameInfo

type BlameInfo struct {
	FilePath string
	Lines    []*BlameLine
}

BlameInfo represents file blame information.

type BlameLine

type BlameLine struct {
	LineNumber  int
	Content     string
	Hash        string
	Author      string
	AuthorEmail string
	Date        time.Time
}

BlameLine represents blame information for a single line.

type CommitStats

type CommitStats struct {
	TotalCommits   int
	FirstCommit    time.Time
	LastCommit     time.Time
	DateRange      time.Duration
	AvgPerDay      float64
	AvgPerWeek     float64
	AvgPerMonth    float64
	PeakDay        time.Time
	PeakCount      int
	UniqueAuthors  int
	TotalFiles     int
	TotalAdditions int
	TotalDeletions int
}

CommitStats represents commit statistics for a repository.

type CommitTrends

type CommitTrends struct {
	Daily   map[string]int // date (YYYY-MM-DD) -> count
	Weekly  map[string]int // week (YYYY-WW) -> count
	Monthly map[string]int // month (YYYY-MM) -> count
	Hourly  map[int]int    // hour (0-23) -> count
}

CommitTrends represents commit trend data over time.

type Contributor

type Contributor struct {
	Name           string
	Email          string
	TotalCommits   int
	FirstCommit    time.Time
	LastCommit     time.Time
	LinesAdded     int
	LinesDeleted   int
	FilesTouched   int
	ActiveDays     int
	CommitsPerWeek float64
	Rank           int
}

Contributor represents a repository contributor.

type ContributorAnalyzer

type ContributorAnalyzer interface {
	Analyze(ctx context.Context, repo *repository.Repository, opts ContributorOptions) ([]*Contributor, error)
	GetTopContributors(ctx context.Context, repo *repository.Repository, limit int) ([]*Contributor, error)
}

ContributorAnalyzer analyzes contributor activity.

func NewContributorAnalyzer

func NewContributorAnalyzer(executor GitExecutor) ContributorAnalyzer

NewContributorAnalyzer creates a new contributor analyzer.

type ContributorOptions

type ContributorOptions struct {
	Since      time.Time
	Until      time.Time
	MinCommits int
	SortBy     ContributorSortBy
}

ContributorOptions configures contributor analysis.

type ContributorSortBy

type ContributorSortBy string

ContributorSortBy defines sorting criteria for contributors.

const (
	SortByCommits      ContributorSortBy = "commits"
	SortByLinesAdded   ContributorSortBy = "additions"
	SortByLinesDeleted ContributorSortBy = "deletions"
	SortByRecent       ContributorSortBy = "recent"
)

type FileCommit

type FileCommit struct {
	Hash         string
	Author       string
	AuthorEmail  string
	Date         time.Time
	Message      string
	LinesAdded   int
	LinesDeleted int
	IsBinary     bool
	WasRenamed   bool
	OldPath      string
}

FileCommit represents a commit affecting a specific file.

type FileHistoryTracker

type FileHistoryTracker interface {
	GetHistory(ctx context.Context, repo *repository.Repository, path string, opts HistoryOptions) ([]*FileCommit, error)
	GetBlame(ctx context.Context, repo *repository.Repository, path string) (*BlameInfo, error)
}

FileHistoryTracker tracks file evolution and changes.

func NewFileHistoryTracker

func NewFileHistoryTracker(executor GitExecutor) FileHistoryTracker

NewFileHistoryTracker creates a new file history tracker.

type Formatter

type Formatter interface {
	FormatCommitStats(stats *CommitStats) ([]byte, error)
	FormatContributors(contributors []*Contributor) ([]byte, error)
	FormatFileHistory(history []*FileCommit) ([]byte, error)
}

Formatter formats analysis results in various output formats.

func NewFormatter

func NewFormatter(format OutputFormat) Formatter

NewFormatter creates a new formatter for the specified output format.

type GitExecutor

type GitExecutor interface {
	Run(ctx context.Context, repoPath string, args ...string) (*gitcmd.Result, error)
}

GitExecutor defines the interface for executing git commands.

type HistoryAnalyzer

type HistoryAnalyzer interface {
	Analyze(ctx context.Context, repo *repository.Repository, opts AnalyzeOptions) (*CommitStats, error)
	GetTrends(ctx context.Context, repo *repository.Repository, opts TrendOptions) (*CommitTrends, error)
}

HistoryAnalyzer analyzes commit history.

func NewHistoryAnalyzer

func NewHistoryAnalyzer(executor *gitcmd.Executor) HistoryAnalyzer

NewHistoryAnalyzer creates a new history analyzer.

type HistoryOptions

type HistoryOptions struct {
	MaxCount int
	Since    time.Time
	Until    time.Time
	Follow   bool // Follow renames
	Author   string
}

HistoryOptions configures file history retrieval.

type OutputFormat

type OutputFormat string

OutputFormat defines the output format for analysis results.

const (
	FormatTable    OutputFormat = "table"
	FormatJSON     OutputFormat = "json"
	FormatCSV      OutputFormat = "csv"
	FormatMarkdown OutputFormat = "markdown"
	FormatLLM      OutputFormat = "llm"
)

type TrendOptions

type TrendOptions struct {
	Since  time.Time
	Until  time.Time
	Branch string
}

TrendOptions configures trend analysis.

Jump to

Keyboard shortcuts

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