Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Trim backticks from MR comments (for Gitlab) #5244

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/events/comment_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
27 changes: 27 additions & 0 deletions server/events/comment_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading