Skip to content
Permalink
Browse files

Moved basic checks to a YAML config file.

  • Loading branch information...
artob committed Apr 23, 2019
1 parent 3d4a7f0 commit 8d7d382a069a6312087f1355a95c452e91320b60
Showing with 71 additions and 19 deletions.
  1. +32 −0 config.yml
  2. +38 −19 drycop/cmd/check.go
  3. +1 −0 drycop/cmd/root.go
@@ -0,0 +1,32 @@
output: text
check:
dirs:
- .git
files:
# TODO: .travis.yml?
# TODO: README symlink?
- file: .gitignore
- file: AUTHORS
- file: CHANGES.rst
markup: rst
- file: CHANGELOG.md
markup: md
builder: Pub
- file: CHANGES.md
markup: md
builder: "!Pub"
- file: CREDITS.rst
markup: rst
- file: CREDITS.md
markup: md
- file: Makefile
- file: README.rst
markup: rst
- file: README.md
markup: md
- file: TODO.rst
markup: rst
- file: TODO.md
markup: md
- file: UNLICENSE
- file: VERSION
@@ -8,8 +8,20 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/dryproject/drycop/drycop/enum"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

type File struct {
File string `mapstructure:"file"`
Markup string `mapstructure:"markup"`
Builder string `mapstructure:"builder"`
}

type Config struct {
Dirs []string `mapstructure:"dirs"`
Files []File `mapstructure:"files"`
}

// CheckCmd describes and implements the `drycop check` command
var CheckCmd = &cobra.Command{
Use: "check [dir...]",
@@ -84,28 +96,30 @@ func checkProject(projectDir string) bool {

ok := true

ok = checkDirExists(logger, projectDir, ".git") && ok
ok = checkFileExists(logger, projectDir, ".gitignore") && ok
// TODO: .travis.yml?
ok = checkFileExists(logger, projectDir, "AUTHORS") && ok
switch markup {
case "rst": // reStructuredText
ok = checkFileExists(logger, projectDir, "CHANGES.rst") && ok
case "md": // Markdown
switch builder {
case enum.DartPub:
ok = checkFileExists(logger, projectDir, "CHANGELOG.md") && ok
var config Config
err := viper.UnmarshalKey("check", &config)
if err != nil {
logger.WithError(err).Errorf("Invalid configuration")
return false
}

for _, expectedDir := range config.Dirs {
ok = checkDirExists(logger, projectDir, expectedDir) && ok
}

for _, expectedFile := range config.Files {
switch expectedFile.Markup {
case "", markup:
switch expectedFile.Builder {
case "", builder.String(): // TODO: support negation filters
ok = checkFileExists(logger, projectDir, expectedFile.File) && ok
default:
// ignore the file
}
default:
ok = checkFileExists(logger, projectDir, "CHANGES.md") && ok
// ignore the file
}
}
ok = checkFileExists(logger, projectDir, "CREDITS."+markup) && ok
ok = checkFileExists(logger, projectDir, "Makefile") && ok
// TODO: README symlink?
ok = checkFileExists(logger, projectDir, "README."+markup) && ok
ok = checkFileExists(logger, projectDir, "TODO."+markup) && ok
ok = checkFileExists(logger, projectDir, "UNLICENSE") && ok
ok = checkFileExists(logger, projectDir, "VERSION") && ok

switch language {
case enum.C:
@@ -144,5 +158,10 @@ func checkProject(projectDir string) bool {
// TODO: check file checksums
// TODO: check change log

if ok {
logger.Infof("Checked project: OK")
} else {
logger.Warnf("Checked project: some issues")
}
return ok
}
@@ -51,6 +51,7 @@ func initConfig() {
} else {
// Search for config file in the current directory and under the home directory:
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("$HOME/.drycop")
viper.AddConfigPath(fmt.Sprintf("%s/src/%s", build.Default.GOPATH, "github.com/dryproject/drycop"))

0 comments on commit 8d7d382

Please sign in to comment.
You can’t perform that action at this time.