gitlog

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gitlog provides parsing of git log output into structured data optimized for LLM-assisted changelog generation.

Index

Constants

View Source
const GitLogFormat = commitDelimiter + "%n%H%n%h%n%an%n%ae%n%aI%n%s%n%b---END_BODY---"

GitLogFormat is the format string to use with git log for parsing. Use: git log --format="---COMMIT_DELIMITER---%n%H%n%h%n%an%n%ae%n%aI%n%s%n%b---END_BODY---" --numstat

Variables

View Source
var KnownConventionalTypes = []string{
	"feat",
	"fix",
	"docs",
	"style",
	"refactor",
	"perf",
	"test",
	"build",
	"ci",
	"chore",
	"revert",
	"security",
	"deps",
}

KnownConventionalTypes are the standard conventional commit types.

Functions

func ExtractIssueNumber

func ExtractIssueNumber(message string) int

ExtractIssueNumber extracts the first issue number from a commit message. It looks for patterns like #123, Closes #123, Fixes #456.

func ExtractPRNumber

func ExtractPRNumber(subject string) int

ExtractPRNumber extracts a PR number from the subject line. It looks for patterns like "(#123)" at the end of the subject.

func GetCategoryMapping

func GetCategoryMapping() map[string]CategorySuggestion

GetCategoryMapping returns the full category mapping for reference.

func GetFirstCommit added in v0.9.0

func GetFirstCommit() (string, error)

GetFirstCommit returns the hash of the first commit in the repository.

func HasBreakingChangeMarker

func HasBreakingChangeMarker(body string) bool

HasBreakingChangeMarker checks if the message body contains BREAKING CHANGE:.

func IsConventionalCommit

func IsConventionalCommit(message string) bool

IsConventionalCommit returns true if the message follows conventional commit format.

func IsKnownType

func IsKnownType(t string) bool

IsKnownType returns true if the type is a recognized conventional commit type.

Types

type CategorySuggestion

type CategorySuggestion struct {
	Category   string  `json:"category"`
	Tier       string  `json:"tier"`
	Confidence float64 `json:"confidence"`
	Reasoning  string  `json:"reasoning"`
}

CategorySuggestion represents a suggested changelog category with confidence.

func SuggestCategory

func SuggestCategory(commitType string) *CategorySuggestion

SuggestCategory suggests a changelog category for a commit based on its type.

func SuggestCategoryFromMessage

func SuggestCategoryFromMessage(message string) *CategorySuggestion

SuggestCategoryFromMessage suggests a category by parsing the commit message.

type Commit

type Commit struct {
	Hash              string   `json:"hash"`
	ShortHash         string   `json:"shortHash"`
	Author            string   `json:"author"`
	AuthorEmail       string   `json:"authorEmail,omitempty"`
	Date              string   `json:"date"`
	Message           string   `json:"message"`
	Body              string   `json:"body,omitempty"`
	Type              string   `json:"type,omitempty"`
	Scope             string   `json:"scope,omitempty"`
	Subject           string   `json:"subject"`
	Breaking          bool     `json:"breaking,omitempty"`
	Issue             int      `json:"issue,omitempty"`
	PR                int      `json:"pr,omitempty"`
	FilesChanged      int      `json:"filesChanged,omitempty"`
	Insertions        int      `json:"insertions,omitempty"`
	Deletions         int      `json:"deletions,omitempty"`
	Files             []string `json:"files,omitempty"`
	SuggestedCategory string   `json:"suggestedCategory,omitempty"`
	IsExternal        bool     `json:"isExternal,omitempty"`
}

Commit represents a parsed git commit with structured metadata.

type Contributor added in v0.6.0

type Contributor struct {
	Name        string `json:"name"`
	CommitCount int    `json:"commitCount"`
	IsExternal  bool   `json:"isExternal,omitempty"`
}

Contributor represents an author with commit count.

type ConventionalCommit

