Skip to content

Commit b437596

Browse files
omriharelbivas
authored andcommitted
Choose assignee w/o case sensitivity to the author's name (#2)
1 parent c616fdb commit b437596

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

bot/actions/autoassign/autoassign.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package autoassign
22

33
import (
44
"math/rand"
5+
"strings"
56

67
"github.com/bivas/rivi/bot"
78
"github.com/bivas/rivi/util"
@@ -60,7 +61,7 @@ func (a *action) Apply(config bot.Configuration, meta bot.EventData) {
6061
}
6162

6263
func (a *action) randomUsers(config bot.Configuration, meta bot.EventData, lookupRoles []string) []string {
63-
possibleSet := util.StringSet{}
64+
possibleSet := util.StringSet{Transformer: strings.ToLower}
6465
possibleSet.AddAll(config.GetRoleMembers(lookupRoles...)).Remove(meta.GetOrigin())
6566
for _, assignee := range meta.GetAssignees() {
6667
possibleSet.Remove(assignee)

bot/actions/autoassign/autoassign_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ func TestActionApplyWithoutOrigin(t *testing.T) {
5757
}
5858
}
5959

60+
func TestActionApplyWithoutOriginCaseInsensitive(t *testing.T) {
61+
action := action{rule: &rule{Require: 1, FromRoles: []string{"default"}}}
62+
roles := make(map[string][]string)
63+
roles["default"] = []string{"usEr1", "user2"}
64+
for i := 0; i < 10; i++ {
65+
config := &mock.MockConfiguration{RoleMembers: roles}
66+
meta := &mock.MockEventData{Assignees: []string{}, Origin: "USER1"}
67+
action.Apply(config, meta)
68+
assert.Len(t, meta.AddedAssignees, 1, "assignment")
69+
assert.NotContains(t, meta.AddedAssignees, "user1", "matched group")
70+
assert.Contains(t, meta.AddedAssignees, "user2", "matched group")
71+
}
72+
}
73+
6074
func TestActionApplyHasAssignee(t *testing.T) {
6175
action := action{rule: &rule{Require: 1, FromRoles: []string{"group"}}}
6276
roles := make(map[string][]string)

0 commit comments

Comments
 (0)