Skip to content

Commit

Permalink
Fixes #533, a regression where Atlantis will respond with errors to
Browse files Browse the repository at this point in the history
comments that aren't intended to invoke Atlantis.
  • Loading branch information
lkysow committed Mar 13, 2019
1 parent aab2211 commit 2bcf17b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
27 changes: 16 additions & 11 deletions server/events/comment_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ package events
import (
"fmt"
"github.com/flynn-archive/go-shlex"
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/events/yaml"
"github.com/spf13/pflag"
"io/ioutil"
"net/url"
"path/filepath"
"regexp"
"strings"

"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/events/yaml"
"github.com/spf13/pflag"
)

const (
Expand Down Expand Up @@ -104,10 +103,9 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen
return CommentParseResult{Ignore: true}
}

args, err := shlex.Split(comment)
if err != nil {
return CommentParseResult{CommentResponse: fmt.Sprintf("```\nError parsing command: %s\n```", err)}
}
// We first use strings.Fields to parse and do an initial evaluation.
// Later we use a proper shell parser and re-parse.
args := strings.Fields(comment)
if len(args) < 1 {
return CommentParseResult{Ignore: true}
}
Expand All @@ -124,13 +122,20 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen
vcsUser = e.GitlabUser
}
executableNames := []string{"run", atlantisExecutable, "@" + vcsUser}

// If the comment doesn't start with the name of our 'executable' then
// ignore it.
if !e.stringInSlice(args[0], executableNames) {
return CommentParseResult{Ignore: true}
}

// Now that we know Atlantis is being invoked, re-parse using a shell-style
// parser.
args, err := shlex.Split(comment)
if err != nil {
return CommentParseResult{CommentResponse: fmt.Sprintf("```\nError parsing command: %s\n```", err)}
}
if len(args) < 1 {
return CommentParseResult{Ignore: true}
}

// If they've just typed the name of the executable then give them the help
// output.
if len(args) == 1 {
Expand Down
1 change: 1 addition & 0 deletions server/events/comment_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestParse_Ignored(t *testing.T) {
"abc",
"atlantis plan\nbut with newlines",
"terraform plan\nbut with newlines",
"This shouldn't error, but it does.",
}
for _, c := range ignoreComments {
r := commentParser.Parse(c, models.Github)
Expand Down

0 comments on commit 2bcf17b

Please sign in to comment.