Use the --tpl=./template.md
flag to specify the generated template.
whatchanged
uses the template in the Golang standard library.
Therefore, as long as your template syntax is correct, it can be generated normally.
Before that, let’s explain the render context in the template.
There are 3 parts in Context
-
Variable
- Version: the version string
- Date: the date string. the format is
YYYY-MM-dd
- Feat: the
commit
list ofnew features
which start withfeat(xxx): xxx
- Fix: the
commit
list ofbus fixed
which start withfix(xxx): xxx
- Refactor: the
commit
list ofcode refactor
which start withrefactor(xxx): xxx
- Test: the
commit
list oftest
which start withtest(xxx): xxx
- Perf: the
commit
list ofperformance
which start withpref(xxx): xxx
- Build: the
commit
list ofbuild
which start withbuild(xxx): xxx
- Ci: the
commit
list ofci
which start withci(xxx): xxx
- Chore: the
commit
list ofchore
which start withchore(xxx): xxx
- Docs: the
commit
list ofdocumentation
which start withdocs(xxx): xxx
- Style: the
commit
list ofstyles
which start withstyle(xxx): xxx
- Revert: the
commit
list ofrevert
which start withrevert: xxx
- BreakingChanges: the
commit
list ofrevert
which includesBREAKING CHANGES: xxx
in commit message body - Commits: all
commit
of generation
-
Method
- unescape(text string): unescape the string
- hashURL(commitHashString string): Add URL to commit
- stringsJoin(arr []string): Join string
source code:
type Commit struct {
Hash string
Short string
Message string
Author *object.Signature
Committer *object.Signature
Field *parser.Message
RevertCommitHash *string // revert hash
}
// https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit-message-header
type TemplateContext struct {
Version string
Date string
Build []*Commit
Ci []*Commit
Chore []*Commit
Docs []*Commit
Feat []*Commit
Fix []*Commit
Perf []*Commit
Refactor []*Commit
Test []*Commit
Style []*Commit
Revert []*Commit
BreakingChanges []*Commit
Commits []*Commit
}
type Header struct {
Type string
Scope string
Subject string
}
type BreakingChange struct {
Title string
Content string
}
type Footer struct {
BreakingChange *BreakingChange
Closes []string
}
type Message struct {
raw string
Title string
Header *Header
Body string
Footer *Footer
Revert *string // if it is a revert commit. then this is a hash for that commit
}
// Signature is used to identify who and when created a commit or tag.
type Signature struct {
// Name represents a person name. It is an arbitrary string.
Name string
// Email is an email, but it cannot be assumed to be well-formed.
Email string
// When is the timestamp of the signature.
When time.Time
}