This commit is contained in:
Jeff Li 2025-03-29 20:27:38 +00:00 committed by GitHub
commit 6498658029
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 51 additions and 6 deletions

View file

@ -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 }}

View file

@ -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,
}

View file

@ -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) {

View file

@ -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",

View file

@ -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
}