Skip to content

Commit c1ebf58

Browse files
authored
Make name comparison case-insensitive (#172)
Signed-off-by: Simeon Widdis <[email protected]>
1 parent ef4dddd commit c1ebf58

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

approval.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ func (a *approvalEnvironment) SetActionOutputs(outputs map[string]string) (bool,
136136
// two outputs from being written on the same line.
137137
fileInfo, err := f.Stat()
138138
if err != nil {
139-
return false, err
139+
return false, err
140140
}
141141
if fileInfo.Size() > 0 {
142-
if _, err := f.WriteString("\n"); err != nil {
143-
return false, err
144-
}
142+
if _, err := f.WriteString("\n"); err != nil {
143+
return false, err
144+
}
145145
}
146146

147147
if _, err := f.WriteString(strings.Join(pairs, "\n")); err != nil {
@@ -194,7 +194,7 @@ func approvalFromComments(comments []*github.IssueComment, approvers []string, m
194194

195195
func approversIndex(approvers []string, name string) int {
196196
for idx, approver := range approvers {
197-
if approver == name {
197+
if strings.EqualFold(approver, name) {
198198
return idx
199199
}
200200
}

approval_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"errors"
55
"os"
6+
"strings"
67
"testing"
78

89
"github.com/google/go-github/v43/github"
@@ -16,6 +17,8 @@ func TestApprovalFromComments(t *testing.T) {
1617
bodyDenied := "Denied"
1718
bodyPending := "not approval or denial"
1819

20+
login1u := strings.ToUpper(login1)
21+
1922
testCases := []struct {
2023
name string
2124
comments []*github.IssueComment
@@ -160,6 +163,17 @@ func TestApprovalFromComments(t *testing.T) {
160163
expectedStatus: approvalStatusPending,
161164
minimumApprovals: 2,
162165
},
166+
{
167+
name: "single_approver_single_comment_approved_case_insensitive",
168+
comments: []*github.IssueComment{
169+
{
170+
User: &github.User{Login: &login1u},
171+
Body: &bodyApproved,
172+
},
173+
},
174+
approvers: []string{login1},
175+
expectedStatus: approvalStatusApproved,
176+
},
163177
}
164178

165179
for _, testCase := range testCases {

0 commit comments

Comments
 (0)