Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make assigned team member check case-insensitive #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions pkg/icassigner/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,9 @@ func (a *Action) Run(ctx context.Context, event *github.IssuesEvent, labelsInput
}

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

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

return labelStrings
}

func isTeamMemberAssigned(teamMembers []MemberConfig, assignees []*github.User) (bool, string) {
for _, m := range teamMembers {
for _, a := range assignees {
if strings.ToLower(a.GetLogin()) == strings.ToLower(m.Name) {
return true, m.Name
}
}
}

return false, ""
}
68 changes: 68 additions & 0 deletions pkg/icassigner/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package icassigner
import (
"fmt"
"testing"

"github.com/google/go-github/github"
)

func TestFindTeam(t *testing.T) {
Expand Down Expand Up @@ -93,3 +95,69 @@ func TestFindTeam(t *testing.T) {
})
}
}

func TestIsTeamMemberAssigned(t *testing.T) {
teamMembers := []MemberConfig{
{Name: "Alice"},
{Name: "Bob"},
{Name: "Charlie"},
}

testCases := []struct {
name string
teamMembers []MemberConfig
assignees []*github.User
expectedResult bool
expectedName string
}{
{
name: "No assignees",
teamMembers: teamMembers,
assignees: []*github.User{},
expectedResult: false,
expectedName: "",
},
{
name: "Assignee matches team member",
teamMembers: teamMembers,
assignees: []*github.User{{Login: github.String("Alice")}},
expectedResult: true,
expectedName: "Alice",
},
{
name: "Case-insensitive match",
teamMembers: teamMembers,
assignees: []*github.User{{Login: github.String("bob")}},
expectedResult: true,
expectedName: "Bob",
},
{
name: "No matching assignees",
teamMembers: teamMembers,
assignees: []*github.User{{Login: github.String("Unknown")}},
expectedResult: false,
expectedName: "",
},
{
name: "Multiple assignees, one matches",
teamMembers: teamMembers,
assignees: []*github.User{{Login: github.String("Unknown")}, {Login: github.String("Charlie")}},
expectedResult: true,
expectedName: "Charlie",
},
}

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
result, name := isTeamMemberAssigned(testCase.teamMembers, testCase.assignees)

if result != testCase.expectedResult {
t.Errorf("Expected result to be %v, but got %v", testCase.expectedResult, result)
}

if name != testCase.expectedName {
t.Errorf("Expected name to be %q, but got %q", testCase.expectedName, name)
}
})
}
}
Loading