Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Thomas Stringer
9dd24779eb 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.
2022-05-25 19:38:04 -04:00
2 changed files with 21 additions and 1 deletions

View file

@ -126,7 +126,7 @@ func approversIndex(approvers []string, name string) int {
func isApproved(commentBody string) (bool, error) { func isApproved(commentBody string) (bool, error) {
for _, approvedWord := range approvedWords { 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 { if err != nil {
return false, err return false, err
} }

View file

@ -215,6 +215,11 @@ func TestApprovedCommentBody(t *testing.T) {
commentBody: "Approved!", commentBody: "Approved!",
isSuccess: true, isSuccess: true,
}, },
{
name: "approved_titlecase_multi_exclamation",
commentBody: "Approved!!",
isSuccess: true,
},
{ {
name: "approved_titlecase_question", name: "approved_titlecase_question",
commentBody: "Approved?", commentBody: "Approved?",
@ -230,6 +235,21 @@ func TestApprovedCommentBody(t *testing.T) {
commentBody: "this is just some random comment", commentBody: "this is just some random comment",
isSuccess: false, 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 { for _, testCase := range testCases {