From 9dd24779eb8717c5fd17c76f133c47f4faa59e03 Mon Sep 17 00:00:00 2001 From: Thomas Stringer Date: Wed, 25 May 2022 19:38:04 -0400 Subject: [PATCH] Fix bug with not accepting newlines 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. --- approval.go | 2 +- approval_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/approval.go b/approval.go index f67f74d..6bb777e 100644 --- a/approval.go +++ b/approval.go @@ -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 } diff --git a/approval_test.go b/approval_test.go index c4114ac..5d7f219 100644 --- a/approval_test.go +++ b/approval_test.go @@ -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?", @@ -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 {