-
Notifications
You must be signed in to change notification settings - Fork 0
/
category.go
70 lines (60 loc) · 1.65 KB
/
category.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package superclog
var (
CategoryBuild = Category{"build", "Build"}
CategoryChore = Category{"chore", "Chores"}
CategoryCI = Category{"ci", "CI"}
CategoryDocs = Category{"docs", "Documentation"}
CategoryFeat = Category{"feat", "Features"}
CategoryFix = Category{"fix", "Fixes"}
CategoryPerf = Category{"perf", "Performance Improvements"}
CategoryRefactor = Category{"refactor", "Refactoring"}
CategoryRevert = Category{"revert", "Reverting"}
CategoryStyle = Category{"style", "Style"}
CategoryTest = Category{"test", "Test"}
CategoryUnknown = Category{"", "Miscellaneous"}
CategoryList = []Category{
CategoryBuild,
CategoryChore,
CategoryCI,
CategoryDocs,
CategoryFeat,
CategoryFix,
CategoryPerf,
CategoryRefactor,
CategoryRevert,
CategoryStyle,
CategoryTest,
CategoryUnknown,
}
)
type Category struct {
Value string
FriendlyName string
}
// CategoryOf gets the category of the change
func CategoryOf(v string) Category {
for i := range CategoryList {
if CategoryList[i].Value == v {
return CategoryList[i]
}
}
return CategoryUnknown
}
// Categories holds which category the commit is.
type Categories map[Category]Component
// CalculateCategories calculates categories for the
func CalculateCategories(commits []Commit) Categories {
v := make(Categories, 10)
for i := range commits {
v.AddCommit(&commits[i])
}
return v
}
func (c Categories) AddCommit(commit *Commit) {
typ := commit.Conventional.Type
component := commit.Conventional.Component
if _, ok := c[typ][component]; !ok {
c[typ] = make(Component, 5)
}
c[typ][component] = append(c[typ][component], commit)
}