mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-08-05 11:38:30 +00:00
Fixes #533, a regression where Atlantis will respond with errors to
comments that aren't intended to invoke Atlantis.
This commit is contained in:
@@ -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 (
|
||||
@@ -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}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user