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: case insensitive pr comments #3361

Merged
merged 5 commits into from
May 4, 2023
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
13 changes: 9 additions & 4 deletions server/events/comment_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,16 @@ func (e *CommentParser) Parse(rawComment string, vcsHost models.VCSHostType) Com
return CommentParseResult{Ignore: true}
}

// Lowercase it to avoid autocorrect issues with browsers.
executableName := strings.ToLower(args[0])

// Helpfully warn the user if they're using "terraform" instead of "atlantis"
if args[0] == "terraform" && e.ExecutableName != "terraform" {
if executableName == "terraform" && e.ExecutableName != "terraform" {
return CommentParseResult{CommentResponse: fmt.Sprintf(DidYouMeanAtlantisComment, e.ExecutableName, "terraform")}
}

// Helpfully warn the user that the command might be misspelled
if utils.IsSimilarWord(args[0], e.ExecutableName) {
if utils.IsSimilarWord(executableName, e.ExecutableName) {
return CommentParseResult{CommentResponse: fmt.Sprintf(DidYouMeanAtlantisComment, e.ExecutableName, args[0])}
}

Expand All @@ -177,7 +180,7 @@ func (e *CommentParser) Parse(rawComment string, vcsHost models.VCSHostType) Com
vcsUser = e.AzureDevopsUser
}
executableNames := []string{"run", e.ExecutableName, "@" + vcsUser}
if !e.stringInSlice(args[0], executableNames) {
if !e.stringInSlice(executableName, executableNames) {
return CommentParseResult{Ignore: true}
}

Expand All @@ -196,7 +199,9 @@ func (e *CommentParser) Parse(rawComment string, vcsHost models.VCSHostType) Com
if len(args) == 1 {
return CommentParseResult{CommentResponse: e.HelpComment()}
}
cmd := args[1]

// Lowercase it to avoid autocorrect issues with browsers.
cmd := strings.ToLower(args[1])

// Help output.
if e.stringInSlice(cmd, []string{"help", "-h", "--help"}) {
Expand Down
9 changes: 5 additions & 4 deletions server/events/comment_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ func TestParse_InvalidCommand(t *testing.T) {
"a warning.")
comments := []string{
"atlantis paln",
"atlantis Plan",
nitrocode marked this conversation as resolved.
Show resolved Hide resolved
"atlantis appely apply",
}
cp := events.NewCommentParser(
Expand Down Expand Up @@ -383,9 +382,7 @@ func TestParse_RelativeDirPath(t *testing.T) {
}
}

// If there's multiple lines but it's whitespace, allow the command. This
// occurs when you copy and paste via GitHub.
func TestParse_Multiline(t *testing.T) {
func TestParse_ValidCommand(t *testing.T) {
comments := []string{
"atlantis plan\n",
"atlantis plan\n\n",
Expand All @@ -395,6 +392,10 @@ func TestParse_Multiline(t *testing.T) {
"\r\natlantis plan",
"\natlantis plan\n",
"\r\natlantis plan\r\n",
"atlantis plan",
"Atlantis plan",
"Atlantis Plan",
"ATLANTIS PLAN",
}
for _, comment := range comments {
t.Run(comment, func(t *testing.T) {
Expand Down