Documentation ¶
Index ¶
- Constants
- Variables
- type Changelog
- func (c *Changelog) Changelog() string
- func (c *Changelog) Config() *Config
- func (c *Changelog) FetchGitLog(sha1, sha2 string, moreArgs ...string) *Changelog
- func (c *Changelog) Generate() (err error)
- func (c *Changelog) LogCount() int
- func (c *Changelog) Parse() (err error)
- func (c *Changelog) SetLogText(gitLogOut string)
- func (c *Changelog) String() string
- func (c *Changelog) WithConfig(cfg *Config) *Changelog
- func (c *Changelog) WithConfigFn(fn func(cfg *Config)) *Changelog
- func (c *Changelog) WithFn(fn func(c *Changelog)) *Changelog
- func (c *Changelog) WriteTo(w io.Writer) (int64, error)
- type Config
- type Formatter
- type GHReleaseFormatter
- type GroupMatcher
- type ItemFilter
- type ItemFilterFunc
- type LineParseFunc
- type LineParser
- type LogItem
- type MarkdownFormatter
- type Rule
- type RuleMatcher
- type SimpleFormatter
Constants ¶
const ( FilterMsgLen = "msg_len" FilterWordsLen = "words_len" FilterKeyword = "keyword" FilterKeywords = "keywords" )
built in filters
const ( FormatterSimple = "simple" FormatterMarkdown = "markdown" FormatterGhRelease = "ghr" )
built-in formatters
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
const Sep = " | "
Sep consts for parse git log
Variables ¶
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
var DefaultGroup = "Other"
DefaultGroup name
var DefaultMatcher = NewDefaultMatcher()
DefaultMatcher for match group name.
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 NewWithGitLog ¶
NewWithGitLog new object with git log output text
func (*Changelog) FetchGitLog ¶
FetchGitLog fetch log data by git log
func (*Changelog) SetLogText ¶
SetLogText by git log
func (*Changelog) WithConfig ¶
WithConfig with new config object
func (*Changelog) WithConfigFn ¶
WithConfigFn config the object
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 (*Config) CreateFilters ¶
func (c *Config) CreateFilters() []ItemFilter
CreateFilters for Changelog
func (*Config) CreateFormatter ¶
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 ¶
GroupMatcher interface
type ItemFilter ¶
ItemFilter interface
type ItemFilterFunc ¶
ItemFilterFunc define. return false to filter item. type LineFilterFunc func(line string) bool
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
type LineParseFunc ¶
LineParseFunc func define
type LineParser ¶
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
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 (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