gitlog

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 5 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 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:"short_hash"`
	Author            string   `json:"author"`
	AuthorEmail       string   `json:"author_email,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:"files_changed,omitempty"`
	Insertions        int      `json:"insertions,omitempty"`
	Deletions         int      `json:"deletions,omitempty"`
	Files             []string `json:"files,omitempty"`
	SuggestedCategory string   `json:"suggested_category,omitempty"`
}

Commit represents a parsed git commit with structured metadata.

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:"generated_at"`
	Commits     []Commit  `json:"commits"`
	Summary     Summary   `json:"summary"`
}

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.

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:"commit_count"`
}

Range represents the commit range that was parsed.

type Summary

type Summary struct {
	ByType              map[string]int `json:"by_type,omitempty"`
	BySuggestedCategory map[string]int `json:"by_suggested_category,omitempty"`
	TotalFilesChanged   int            `json:"total_files_changed,omitempty"`
	TotalInsertions     int            `json:"total_insertions,omitempty"`
	TotalDeletions      int            `json:"total_deletions,omitempty"`
}

Summary provides aggregate statistics about the parsed commits.

Jump to

Keyboard shortcuts

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