starting config parsing
This commit is contained in:
parent
5c617cb37c
commit
3b3f0f5621
1
go.sum
1
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=
|
||||
|
6
main.go
6
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
|
||||
}
|
||||
|
1
test/bad_config/.tidelift.yml
Normal file
1
test/bad_config/.tidelift.yml
Normal file
@ -0,0 +1 @@
|
||||
team-name: only Team
|
2
test/fixtures/.tidelift.yml
vendored
2
test/fixtures/.tidelift.yml
vendored
@ -1,2 +1,2 @@
|
||||
team-name: tidelift
|
||||
repo-name: fake
|
||||
repository-name: fake
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user