Skip to content

Commit 7a936d9

Browse files
committed
Trim backticks from comments
Signed-off-by: Clement Debiaune <[email protected]>
1 parent f3ed6c4 commit 7a936d9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

server/events/comment_parser.go

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ type CommentParseResult struct {
145145
// - atlantis import ADDRESS ID
146146
func (e *CommentParser) Parse(rawComment string, vcsHost models.VCSHostType) CommentParseResult {
147147
comment := strings.TrimSpace(rawComment)
148+
// comment = strings.Trim(comment, "`")
148149

149150
if multiLineRegex.MatchString(comment) {
150151
return CommentParseResult{Ignore: true}

server/events/comment_parser_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,33 @@ func TestParse_HelpResponse(t *testing.T) {
144144
}
145145
}
146146

147+
func TestParse_TrimCommandString(t *testing.T) {
148+
t.Log("commands should be trimmed of whitespace and backtick (helps with Gitlab copy/paste issues)")
149+
allowCommandsCases := [][]command.Name{
150+
command.AllCommentCommands,
151+
{}, // empty case
152+
}
153+
helpComments := []string{
154+
"`atlantis help`",
155+
"` atlantis help `",
156+
"`atlantis help` ",
157+
" `atlantis help",
158+
}
159+
for _, allowCommandCase := range allowCommandsCases {
160+
for _, c := range helpComments {
161+
t.Run(fmt.Sprintf("%s with allow commands %v", c, allowCommandCase), func(t *testing.T) {
162+
commentParser := events.CommentParser{
163+
GithubUser: "github-user",
164+
ExecutableName: "atlantis",
165+
AllowCommands: allowCommandCase,
166+
}
167+
r := commentParser.Parse(c, models.Github)
168+
Equals(t, commentParser.HelpComment(), r.CommentResponse)
169+
})
170+
}
171+
}
172+
}
173+
147174
func TestParse_UnusedArguments(t *testing.T) {
148175
t.Log("if there are unused flags we return an error")
149176
cases := []struct {

0 commit comments

Comments
 (0)