diff --git a/server/events/yaml/parser_validator.go b/server/events/yaml/parser_validator.go index 4d879934a..0e2bd84a2 100644 --- a/server/events/yaml/parser_validator.go +++ b/server/events/yaml/parser_validator.go @@ -27,7 +27,14 @@ type ParserValidator struct{} // for the repo at absRepoDir. // Returns an error if for some reason it can't read that directory. func (p *ParserValidator) HasRepoCfg(absRepoDir string) (bool, error) { - _, err := os.Stat(p.repoCfgPath(absRepoDir)) + // Checks for a config file with an invalid extension (atlantis.yml) + const invalidExtensionFilename = "atlantis.yml" + _, err := os.Stat(p.repoCfgPath(absRepoDir, invalidExtensionFilename)) + if err == nil { + return false, errors.Errorf("found %q as config file; rename using the .yaml extension - %q", invalidExtensionFilename, AtlantisYAMLFilename) + } + + _, err = os.Stat(p.repoCfgPath(absRepoDir, AtlantisYAMLFilename)) if os.IsNotExist(err) { return false, nil } @@ -38,7 +45,7 @@ func (p *ParserValidator) HasRepoCfg(absRepoDir string) (bool, error) { // repo at absRepoDir. // If there was no config file, it will return an os.IsNotExist(error). func (p *ParserValidator) ParseRepoCfg(absRepoDir string, globalCfg valid.GlobalCfg, repoID string) (valid.RepoCfg, error) { - configFile := p.repoCfgPath(absRepoDir) + configFile := p.repoCfgPath(absRepoDir, AtlantisYAMLFilename) configData, err := ioutil.ReadFile(configFile) // nolint: gosec if err != nil { @@ -122,8 +129,8 @@ func (p *ParserValidator) validateRawGlobalCfg(rawCfg raw.GlobalCfg, defaultCfg return validCfg, nil } -func (p *ParserValidator) repoCfgPath(repoDir string) string { - return filepath.Join(repoDir, AtlantisYAMLFilename) +func (p *ParserValidator) repoCfgPath(repoDir, cfgFilename string) string { + return filepath.Join(repoDir, cfgFilename) } func (p *ParserValidator) validateProjectNames(config valid.RepoCfg) error { diff --git a/server/events/yaml/parser_validator_test.go b/server/events/yaml/parser_validator_test.go index 48f7dff68..ae332636f 100644 --- a/server/events/yaml/parser_validator_test.go +++ b/server/events/yaml/parser_validator_test.go @@ -33,6 +33,17 @@ func TestHasRepoCfg_FileDoesNotExist(t *testing.T) { Equals(t, false, exists) } +func TestHasRepoCfg_InvalidFileExtension(t *testing.T) { + tmpDir, cleanup := TempDir(t) + defer cleanup() + _, err := os.Create(filepath.Join(tmpDir, "atlantis.yml")) + Ok(t, err) + + r := yaml.ParserValidator{} + _, err = r.HasRepoCfg(tmpDir) + ErrContains(t, "found \"atlantis.yml\" as config file; rename using the .yaml extension - \"atlantis.yaml\"", err) +} + func TestParseRepoCfg_DirDoesNotExist(t *testing.T) { r := yaml.ParserValidator{} _, err := r.ParseRepoCfg("/not/exist", globalCfg, "")