/
rule.go
36 lines (29 loc) · 822 Bytes
/
rule.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
package sizing
import (
"math"
)
type sizingRule struct {
Name string
Label string `mapstructure:"label"`
Comment string `mapstructure:"comment"`
ChangedFilesThreshold int `mapstructure:"changed-files-threshold"`
ChangesThreshold int `mapstructure:"changes-threshold"`
}
func (rule *sizingRule) Defaults() {
if rule.ChangesThreshold == 0 {
rule.ChangesThreshold = math.MaxInt32
}
if rule.ChangedFilesThreshold == 0 {
rule.ChangedFilesThreshold = math.MaxInt32
}
}
type rules []sizingRule
func (r rules) Len() int {
return len(r)
}
func (r rules) Less(i, j int) bool {
return r[i].ChangedFilesThreshold < r[j].ChangedFilesThreshold || r[i].ChangesThreshold < r[j].ChangesThreshold
}
func (r rules) Swap(i, j int) {
r[i], r[j] = r[j], r[i]
}