chlog

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FilterMsgLen   = "msg_len"
	FilterWordsLen = "words_len"
	FilterKeyword  = "keyword"
	FilterKeywords = "keywords"
)

built in filters

View Source
const (
	FormatterSimple    = "simple"
	FormatterMarkdown  = "markdown"
	FormatterGhRelease = "ghr"
)

built-in formatters

View Source
const (
	// LogFmtHs - %n new line
	// id, msg
	LogFmtHs = "%H | %s"
	// LogFmtHsa id, msg, author
	LogFmtHsa = "%H | %s | %an"
	// LogFmtHsc id, msg, committer
	LogFmtHsc = "%H | %s | %cn"
	// LogFmtHsd id, msg, author date
	LogFmtHsd = "%H | %s | %ai"
	// LogFmtHsd1 id, msg, commit date
	LogFmtHsd1 = "%H | %s | %ci"
)

see https://devhints.io/git-log-format see https://git-scm.com/docs/pretty-formats

View Source
const Sep = " | "

Sep consts for parse git log

Variables

View Source
var BuiltInParser = LineParseFunc(func(line string, c *Changelog) *LogItem {
	li := &LogItem{}
	switch c.cfg.LogFormat {
	case LogFmtHs:
		ss := strings.SplitN(line, Sep, 2)
		if len(ss) < 2 {
			return nil
		}

		li.HashID, li.Msg = ss[0], ss[1]
	case LogFmtHsa:
		ss := strings.SplitN(line, Sep, 3)
		if len(ss) < 3 {
			return nil
		}

		li.HashID, li.Msg, li.Author = ss[0], ss[1], ss[2]
	case LogFmtHsc:
		ss := strings.SplitN(line, Sep, 3)
		if len(ss) < 3 {
			return nil
		}

		li.HashID, li.Msg, li.Committer = ss[0], ss[1], ss[2]
	case LogFmtHsd, LogFmtHsd1:
		ss := strings.SplitN(line, Sep, 3)
		if len(ss) < 3 {
			return nil
		}

		li.HashID, li.Msg, li.Date = ss[0], ss[1], ss[2]
	default:
		goutil.Panicf("unsupported log format '%s'", c.cfg.LogFormat)
	}

	return li
})

BuiltInParser struct

View Source
var DefaultGroup = "Other"

DefaultGroup name

View Source
var DefaultMatcher = NewDefaultMatcher()

DefaultMatcher for match group name.

View Source
var ErrEmptyLogText = errors.New("empty git log text for parse")

ErrEmptyLogText error

Functions

This section is empty.

Types

type Changelog

type Changelog struct {

	// LineParser can custom log line parser
	LineParser LineParser
	// ItemFilters The parsed log item filters
	ItemFilters []ItemFilter
	// Formatter The item formatter. format each item to string
	Formatter Formatter
	// contains filtered or unexported fields
}

Changelog struct

func New

func New() *Changelog

New object

func NewWithConfig

func NewWithConfig(cfg *Config) *Changelog

NewWithConfig object

func NewWithGitLog

func NewWithGitLog(gitLogOut string) *Changelog

NewWithGitLog new object with git log output text

func (*Changelog) Changelog

func (c *Changelog) Changelog() string

Changelog get generated change log string

func (*Changelog) Config

func (c *Changelog) Config() *Config

Config get

func (*Changelog) FetchGitLog

func (c *Changelog) FetchGitLog(sha1, sha2 string, moreArgs ...string) *Changelog

FetchGitLog fetch log data by git log

func (*Changelog) Generate

func (c *Changelog) Generate() (err error)

Generate the changelog by parsed log items

func (*Changelog) LogCount

func (c *Changelog) LogCount() int

LogCount get

func (*Changelog) LogIsEmpty added in v0.3.5

func (c *Changelog) LogIsEmpty() bool

LogIsEmpty check by git log

func (*Changelog) Parse

func (c *Changelog) Parse() (err error)

Parse the loaded git log text

func (*Changelog) SetLogText

func (c *Changelog) SetLogText(gitLogOut string)

SetLogText from git log

func (*Changelog) String

func (c *Changelog) String() string

String get generated change log string

func (*Changelog) WithConfig

func (c *Changelog) WithConfig(cfg *Config) *Changelog

WithConfig with new config object

func (*Changelog) WithConfigFn

func (c *Changelog) WithConfigFn(fn func(cfg *Config)) *Changelog

WithConfigFn config the object

func (*Changelog) WithFn

func (c *Changelog) WithFn(fn func(c *Changelog)) *Changelog

WithFn config the object

func (*Changelog) WriteTo

func (c *Changelog) WriteTo(w io.Writer) (int64, error)

WriteTo changelog to the writer

type Config

