Skip to content

Commit 6fd5056

Browse files
Merge pull request #49 from grafana/alexander-akhmetov/assigned-member-lowercase
Make assigned team member check case-insensitive
2 parents ed5ad96 + df64d51 commit 6fd5056

File tree

2 files changed

+83
-7
lines changed

2 files changed

+83
-7
lines changed

pkg/icassigner/action.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,9 @@ func (a *Action) Run(ctx context.Context, event *github.IssuesEvent, labelsInput
6060
}
6161

6262
// check if someone from the team is already assigned (skip in this case)
63-
for _, m := range teamMembers {
64-
for _, a := range event.Issue.Assignees {
65-
if a.GetLogin() == m.Name {
66-
log.Printf("Found assignee %q which is member of the matched team %q. Stopping\n", m.Name, teamName)
67-
return nil
68-
}
69-
}
63+
if assigned, teamMember := isTeamMemberAssigned(teamMembers, event.Issue.Assignees); assigned {
64+
log.Printf("Found assignee %q which is member of the matched team %q. Stopping\n", teamMember, teamName)
65+
return nil
7066
}
7167

7268
// Log the known team member names.
@@ -255,3 +251,15 @@ func convertLabels(labels []github.Label) []string {
255251

256252
return labelStrings
257253
}
254+
255+
func isTeamMemberAssigned(teamMembers []MemberConfig, assignees []*github.User) (bool, string) {
256+
for _, m := range teamMembers {
257+
for _, a := range assignees {
258+
if strings.ToLower(a.GetLogin()) == strings.ToLower(m.Name) {
259+
return true, m.Name
260+
}
261+
}
262+
}
263+
264+
return false, ""
265+
}

pkg/icassigner/action_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package icassigner
1919
import (
2020
"fmt"
2121
"testing"
22+
23+
"github.com/google/go-github/github"
2224
)
2325

2426
func TestFindTeam(t *testing.T) {
@@ -93,3 +95,69 @@ func TestFindTeam(t *testing.T) {
9395
})
9496
}
9597
}
98+
99+
func TestIsTeamMemberAssigned(t *testing.T) {
100+
teamMembers := []MemberConfig{
101+
{Name: "Alice"},
102+
{Name: "Bob"},
103+
{Name: "Charlie"},
104+
}
105+
106+
testCases := []struct {
107+
name string
108+
teamMembers []MemberConfig
109+
assignees []*github.User
110+
expectedResult bool
111+
expectedName string
112+
}{
113+
{
114+
name: "No assignees",
115+
teamMembers: teamMembers,
116+
assignees: []*github.User{},
117+
expectedResult: false,
118+
expectedName: "",
119+
},
120+
{
121+
name: "Assignee matches team member",
122+
teamMembers: teamMembers,
123+
assignees: []*github.User{{Login: github.String("Alice")}},
124+
expectedResult: true,
125+
expectedName: "Alice",
126+
},
127+
{
128+
name: "Case-insensitive match",
129+
teamMembers: teamMembers,
130+
assignees: []*github.User{{Login: github.String("bob")}},
131+
expectedResult: true,
132+
expectedName: "Bob",
133+
},
134+
{
135+
name: "No matching assignees",
136+
teamMembers: teamMembers,
137+
assignees: []*github.User{{Login: github.String("Unknown")}},
138+
expectedResult: false,
139+
expectedName: "",
140+
},
141+
{
142+
name: "Multiple assignees, one matches",
143+
teamMembers: teamMembers,
144+
assignees: []*github.User{{Login: github.String("Unknown")}, {Login: github.String("Charlie")}},
145+
expectedResult: true,
146+
expectedName: "Charlie",
147+
},
148+
}
149+
150+
for _, testCase := range testCases {
151+
t.Run(testCase.name, func(t *testing.T) {
152+
result, name := isTeamMemberAssigned(testCase.teamMembers, testCase.assignees)
153+
154+
if result != testCase.expectedResult {
155+
t.Errorf("Expected result to be %v, but got %v", testCase.expectedResult, result)
156+
}
157+
158+
if name != testCase.expectedName {
159+
t.Errorf("Expected name to be %q, but got %q", testCase.expectedName, name)
160+
}
161+
})
162+
}
163+
}

0 commit comments

Comments
 (0)