mirror of
https://github.com/gojp/goreportcard.git
synced 2026-01-28 22:39:05 +08:00
#40 start license check
This commit is contained in:
38
check/license.go
Normal file
38
check/license.go
Normal file
@@ -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."
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user