type ConventionalCommit struct {
	Type     string `json:"type"`
	Scope    string `json:"scope,omitempty"`
	Subject  string `json:"subject"`
	Breaking bool   `json:"breaking"`
}

ConventionalCommit represents parsed components of a conventional commit message.

func ParseConventionalCommit

func ParseConventionalCommit(message string) *ConventionalCommit

ParseConventionalCommit parses a commit message into conventional commit components. Returns nil if the message doesn't follow conventional commit format.

type ParseResult

type ParseResult struct {
	Repository   string        `json:"repository,omitempty"`
	Range        Range         `json:"range"`
	GeneratedAt  time.Time     `json:"generatedAt"`
	Commits      []Commit      `json:"commits"`
	Summary      Summary       `json:"summary"`
	Contributors []Contributor `json:"contributors,omitempty"`
}

ParseResult is the complete output of parsing git commits.

func NewParseResult

func NewParseResult() *ParseResult

NewParseResult creates a new ParseResult with initialized maps.

func ParseSimple

func ParseSimple(input string) (*ParseResult, error)

ParseSimple parses a simpler git log format without numstat. Use with: git log --format="%H|%h|%an|%ae|%aI|%s"

func (*ParseResult) AddCommit

func (pr *ParseResult) AddCommit(c Commit)

AddCommit adds a commit and updates summary statistics.

func (*ParseResult) ComputeContributors added in v0.6.0

func (pr *ParseResult) ComputeContributors()

ComputeContributors builds the Contributors list from commits. Call this after all commits have been added and IsExternal has been set.

type Parser

type Parser struct {
	IncludeFiles bool
}

Parser parses git log output into structured commits.

func NewParser

func NewParser() *Parser

NewParser creates a new git log parser.

func (*Parser) Parse

func (p *Parser) Parse(input string) (*ParseResult, error)

Parse parses git log output and returns a ParseResult.

type Range

type Range struct {
	Since       string `json:"since,omitempty"`
	Until       string `json:"until,omitempty"`
	CommitCount int    `json:"commitCount"`
}

Range represents the commit range that was parsed.

type Summary

type Summary struct {
	ByType              map[string]int `json:"byType,omitempty"`
	BySuggestedCategory map[string]int `json:"bySuggestedCategory,omitempty"`
	TotalFilesChanged   int            `json:"totalFilesChanged,omitempty"`
	TotalInsertions     int            `json:"totalInsertions,omitempty"`
	TotalDeletions      int            `json:"totalDeletions,omitempty"`
}

Summary provides aggregate statistics about the parsed commits.

type Tag added in v0.9.0

type Tag struct {
	Name        string    `json:"name"`
	Date        time.Time `json:"date"`
	DateString  string    `json:"dateString"`
	CommitHash  string    `json:"commitHash"`
	CommitCount int       `json:"commitCount,omitempty"` // Commits since previous tag
	IsInitial   bool      `json:"isInitial,omitempty"`   // True if this is the first tag
}

Tag represents a git tag with metadata.

type TagList added in v0.9.0

type TagList struct {
	Repository  string    `json:"repository,omitempty"`
	Tags        []Tag     `json:"tags"`
	TotalTags   int       `json:"totalTags"`
	GeneratedAt time.Time `json:"generatedAt"`
}

TagList represents a list of tags with metadata.

func GetTags added in v0.9.0

func GetTags() (*TagList, error)

GetTags returns all semver tags in the repository sorted by version.

type VersionRange added in v0.9.0

type VersionRange struct {
	Version string `json:"version"`
	Since   string `json:"since"`   // Previous version (empty for first)
	Until   string `json:"until"`   // This version
	Date    string `json:"date"`    // Release date
	Commits int    `json:"commits"` // Commit count in range
}

VersionRange represents a range between two versions for parsing.

func GetAllVersionRanges added in v0.9.0

func GetAllVersionRanges() ([]VersionRange, error)

GetAllVersionRanges returns all version ranges for parsing commits.

Jump to

Keyboard shortcuts

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