Skip to content

Commit 194769b

Browse files
committed
sort size rules
1 parent 7d161ea commit 194769b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

bot/actions/sizing/rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (r rules) Len() int {
2828
}
2929

3030
func (r rules) Less(i, j int) bool {
31-
return r[i].ChangedFilesThreshold < r[j].ChangedFilesThreshold && r[i].ChangesThreshold < r[j].ChangesThreshold
31+
return r[i].ChangedFilesThreshold < r[j].ChangedFilesThreshold || r[i].ChangesThreshold < r[j].ChangesThreshold
3232
}
3333

3434
func (r rules) Swap(i, j int) {

bot/actions/sizing/sizing_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package sizing
33
import (
44
"github.com/bivas/rivi/bot/mock"
55
"github.com/stretchr/testify/assert"
6-
"sort"
76
"testing"
87
)
98

@@ -15,6 +14,7 @@ func buildRule(name, label string, changedFiles int) *sizingRule {
1514

1615
func buildRules(withDefault bool) *action {
1716
result := &action{items: rules{
17+
*buildRule("l", "size/l", 150),
1818
*buildRule("xs", "size/xs", 5),
1919
*buildRule("s", "size/s", 15),
2020
*buildRule("m", "size/m", 75),
@@ -27,10 +27,18 @@ func buildRules(withDefault bool) *action {
2727
result.possibleLabels = append(result.possibleLabels, "default-label")
2828
result.items = append(result.items, sizingRule{Name: "default", Label: "default-label"})
2929
}
30-
sort.Sort(sort.Reverse(result.items))
3130
return result
3231
}
3332

33+
func TestSizingXS(t *testing.T) {
34+
action := buildRules(false)
35+
config := &mock.MockConfiguration{}
36+
meta := &mock.MockEventData{Labels: []string{}, ChangedFiles: 1, ChangesAdd: 24, ChangesRemove: 31}
37+
action.Apply(config, meta)
38+
assert.Len(t, meta.AddedLabels, 1, "labels")
39+
assert.Equal(t, "size/xs", meta.AddedLabels[0], "size label")
40+
}
41+
3442
func TestSizing(t *testing.T) {
3543
action := buildRules(false)
3644
config := &mock.MockConfiguration{}

0 commit comments

Comments
 (0)