type Config struct {
	// Title string for formatted text. eg: "## Change Log"
	Title string `json:"title" yaml:"title"`
	// RepoURL repo URL address
	RepoURL string `json:"repo_url" yaml:"repo_url"`
	// Style name. allow: simple, markdown, ghr
	Style string `json:"style" yaml:"style"`
	// LogFormat built-in log format string.
	//
	// use on the `git log --pretty="format:%H"`.
	//
	// see consts LogFmt*, eg: LogFmtHs
	LogFormat string `json:"log_format" yaml:"log_format"`
	// GroupPrefix string. eg: '### '
	GroupPrefix string `yaml:"group_prefix"`
	// GroupPrefix string.
	GroupSuffix string `yaml:"group_suffix"`
	// NoGroup Not output group name line.
	NoGroup bool `yaml:"no_group"`
	// RmRepeat remove repeated log by message
	RmRepeat bool `json:"rm_repeat" yaml:"rm_repeat"`
	// Verbose show more information
	Verbose bool `json:"verbose" yaml:"verbose"`
	// Names define group names and sort
	Names []string `json:"names" yaml:"names"`
	// Rules for match group
	Rules []Rule `json:"rules" yaml:"rules"`
	// Filters for filtering
	Filters []maputil.Data `json:"filters" yaml:"filters"`
}

Config struct

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig instance

func (*Config) Create

func (c *Config) Create() *Changelog

Create Changelog

func (*Config) CreateFilters

func (c *Config) CreateFilters() []ItemFilter

CreateFilters for Changelog

func (*Config) CreateFormatter

func (c *Config) CreateFormatter() Formatter

CreateFormatter for Changelog

type Formatter

type Formatter interface {
	// MatchGroup from log msg
	MatchGroup(msg string) (group string)
	// Format the log item to line
	Format(li *LogItem) (group, fmtLine string)
}

Formatter interface

type GHReleaseFormatter

type GHReleaseFormatter struct {
	MarkdownFormatter
}

GHReleaseFormatter struct

func (*GHReleaseFormatter) Format

func (f *GHReleaseFormatter) Format(li *LogItem) (group, fmtLine string)

Format the log item to line

type GroupMatcher

type GroupMatcher interface {
	// Match group from log msg(has been trimmed)
	Match(msg string) (group string)
}

GroupMatcher interface

type ItemFilter

type ItemFilter interface {
	// Handle filtering
	Handle(li *LogItem) bool
}

ItemFilter interface

type ItemFilterFunc

type ItemFilterFunc func(li *LogItem) bool

ItemFilterFunc define. return False to filter(discard) item.

func KeywordFilter

func KeywordFilter(kw string, exclude bool) ItemFilterFunc

KeywordFilter filter log item by keyword

func KeywordsFilter

func KeywordsFilter(kws []string, exclude bool) ItemFilterFunc

KeywordsFilter filter log item by keywords

func MsgLenFilter

func MsgLenFilter(minLen int) ItemFilterFunc

MsgLenFilter handler

func WordsLenFilter

func WordsLenFilter(minLen int) ItemFilterFunc

WordsLenFilter handler

  • For English text: counts words separated by whitespace
  • For Chinese text: counts characters (runes) since Chinese doesn't use spaces
  • For mixed text: counts both English words and Chinese characters

func (ItemFilterFunc) Handle

func (f ItemFilterFunc) Handle(li *LogItem) bool

Handle filtering

type LineParseFunc

type LineParseFunc func(line string, c *Changelog) *LogItem

LineParseFunc func define

func (LineParseFunc) Parse

func (f LineParseFunc) Parse(line string, c *Changelog) *LogItem

Parse log line to log item

type LineParser

type LineParser interface {
	Parse(line string, c *Changelog) *LogItem
}

LineParser interface define

type LogItem

type LogItem struct {
	HashID    string // %H %h
	ParentID  string // %P %p
	Msg       string // %s
	Date      string // %ci
	Author    string // %an
	Committer string // %cn
}

LogItem struct

func (*LogItem) AbbrevID

func (l *LogItem) AbbrevID() string

AbbrevID get abbrev commit ID

func (*LogItem) Username

func (l *LogItem) Username() string

Username get commit username.

type MarkdownFormatter

type MarkdownFormatter struct {
	SimpleFormatter
	// RepoURL git repo remote URL address
	RepoURL string
}

MarkdownFormatter struct

func (*MarkdownFormatter) Format

func (f *MarkdownFormatter) Format(li *LogItem) (group, fmtLine string)

Format the log item to line

type Rule

type Rule struct {
	// Name for group
	Name string `json:"name" yaml:"name"`
	// StartWiths message start withs string.
	StartWiths []string `json:"start_withs" yaml:"start_withs"`
	// Contains message should contain there are strings.
	Contains []string `json:"contains" yaml:"contains"`
}

Rule struct

type RuleMatcher

type RuleMatcher struct {
	// Names define group names and sort
	Names []string `json:"names" yaml:"names"`
	Rules []Rule   `json:"rules" yaml:"rules"`
}

RuleMatcher struct

func NewDefaultMatcher

func NewDefaultMatcher() *RuleMatcher

NewDefaultMatcher instance

func (RuleMatcher) Match

func (m RuleMatcher) Match(msg string) string

Match group name from log message.

type SimpleFormatter

type SimpleFormatter struct {
	// GroupMatch group match handler.
	GroupMatch GroupMatcher
}

SimpleFormatter struct

func (*SimpleFormatter) Format

func (f *SimpleFormatter) Format(li *LogItem) (group, fmtLine string)

Format the log item to line

func (*SimpleFormatter) MatchGroup

func (f *SimpleFormatter) MatchGroup(msg string) (group string)

MatchGroup from log msg

Jump to

Keyboard shortcuts

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