diff --git a/check/license.go b/check/license.go new file mode 100644 index 0000000..d48b93b --- /dev/null +++ b/check/license.go @@ -0,0 +1,38 @@ +package check + +import ( + "bytes" + "os/exec" +) + +// License is the check for the go cyclo command +type License struct { + Dir string + Filenames []string +} + +// Name returns the name of the display name of the command +func (g License) Name() string { + return "license" +} + +// Percentage returns 0 if no LICENSE, 100 if LICENSE +func (g License) Percentage() (float64, []FileSummary, error) { + cmd := exec.Command("find", g.Dir, "-maxdepth", "1", "-type", "f", "-name", "LICENSE") + var out bytes.Buffer + cmd.Stdout = &out + err := cmd.Run() + if err != nil { + return 0.0, []FileSummary{}, err + } + if out.String() == "" { + return 0.0, []FileSummary{}, nil + } + + return 100.0, []FileSummary{}, nil +} + +// Description returns the description of License +func (g License) Description() string { + return "Checks whether your project has a LICENSE file." +} diff --git a/handlers/checks.go b/handlers/checks.go index 3b953a8..12fd518 100644 --- a/handlers/checks.go +++ b/handlers/checks.go @@ -132,6 +132,7 @@ func newChecksResp(repo string, forceRefresh bool) (checksResp, error) { check.GoVet{Dir: dir, Filenames: filenames}, check.GoLint{Dir: dir, Filenames: filenames}, check.GoCyclo{Dir: dir, Filenames: filenames}, + check.License{Dir: dir, Filenames: []string{}}, } ch := make(chan score)