starting config parsing

This commit is contained in:
Tyrel Souza 2019-05-14 23:19:10 -04:00 committed by Tyrel Souza
parent 5c617cb37c
commit 3b3f0f5621
No known key found for this signature in database
GPG Key ID: 5A9394D4C30AEAC0
5 changed files with 49 additions and 1 deletions

1
go.sum
View File

@ -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 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= 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/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= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@ -83,6 +83,12 @@ func verify(directory string) error {
if !verifyTideliftYamlExists(directory) { if !verifyTideliftYamlExists(directory) {
return cli.NewExitError("no .tidelift.yml at supplied directory path", 6) 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 return nil
} }

View File

@ -0,0 +1 @@
team-name: only Team

View File

@ -1,2 +1,2 @@
team-name: tidelift team-name: tidelift
repo-name: fake repository-name: fake

View File

@ -1,7 +1,11 @@
package main package main
import ( import (
"io/ioutil"
"os" "os"
"path/filepath"
"gopkg.in/yaml.v2"
) )
func verifyTideliftYamlExists(directory string) bool { func verifyTideliftYamlExists(directory string) bool {
@ -12,3 +16,39 @@ func verifyTideliftYamlExists(directory string) bool {
return false 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)
}
}