Skip to content

Commit c3a3e30

Browse files
feat(semrel): sort types in changelog
1 parent ffb7964 commit c3a3e30

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

semrel.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/google/go-github/github"
99
"golang.org/x/oauth2"
1010
"regexp"
11+
"sort"
1112
"strings"
1213
"time"
1314
)
@@ -194,6 +195,17 @@ var typeToText = map[string]string{
194195
"%%bc%%": "Breaking Changes",
195196
}
196197

198+
func getSortedKeys(m *map[string]string) []string {
199+
keys := make([]string, len(*m))
200+
i := 0
201+
for k, _ := range *m {
202+
keys[i] = k
203+
i++
204+
}
205+
sort.Strings(keys)
206+
return keys
207+
}
208+
197209
func GetChangelog(commits []*Commit, latestRelease *Release, newVersion *semver.Version) string {
198210
ret := fmt.Sprintf("## %s (%s)\n\n", newVersion.String(), time.Now().UTC().Format("2006-01-02"))
199211
typeScopeMap := make(map[string]string)
@@ -210,7 +222,8 @@ func GetChangelog(commits []*Commit, latestRelease *Release, newVersion *semver.
210222
}
211223
typeScopeMap[commit.Type] += formatCommit(commit)
212224
}
213-
for t, msg := range typeScopeMap {
225+
for _, t := range getSortedKeys(&typeScopeMap) {
226+
msg := typeScopeMap[t]
214227
typeName, found := typeToText[t]
215228
if !found {
216229
typeName = t

0 commit comments

Comments
 (0)