-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathentrytype.go
76 lines (66 loc) · 1.75 KB
/
entrytype.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
71
72
73
74
75
76
package changelogutils
import (
"encoding/json"
"fmt"
)
type ChangelogEntryType int
const (
BREAKING_CHANGE ChangelogEntryType = iota
FIX
NEW_FEATURE
NON_USER_FACING
DEPENDENCY_BUMP
HELM
UPGRADE
)
var (
_ChangelogEntryTypeToValue = map[string]ChangelogEntryType{
"BREAKING_CHANGE": BREAKING_CHANGE,
"FIX": FIX,
"NEW_FEATURE": NEW_FEATURE,
"NON_USER_FACING": NON_USER_FACING,
"DEPENDENCY_BUMP": DEPENDENCY_BUMP,
"HELM": HELM,
"UPGRADE": UPGRADE,
}
_ChangelogEntryValueToType = map[ChangelogEntryType]string{
BREAKING_CHANGE: "BREAKING_CHANGE",
FIX: "FIX",
NEW_FEATURE: "NEW_FEATURE",
NON_USER_FACING: "NON_USER_FACING",
DEPENDENCY_BUMP: "DEPENDENCY_BUMP",
HELM: "HELM",
UPGRADE: "UPGRADE",
}
)
func (clt ChangelogEntryType) String() string {
return [...]string{"BREAKING_CHANGE", "FIX", "NEW_FEATURE", "NON_USER_FACING", "DEPENDENCY_BUMP", "HELM", "UPGRADE"}[clt]
}
func (clt ChangelogEntryType) BreakingChange() bool {
return clt == BREAKING_CHANGE
}
func (clt ChangelogEntryType) NewFeature() bool {
return clt == NEW_FEATURE
}
func (clt ChangelogEntryType) MarshalJSON() ([]byte, error) {
if s, ok := interface{}(clt).(fmt.Stringer); ok {
return json.Marshal(s.String())
}
s, ok := _ChangelogEntryValueToType[clt]
if !ok {
return nil, fmt.Errorf("invalid ChangelogEntry type: %d", clt)
}
return json.Marshal(s)
}
func (clt *ChangelogEntryType) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("ChangelogEntryType should be a string, got %s", data)
}
v, ok := _ChangelogEntryTypeToValue[s]
if !ok {
return fmt.Errorf("invalid ChangelogEntryType %q", s)
}
*clt = v
return nil
}