Skip to content

Commit

Permalink
Fix bug with not accepting newlines (#12)
Browse files Browse the repository at this point in the history
Prior to this PR, if there was a newline (or multiple newline
characters) at the end of the keyword then it wouldn't match. With this
fix any number of newlines at the end of the keyword match will now be
considered for approve or deny.
  • Loading branch information
trstringer authored May 25, 2022
1 parent c4d4c80 commit 75c263a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion approval.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func approversIndex(approvers []string, name string) int {

func isApproved(commentBody string) (bool, error) {
for _, approvedWord := range approvedWords {
matched, err := regexp.MatchString(fmt.Sprintf("(?i)^%s[.!]?$", approvedWord), commentBody)
matched, err := regexp.MatchString(fmt.Sprintf("(?i)^%s[.!]*\n*$", approvedWord), commentBody)
if err != nil {
return false, err
}
Expand Down
20 changes: 20 additions & 0 deletions approval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ func TestApprovedCommentBody(t *testing.T) {
commentBody: "Approved!",
isSuccess: true,
},
{
name: "approved_titlecase_multi_exclamation",
commentBody: "Approved!!",
isSuccess: true,
},
{
name: "approved_titlecase_question",
commentBody: "Approved?",
Expand All @@ -230,6 +235,21 @@ func TestApprovedCommentBody(t *testing.T) {
commentBody: "this is just some random comment",
isSuccess: false,
},
{
name: "approved_with_newline",
commentBody: "approved\n",
isSuccess: true,
},
{
name: "approved_with_exclamation_newline",
commentBody: "approved!\n",
isSuccess: true,
},
{
name: "approved_with_multi_exclamation_multi_newline",
commentBody: "approved!!!\n\n\n",
isSuccess: true,
},
}

for _, testCase := range testCases {
Expand Down

0 comments on commit 75c263a

Please sign in to comment.