Commit 980e3544 authored by Darrell Kienzle's avatar Darrell Kienzle Committed by Faho Shubladze
Browse files

remove unneeded goreportcard file. clean up go.mod and modules.txt

cr: https://code.amazon.com/reviews/CR-56027844
parent 8de23f64
package handlers
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
"github.com/boltdb/bolt"
"github.com/gojp/goreportcard/check"
)
func dirName(repo string) string {
return fmt.Sprintf("repos/src/%s", repo)
}
func getFromCache(repo string) (checksResp, error) {
// try and fetch from boltdb
db, err := bolt.Open(DBPath, 0600, &bolt.Options{Timeout: 1 * time.Second})
if err != nil {
return checksResp{}, fmt.Errorf("failed to open bolt database during GET: %v", err)
}
defer db.Close()
resp := checksResp{}
err = db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(RepoBucket))
if b == nil {
return errors.New("No repo bucket")
}
cached := b.Get([]byte(repo))
if cached == nil {
return fmt.Errorf("%q not found in cache", repo)
}
err = json.Unmarshal(cached, &resp)
if err != nil {
return fmt.Errorf("failed to parse JSON for %q in cache", repo)
}
return nil
})
if err != nil {
return resp, err
}
resp.LastRefresh = resp.LastRefresh.UTC()
return resp, nil
}
type score struct {
Name string `json:"name"`
Description string `json:"description"`
FileSummaries []check.FileSummary `json:"file_summaries"`
Weight float64 `json:"weight"`
Percentage float64 `json:"percentage"`
}
type checksResp struct {
Checks []score `json:"checks"`
Average float64 `json:"average"`
Grade Grade `json:"grade"`
Files int `json:"files"`
Issues int `json:"issues"`
Repo string `json:"repo"`
LastRefresh time.Time `json:"last_refresh"`
}
func goGet(repo string, firstAttempt bool) error {
log.Printf("Go getting %q...", repo)
if err := os.Mkdir("repos", 0755); err != nil && !os.IsExist(err) {
return fmt.Errorf("could not create dir: %v", err)
}
d, err := filepath.Abs("repos")
if err != nil {
return fmt.Errorf("could not fetch absolute path: %v", err)
}
os.Setenv("GOPATH", d)
cmd := exec.Command("go", "get", "-d", "-u", repo)
cmd.Stdout = os.Stdout
stderr, err := cmd.StderrPipe()
if err != nil {
return fmt.Errorf("could not get stderr pipe: %v", err)
}
err = cmd.Start()
if err != nil {
return fmt.Errorf("could not start command: %v", err)
}
b, err := ioutil.ReadAll(stderr)
if err != nil {
return fmt.Errorf("could not read stderr: %v", err)
}
err = cmd.Wait()
// we don't care if there are no buildable Go source files, we just need the source on disk
if err != nil && !strings.Contains(string(b), "no buildable Go source files") {
log.Println("Go get error log:", string(b))
if firstAttempt {
// try one more time, this time deleting the cached directory first,
// in case our cache is stale (remote repository was force-pushed, replaced, etc)
err = os.RemoveAll(filepath.Join(d, "src", repo))
if err != nil {
return fmt.Errorf("could not delete repo: %v", err)
}
return goGet(repo, false)
}
return fmt.Errorf("could not run go get: %v", err)
}
return nil
}
func newChecksResp(repo string, forceRefresh bool) (checksResp, error) {
if !forceRefresh {
resp, err := getFromCache(repo)
if err != nil {
// just log the error and continue
log.Println(err)
} else {
resp.Grade = grade(resp.Average * 100) // grade is not stored for some repos, yet
return resp, nil
}
}
// fetch the repo and grade it
dir := dirName(repo)
err := goGet(repo, false)
if err != nil {
// Cannot download github package
// Search the package on local
isExist, _ := exists(dir)
if !isExist {
return checksResp{}, fmt.Errorf("could not clone repo: %v", err)
}
}
filenames, err := check.GoFiles(dir)
if err != nil {
return checksResp{}, fmt.Errorf("could not get filenames: %v", err)
}
if len(filenames) == 0 {
return checksResp{}, fmt.Errorf("no .go files found")
}
checks := []check.Check{
check.GoFmt{Dir: dir, Filenames: filenames},
check.GoVet{Dir: dir, Filenames: filenames},
check.GoLint{Dir: dir, Filenames: filenames},
check.GoCyclo{Dir: dir, Filenames: filenames},
check.License{Dir: dir, Filenames: []string{}},
check.Misspell{Dir: dir, Filenames: filenames},
}
ch := make(chan score)
for _, c := range checks {
go func(c check.Check) {
p, summaries, err := c.Percentage()
if err != nil {
log.Printf("ERROR: (%s) %v", c.Name(), err)
}
s := score{
Name: c.Name(),
Description: c.Description(),
FileSummaries: summaries,
Weight: c.Weight(),
Percentage: p,
}
ch <- s
}(c)
}
resp := checksResp{Repo: repo,
Files: len(filenames),
LastRefresh: time.Now().UTC()}
var total float64
var issues = make(map[string]bool)
for i := 0; i < len(checks); i++ {
s := <-ch
resp.Checks = append(resp.Checks, s)
total += s.Percentage * s.Weight
for _, fs := range s.FileSummaries {
issues[fs.Filename] = true
}
}
resp.Average = total
resp.Issues = len(issues)
resp.Grade = grade(total * 100)
return resp, nil
}
func exists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return true, err
}
...@@ -10,7 +10,6 @@ require ( ...@@ -10,7 +10,6 @@ require (
github.com/Jeffail/gabs v1.0.0 github.com/Jeffail/gabs v1.0.0
github.com/Workiva/go-datastructures v1.0.53 github.com/Workiva/go-datastructures v1.0.53
github.com/aws/aws-sdk-go v1.35.23 github.com/aws/aws-sdk-go v1.35.23
github.com/boltdb/bolt v1.3.1
github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82 github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82
github.com/cenkalti/backoff/v4 v4.0.2 github.com/cenkalti/backoff/v4 v4.0.2
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575
...@@ -19,7 +18,6 @@ require ( ...@@ -19,7 +18,6 @@ require (
github.com/fsnotify/fsnotify v1.4.7 github.com/fsnotify/fsnotify v1.4.7
github.com/go-git/go-billy/v5 v5.3.0 // indirect github.com/go-git/go-billy/v5 v5.3.0 // indirect
github.com/go-git/go-git/v5 v5.3.0 github.com/go-git/go-git/v5 v5.3.0
github.com/gojp/goreportcard v0.0.0-20210509005623-09fa9206097e
github.com/google/go-github v0.0.0-20170604025028-a117bb2595a5 // this corresponds to v8 github.com/google/go-github v0.0.0-20170604025028-a117bb2595a5 // this corresponds to v8
github.com/google/go-querystring v1.0.0 // indirect github.com/google/go-querystring v1.0.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
...@@ -29,7 +27,6 @@ require ( ...@@ -29,7 +27,6 @@ require (
github.com/mitchellh/go-ps v1.0.0 github.com/mitchellh/go-ps v1.0.0
github.com/nightlyone/lockfile v0.0.0 github.com/nightlyone/lockfile v0.0.0
github.com/pborman/ansi v1.0.0 github.com/pborman/ansi v1.0.0
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
github.com/twinj/uuid v0.0.0-20151029044442-89173bcdda19 // Don't update -- breaks github.com/twinj/uuid v0.0.0-20151029044442-89173bcdda19 // Don't update -- breaks
github.com/xtaci/smux v1.5.15 github.com/xtaci/smux v1.5.15
......
This diff is collapsed.
...@@ -448,7 +448,3 @@ lint-all: copy-package-dep ...@@ -448,7 +448,3 @@ lint-all: copy-package-dep
# if you want to configure what linters are run, edit .golangci.yml # if you want to configure what linters are run, edit .golangci.yml
# if you want to restrict to some specific package edit Tools/src/run_golangci-lint.sh # if you want to restrict to some specific package edit Tools/src/run_golangci-lint.sh
$(GO_SPACE)/Tools/src/run_golangci-lint.sh $(GO_SPACE)/Tools/src/run_golangci-lint.sh
.PHONY: gen-report
gen-report:
$(GO_SPACE)/Tools/src/gen-report.sh
\ No newline at end of file
...@@ -70,9 +70,6 @@ github.com/aws/aws-sdk-go/service/ssmmds/ssmmdsiface ...@@ -70,9 +70,6 @@ github.com/aws/aws-sdk-go/service/ssmmds/ssmmdsiface
github.com/aws/aws-sdk-go/service/ssmmds/ssmmdsiface/mocks github.com/aws/aws-sdk-go/service/ssmmds/ssmmdsiface/mocks
github.com/aws/aws-sdk-go/service/sts github.com/aws/aws-sdk-go/service/sts
github.com/aws/aws-sdk-go/service/sts/stsiface github.com/aws/aws-sdk-go/service/sts/stsiface
# github.com/boltdb/bolt v1.3.1
## explicit
github.com/boltdb/bolt
# github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82 # github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82
## explicit ## explicit
github.com/carlescere/scheduler github.com/carlescere/scheduler
...@@ -161,11 +158,6 @@ github.com/go-git/go-git/v5/utils/merkletrie/filesystem ...@@ -161,11 +158,6 @@ github.com/go-git/go-git/v5/utils/merkletrie/filesystem
github.com/go-git/go-git/v5/utils/merkletrie/index github.com/go-git/go-git/v5/utils/merkletrie/index
github.com/go-git/go-git/v5/utils/merkletrie/internal/frame github.com/go-git/go-git/v5/utils/merkletrie/internal/frame
github.com/go-git/go-git/v5/utils/merkletrie/noder github.com/go-git/go-git/v5/utils/merkletrie/noder
# github.com/gojp/goreportcard v0.0.0-20210509005623-09fa9206097e
## explicit
github.com/gojp/goreportcard/check
# github.com/golang/protobuf v1.5.2
github.com/golang/protobuf/proto
# github.com/google/go-github v0.0.0-20170604025028-a117bb2595a5 # github.com/google/go-github v0.0.0-20170604025028-a117bb2595a5
## explicit ## explicit
github.com/google/go-github/github github.com/google/go-github/github
...@@ -208,8 +200,6 @@ github.com/pborman/ansi ...@@ -208,8 +200,6 @@ github.com/pborman/ansi
github.com/pmezard/go-difflib/difflib github.com/pmezard/go-difflib/difflib
# github.com/sergi/go-diff v1.1.0 # github.com/sergi/go-diff v1.1.0
github.com/sergi/go-diff/diffmatchpatch github.com/sergi/go-diff/diffmatchpatch
# github.com/smartystreets/goconvey v1.6.4
## explicit
# github.com/stretchr/objx v0.1.1 # github.com/stretchr/objx v0.1.1
github.com/stretchr/objx github.com/stretchr/objx
# github.com/stretchr/testify v1.7.0 # github.com/stretchr/testify v1.7.0
...@@ -279,54 +269,11 @@ golang.org/x/sys/windows ...@@ -279,54 +269,11 @@ golang.org/x/sys/windows
golang.org/x/sys/windows/registry golang.org/x/sys/windows/registry
golang.org/x/sys/windows/svc golang.org/x/sys/windows/svc
golang.org/x/sys/windows/svc/mgr golang.org/x/sys/windows/svc/mgr
# google.golang.org/appengine v1.6.6
google.golang.org/appengine
google.golang.org/appengine/internal
google.golang.org/appengine/internal/app_identity
google.golang.org/appengine/internal/base
google.golang.org/appengine/internal/datastore
google.golang.org/appengine/internal/log
google.golang.org/appengine/internal/modules
google.golang.org/appengine/internal/remote_api
google.golang.org/appengine/internal/urlfetch
google.golang.org/appengine/urlfetch
# google.golang.org/protobuf v1.26.0
google.golang.org/protobuf/encoding/prototext
google.golang.org/protobuf/encoding/protowire
google.golang.org/protobuf/internal/descfmt
google.golang.org/protobuf/internal/descopts
google.golang.org/protobuf/internal/detrand
google.golang.org/protobuf/internal/encoding/defval
google.golang.org/protobuf/internal/encoding/messageset
google.golang.org/protobuf/internal/encoding/tag
google.golang.org/protobuf/internal/encoding/text
google.golang.org/protobuf/internal/errors
google.golang.org/protobuf/internal/filedesc
google.golang.org/protobuf/internal/filetype
google.golang.org/protobuf/internal/flags
google.golang.org/protobuf/internal/genid
google.golang.org/protobuf/internal/impl
google.golang.org/protobuf/internal/order
google.golang.org/protobuf/internal/pragma
google.golang.org/protobuf/internal/set
google.golang.org/protobuf/internal/strs
google.golang.org/protobuf/internal/version
google.golang.org/protobuf/proto
google.golang.org/protobuf/reflect/protodesc
google.golang.org/protobuf/reflect/protoreflect
google.golang.org/protobuf/reflect/protoregistry
google.golang.org/protobuf/runtime/protoiface
google.golang.org/protobuf/runtime/protoimpl
google.golang.org/protobuf/types/descriptorpb
# gopkg.in/ini.v1 v1.62.0 # gopkg.in/ini.v1 v1.62.0
## explicit ## explicit
gopkg.in/ini.v1 gopkg.in/ini.v1
# gopkg.in/warnings.v0 v0.1.2
gopkg.in/warnings.v0
# gopkg.in/yaml.v2 v2.3.0 # gopkg.in/yaml.v2 v2.3.0
## explicit ## explicit
gopkg.in/yaml.v2 gopkg.in/yaml.v2
# gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
gopkg.in/yaml.v3
# github.com/aws/aws-sdk-go => ./extra/aws-sdk-go # github.com/aws/aws-sdk-go => ./extra/aws-sdk-go
# github.com/nightlyone/lockfile => ./extra/lockfile # github.com/nightlyone/lockfile => ./extra/lockfile
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment