From 7a936d9c716261165154b4ad31f8a35c270fe1cc Mon Sep 17 00:00:00 2001 From: Clement Debiaune Date: Sat, 18 Jan 2025 21:24:46 +0000 Subject: [PATCH] Trim backticks from comments Signed-off-by: Clement Debiaune --- server/events/comment_parser.go | 1 + server/events/comment_parser_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/server/events/comment_parser.go b/server/events/comment_parser.go index 829c15ced9..34849cf9d0 100644 --- a/server/events/comment_parser.go +++ b/server/events/comment_parser.go @@ -145,6 +145,7 @@ type CommentParseResult struct { // - atlantis import ADDRESS ID func (e *CommentParser) Parse(rawComment string, vcsHost models.VCSHostType) CommentParseResult { comment := strings.TrimSpace(rawComment) + // comment = strings.Trim(comment, "`") if multiLineRegex.MatchString(comment) { return CommentParseResult{Ignore: true} diff --git a/server/events/comment_parser_test.go b/server/events/comment_parser_test.go index 88ededcfff..bf48469302 100644 --- a/server/events/comment_parser_test.go +++ b/server/events/comment_parser_test.go @@ -144,6 +144,33 @@ func TestParse_HelpResponse(t *testing.T) { } } +func TestParse_TrimCommandString(t *testing.T) { + t.Log("commands should be trimmed of whitespace and backtick (helps with Gitlab copy/paste issues)") + allowCommandsCases := [][]command.Name{ + command.AllCommentCommands, + {}, // empty case + } + helpComments := []string{ + "`atlantis help`", + "` atlantis help `", + "`atlantis help` ", + " `atlantis help", + } + for _, allowCommandCase := range allowCommandsCases { + for _, c := range helpComments { + t.Run(fmt.Sprintf("%s with allow commands %v", c, allowCommandCase), func(t *testing.T) { + commentParser := events.CommentParser{ + GithubUser: "github-user", + ExecutableName: "atlantis", + AllowCommands: allowCommandCase, + } + r := commentParser.Parse(c, models.Github) + Equals(t, commentParser.HelpComment(), r.CommentResponse) + }) + } + } +} + func TestParse_UnusedArguments(t *testing.T) { t.Log("if there are unused flags we return an error") cases := []struct {