tideliftcli/tidelift_yml.go

72 lines
1.1 KiB
Go
Raw Normal View History

2019-05-15 02:40:51 +00:00
package main
import (
2019-05-15 03:54:04 +00:00
"fmt"
2019-05-15 03:19:10 +00:00
"io/ioutil"
2019-05-15 02:40:51 +00:00
"os"
2019-05-15 03:19:10 +00:00
"path/filepath"
"gopkg.in/yaml.v2"
2019-05-15 02:40:51 +00:00
)
2019-05-15 17:12:36 +00:00
type TideliftYML struct {
TeamName string `yaml:"team-name"`
RepositoryName string `yaml:"repository-name"`
}
2019-05-15 02:40:51 +00:00
func verifyTideliftYamlExists(directory string) bool {
2019-05-15 03:54:04 +00:00
filepath := fmt.Sprintf("%s/.tidelift.yml", directory)
if fileExists(filepath) {
2019-05-15 02:40:51 +00:00
return true
}
return false
}
2019-05-15 03:19:10 +00:00
2019-05-15 17:12:36 +00:00
func readTideliftYamlFile(directory string) []byte {
2019-05-15 03:55:45 +00:00
filename, _ := filepath.Abs(fmt.Sprintf("%s/.tidelift.yml", directory))
2019-05-15 03:19:10 +00:00
yamlFile, err := ioutil.ReadFile(filename)
2019-05-15 03:55:45 +00:00
2019-05-15 03:19:10 +00:00
check(err)
2019-05-15 17:12:36 +00:00
return yamlFile
}
2019-05-15 03:19:10 +00:00
2019-05-15 17:12:36 +00:00
func getKeysFromYaml(yamlText []byte) TideliftYML {
2019-05-15 03:19:10 +00:00
var yml TideliftYML
2019-05-15 17:12:36 +00:00
err := yaml.Unmarshal(yamlText, &yml)
2019-05-15 03:55:45 +00:00
2019-05-15 03:19:10 +00:00
check(err)
2019-05-15 17:12:36 +00:00
return yml
}
func passesMinimumRequirements(yamlText []byte) string {
yml := getKeysFromYaml(yamlText)
2019-05-15 03:19:10 +00:00
// 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 ""
}
2019-05-15 03:54:04 +00:00
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}