diff --git a/README.md b/README.md index f053839f..c7127f4b 100644 --- a/README.md +++ b/README.md @@ -480,6 +480,13 @@ The basic templates are as follows. {{ end }} {{ end -}} {{ end -}} + +{{- if .Unreleased.OtherCommits -}} +### Others +{{ range .Unreleased.OtherCommits -}} +- {{ .Header }} +{{ end -}} +{{ end -}} {{ end -}} {{ range .Versions }} @@ -514,6 +521,13 @@ The basic templates are as follows. {{ end }} {{ end -}} {{ end -}} + +{{- if .OtherCommits -}} +### Others +{{ range .OtherCommits -}} +- {{ .Header }} +{{ end -}} +{{ end -}} {{ end -}} {{- if .Versions }} diff --git a/chglog.go b/chglog.go index fc5cf9e3..d988e792 100644 --- a/chglog.go +++ b/chglog.go @@ -203,7 +203,7 @@ func (gen *Generator) readVersions(tags []*Tag, first string) ([]*Version, error return nil, err } - commitGroups, mergeCommits, revertCommits, noteGroups := gen.commitExtractor.Extract(commits) + commitGroups, mergeCommits, revertCommits, otherCommits, noteGroups := gen.commitExtractor.Extract(commits) versions = append(versions, &Version{ Tag: tag, @@ -211,6 +211,7 @@ func (gen *Generator) readVersions(tags []*Tag, first string) ([]*Version, error Commits: commits, MergeCommits: mergeCommits, RevertCommits: revertCommits, + OtherCommits: otherCommits, NoteGroups: noteGroups, }) @@ -239,13 +240,14 @@ func (gen *Generator) readUnreleased(tags []*Tag) (*Unreleased, error) { return nil, err } - commitGroups, mergeCommits, revertCommits, noteGroups := gen.commitExtractor.Extract(commits) + commitGroups, mergeCommits, revertCommits, otherCommits, noteGroups := gen.commitExtractor.Extract(commits) unreleased := &Unreleased{ CommitGroups: commitGroups, Commits: commits, MergeCommits: mergeCommits, RevertCommits: revertCommits, + OtherCommits: otherCommits, NoteGroups: noteGroups, } diff --git a/commit_extractor.go b/commit_extractor.go index 1c4fc2ad..f554cc2c 100644 --- a/commit_extractor.go +++ b/commit_extractor.go @@ -15,11 +15,12 @@ func newCommitExtractor(opts *Options) *commitExtractor { } } -func (e *commitExtractor) Extract(commits []*Commit) ([]*CommitGroup, []*Commit, []*Commit, []*NoteGroup) { +func (e *commitExtractor) Extract(commits []*Commit) ([]*CommitGroup, []*Commit, []*Commit, []*Commit, []*NoteGroup) { commitGroups := []*CommitGroup{} noteGroups := []*NoteGroup{} mergeCommits := []*Commit{} revertCommits := []*Commit{} + otherCommits := []*Commit{} filteredCommits := commitFilter(commits, e.opts.CommitFilters, e.opts.NoCaseSensitive) @@ -33,6 +34,10 @@ func (e *commitExtractor) Extract(commits []*Commit) ([]*CommitGroup, []*Commit, revertCommits = append(revertCommits, commit) continue } + + if commit.Type == "" { + otherCommits = append(otherCommits, commit) + } } for _, commit := range filteredCommits { @@ -46,7 +51,7 @@ func (e *commitExtractor) Extract(commits []*Commit) ([]*CommitGroup, []*Commit, e.sortCommitGroups(commitGroups) e.sortNoteGroups(noteGroups) - return commitGroups, mergeCommits, revertCommits, noteGroups + return commitGroups, mergeCommits, revertCommits, otherCommits, noteGroups } func (e *commitExtractor) processCommitGroups(groups *[]*CommitGroup, commit *Commit, noCaseSensitive bool) { diff --git a/commit_extractor_test.go b/commit_extractor_test.go index bfde4bff..d28be048 100644 --- a/commit_extractor_test.go +++ b/commit_extractor_test.go @@ -76,9 +76,16 @@ func TestCommitExtractor(t *testing.T) { Header: "REVERT1", }, }, + // [6] + { + Type: "", + Scope: "", + Header: "Other", + Notes: []*Note{}, + }, } - commitGroups, mergeCommits, revertCommits, noteGroups := extractor.Extract(fixtures) + commitGroups, mergeCommits, revertCommits, otherCommits, noteGroups := extractor.Extract(fixtures) assert.Equal([]*CommitGroup{ { @@ -107,6 +114,10 @@ func TestCommitExtractor(t *testing.T) { fixtures[5], }, revertCommits) + assert.Equal([]*Commit{ + fixtures[6], + }, otherCommits) + assert.Equal([]*NoteGroup{ { Title: "note1-title", @@ -207,9 +218,16 @@ func TestCommitOrderExtractor(t *testing.T) { Header: "REVERT1", }, }, + // [6] + { + Type: "", + Scope: "", + Header: "Other", + Notes: []*Note{}, + }, } - commitGroups, mergeCommits, revertCommits, noteGroups := extractor.Extract(fixtures) + commitGroups, mergeCommits, revertCommits, otherCommits, noteGroups := extractor.Extract(fixtures) assert.Equal([]*CommitGroup{ { @@ -238,6 +256,10 @@ func TestCommitOrderExtractor(t *testing.T) { fixtures[5], }, revertCommits) + assert.Equal([]*Commit{ + fixtures[6], + }, otherCommits) + assert.Equal([]*NoteGroup{ { Title: "note1-title", diff --git a/fields.go b/fields.go index 2d68b885..c25897fd 100644 --- a/fields.go +++ b/fields.go @@ -120,6 +120,7 @@ type Version struct { Commits []*Commit MergeCommits []*Commit RevertCommits []*Commit + OtherCommits []*Commit NoteGroups []*NoteGroup } @@ -129,5 +130,6 @@ type Unreleased struct { Commits []*Commit MergeCommits []*Commit RevertCommits []*Commit + OtherCommits []*Commit NoteGroups []*NoteGroup }