diff --git a/go.sum b/go.sum index c77081e..6ef6af8 100644 --- a/go.sum +++ b/go.sum @@ -8,4 +8,5 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/main.go b/main.go index edc60cb..d4b5500 100644 --- a/main.go +++ b/main.go @@ -83,6 +83,12 @@ func verify(directory string) error { if !verifyTideliftYamlExists(directory) { return cli.NewExitError("no .tidelift.yml at supplied directory path", 6) } + missingKey := passesMinimumRequirements(directory) + if missingKey != "" { + errorMsg := fmt.Sprintf("Missing key '%s:' in .tidelift.yml", missingKey) + return cli.NewExitError(errorMsg, 7) + + } return nil } diff --git a/test/bad_config/.tidelift.yml b/test/bad_config/.tidelift.yml new file mode 100644 index 0000000..870ef2d --- /dev/null +++ b/test/bad_config/.tidelift.yml @@ -0,0 +1 @@ +team-name: only Team \ No newline at end of file diff --git a/test/fixtures/.tidelift.yml b/test/fixtures/.tidelift.yml index be17aa5..2c10a5d 100644 --- a/test/fixtures/.tidelift.yml +++ b/test/fixtures/.tidelift.yml @@ -1,2 +1,2 @@ team-name: tidelift -repo-name: fake +repository-name: fake diff --git a/tidelift_yml.go b/tidelift_yml.go index ae1aab7..462e871 100644 --- a/tidelift_yml.go +++ b/tidelift_yml.go @@ -1,7 +1,11 @@ package main import ( + "io/ioutil" "os" + "path/filepath" + + "gopkg.in/yaml.v2" ) func verifyTideliftYamlExists(directory string) bool { @@ -12,3 +16,39 @@ func verifyTideliftYamlExists(directory string) bool { return false } + +func passesMinimumRequirements(directory string) string { + os.Chdir(directory) + filename, _ := filepath.Abs("./.tidelift.yml") + + yamlFile, err := ioutil.ReadFile(filename) + check(err) + + type TideliftYML struct { + TeamName string `yaml:"team-name"` + RepositoryName string `yaml:"repository-name"` + } + + var yml TideliftYML + + err = yaml.Unmarshal(yamlFile, &yml) + check(err) + + // Check for Team name + if len(yml.TeamName) <= 0 { + return "team-name" + } + + // Check for Repository Name + if len(yml.RepositoryName) <= 0 { + return "repository-name" + } + + return "" +} + +func check(e error) { + if e != nil { + panic(e) + } +}