mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-11 08:55:27 +03:00
Fix - golangci issues gomnd, goconst
Fixed the golangci issues for gomnd and goconst. Added ginkgo dependency in the makefile.
This commit is contained in:
parent
f906f3f568
commit
554ca76bfe
1
.gitignore
vendored
1
.gitignore
vendored
@ -19,6 +19,7 @@ results.json
|
||||
# IDE directories.
|
||||
.vscode/
|
||||
*.iml
|
||||
.idea
|
||||
|
||||
# tools
|
||||
bin
|
||||
|
9
Makefile
9
Makefile
@ -1,4 +1,6 @@
|
||||
SHELL := /bin/bash
|
||||
GOBIN ?= $(GOPATH)/bin
|
||||
GINKGO ?= $(GOBIN)/ginkgo
|
||||
all: fmt tidy lint test
|
||||
build:
|
||||
CGO_ENABLED=0 go build -a -tags netgo -ldflags '-w -extldflags "-static"'
|
||||
@ -29,10 +31,11 @@ endif
|
||||
|
||||
.PHONY: e2e
|
||||
# export GITHUB_AUTH_TOKEN with personal access token to run the e2e
|
||||
e2e: build check-env
|
||||
ginkgo --skip="E2E TEST:executable" -p -v -cover ./...
|
||||
|
||||
e2e: build check-env ginkgo
|
||||
$(GINKGO) --skip="E2E TEST:executable" -p -v -cover ./...
|
||||
|
||||
ginkgo:
|
||||
GO111MODULE=off go get -u github.com/onsi/ginkgo/ginkgo
|
||||
.PHONY: ci-e2e
|
||||
# export GITHUB_AUTH_TOKEN with personal access token to run the e2e
|
||||
ci-e2e: build check-env
|
||||
|
@ -78,16 +78,17 @@ func ProportionalResult(numerator int, denominator int, threshold float32) Check
|
||||
}
|
||||
|
||||
actual := float32(numerator) / float32(denominator)
|
||||
const confidence = 10
|
||||
if actual >= threshold {
|
||||
return CheckResult{
|
||||
Pass: true,
|
||||
Confidence: int(actual * 10),
|
||||
Confidence: int(actual * confidence),
|
||||
}
|
||||
}
|
||||
|
||||
return CheckResult{
|
||||
Pass: false,
|
||||
Confidence: int(maxConfidence - int(actual*10)),
|
||||
Confidence: maxConfidence - int(actual*confidence),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,10 @@ func IsActive(c checker.Checker) checker.CheckResult {
|
||||
}
|
||||
}
|
||||
c.Logf("commits in last %d days: %d", lookbackDays, totalCommits)
|
||||
const numCommits = 2
|
||||
const confidence = 10
|
||||
return checker.CheckResult{
|
||||
Pass: totalCommits >= 2,
|
||||
Confidence: 10,
|
||||
Pass: totalCommits >= numCommits,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
|
@ -31,15 +31,17 @@ func BranchProtection(c checker.Checker) checker.CheckResult {
|
||||
|
||||
protection, resp, err := c.Client.Repositories.
|
||||
GetBranchProtection(c.Ctx, c.Owner, c.Repo, *repo.DefaultBranch)
|
||||
if resp.StatusCode == 404 {
|
||||
const fileNotFound = 404
|
||||
if resp.StatusCode == fileNotFound {
|
||||
return checker.RetryResult(err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.Logf("!! branch protection not enabled")
|
||||
const confidence = 10
|
||||
return checker.CheckResult{
|
||||
Pass: false,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
return IsBranchProtected(protection, c)
|
||||
|
@ -52,6 +52,7 @@ func CITests(c checker.Checker) checker.CheckResult {
|
||||
var foundCI bool
|
||||
|
||||
// Github Statuses
|
||||
const s = "success"
|
||||
if usedSystem <= githubStatuses {
|
||||
statuses, _, err := c.Client.Repositories.ListStatuses(c.Ctx, c.Owner, c.Repo, pr.GetHead().GetSHA(), &github.ListOptions{})
|
||||
if err != nil {
|
||||
@ -59,7 +60,7 @@ func CITests(c checker.Checker) checker.CheckResult {
|
||||
}
|
||||
|
||||
for _, status := range statuses {
|
||||
if status.GetState() != "success" {
|
||||
if status.GetState() != s {
|
||||
continue
|
||||
}
|
||||
if isTest(status.GetContext()) {
|
||||
@ -87,7 +88,7 @@ func CITests(c checker.Checker) checker.CheckResult {
|
||||
if cr.GetStatus() != "completed" {
|
||||
continue
|
||||
}
|
||||
if cr.GetConclusion() != "success" {
|
||||
if cr.GetConclusion() != s {
|
||||
continue
|
||||
}
|
||||
if isTest(cr.GetApp().GetSlug()) {
|
||||
|
@ -49,11 +49,12 @@ func CIIBestPractices(c checker.Checker) checker.CheckResult {
|
||||
return checker.RetryResult(err)
|
||||
}
|
||||
|
||||
const confidence = 10
|
||||
if len(parsedResponse) < 1 {
|
||||
c.Logf("no badge found")
|
||||
return checker.CheckResult{
|
||||
Pass: false,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,12 +64,12 @@ func CIIBestPractices(c checker.Checker) checker.CheckResult {
|
||||
if result.BadgeLevel != "" {
|
||||
return checker.CheckResult{
|
||||
Pass: true,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
|
||||
return checker.CheckResult{
|
||||
Pass: false,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
|
@ -108,9 +108,10 @@ func IsPrReviewRequired(c checker.Checker) checker.CheckResult {
|
||||
}
|
||||
if bp.GetRequiredPullRequestReviews().RequiredApprovingReviewCount >= 1 {
|
||||
c.Logf("pr review policy enforced")
|
||||
const confidence = 5
|
||||
return checker.CheckResult{
|
||||
Pass: true,
|
||||
Confidence: 5,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
return checker.InconclusiveResult
|
||||
|
@ -38,7 +38,9 @@ func Contributors(c checker.Checker) checker.CheckResult {
|
||||
|
||||
companies := map[string]struct{}{}
|
||||
for _, contrib := range contribs {
|
||||
if contrib.GetContributions() >= 5 {
|
||||
const contributorsCount = 5
|
||||
//nolint:nestif
|
||||
if contrib.GetContributions() >= contributorsCount {
|
||||
u, _, err := c.Client.Users.Get(c.Ctx, contrib.GetLogin())
|
||||
if err != nil {
|
||||
return checker.RetryResult(err)
|
||||
@ -82,14 +84,16 @@ func Contributors(c checker.Checker) checker.CheckResult {
|
||||
names = append(names, c)
|
||||
}
|
||||
c.Logf("companies found: %v", strings.Join(names, ","))
|
||||
if len(companies) >= 2 {
|
||||
const numContributors = 2
|
||||
const confidence = 10
|
||||
if len(companies) >= numContributors {
|
||||
return checker.CheckResult{
|
||||
Pass: true,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
return checker.CheckResult{
|
||||
Pass: false,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ func init() {
|
||||
}
|
||||
|
||||
var passResult = checker.CheckResult{
|
||||
Pass: true,
|
||||
Pass: true,
|
||||
//nolint:gomnd
|
||||
Confidence: 10,
|
||||
}
|
||||
|
||||
@ -63,8 +64,9 @@ func FrozenDeps(c checker.Checker) checker.CheckResult {
|
||||
}
|
||||
|
||||
// Strip the repo name
|
||||
names := strings.SplitN(hdr.Name, "/", 2)
|
||||
if len(names) < 2 {
|
||||
const splitLength = 2
|
||||
names := strings.SplitN(hdr.Name, "/", splitLength)
|
||||
if len(names) < splitLength {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -97,8 +99,9 @@ func FrozenDeps(c checker.Checker) checker.CheckResult {
|
||||
return passResult
|
||||
}
|
||||
}
|
||||
const confidence = 5
|
||||
return checker.CheckResult{
|
||||
Pass: false,
|
||||
Confidence: 5,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
|
@ -33,16 +33,17 @@ func Fuzzing(c checker.Checker) checker.CheckResult {
|
||||
return checker.RetryResult(err)
|
||||
}
|
||||
|
||||
const confidence = 10
|
||||
if *results.Total > 0 {
|
||||
c.Logf("found project in OSS-Fuzz")
|
||||
return checker.CheckResult{
|
||||
Pass: true,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
|
||||
return checker.CheckResult{
|
||||
Pass: false,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ func Packaging(c checker.Checker) checker.CheckResult {
|
||||
return checker.RetryResult(err)
|
||||
}
|
||||
|
||||
const confidence = 10
|
||||
for _, f := range dc {
|
||||
fp := f.GetPath()
|
||||
fo, _, _, err := c.Client.Repositories.GetContents(c.Ctx, c.Owner, c.Repo, fp, &github.RepositoryContentGetOptions{})
|
||||
@ -62,7 +63,7 @@ func Packaging(c checker.Checker) checker.CheckResult {
|
||||
c.Logf("found a completed run: %s", runs.WorkflowRuns[0].GetHTMLURL())
|
||||
return checker.CheckResult{
|
||||
Pass: true,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
c.Logf("!! no run completed")
|
||||
@ -70,7 +71,7 @@ func Packaging(c checker.Checker) checker.CheckResult {
|
||||
|
||||
return checker.CheckResult{
|
||||
Pass: false,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,8 +85,9 @@ func CodeQLInCheckDefinitions(c checker.Checker) checker.CheckResult {
|
||||
c.Logf("found CodeQL definition: %s", result.GetPath())
|
||||
}
|
||||
|
||||
const confidence = 10
|
||||
return checker.CheckResult{
|
||||
Pass: *results.Total > 0,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ func init() {
|
||||
|
||||
func SecurityPolicy(c checker.Checker) checker.CheckResult {
|
||||
// check repository for repository-specific policy
|
||||
const confidence = 10
|
||||
for _, securityFile := range []string{"SECURITY.md", "SECURITY.MD", "security.md", "security.MD"} {
|
||||
for _, dirs := range []string{"", ".github", "docs"} {
|
||||
fp := path.Join(dirs, securityFile)
|
||||
@ -38,7 +39,7 @@ func SecurityPolicy(c checker.Checker) checker.CheckResult {
|
||||
c.Logf("security policy found: %s", fp)
|
||||
return checker.CheckResult{
|
||||
Pass: true,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,13 +50,13 @@ func SecurityPolicy(c checker.Checker) checker.CheckResult {
|
||||
c.Logf("security policy found (default community health file): %s", securityFile)
|
||||
return checker.CheckResult{
|
||||
Pass: true,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
}
|
||||
// policy wasn't found, return failure case
|
||||
return checker.CheckResult{
|
||||
Pass: false,
|
||||
Confidence: 10,
|
||||
Confidence: confidence,
|
||||
}
|
||||
}
|
||||
|
@ -228,8 +228,9 @@ func displayResult(result bool) string {
|
||||
// Gets the GitHub repository URL for the npm package
|
||||
func fetchGitRepoistoryFromNPM(packageName string) (string, error) {
|
||||
npmsearchURL := "https://registry.npmjs.org/-/v1/search?text=%s&size=1"
|
||||
const timeout = 10
|
||||
client := &http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
Timeout: timeout * time.Second,
|
||||
}
|
||||
resp, err := client.Get(fmt.Sprintf(npmsearchURL, packageName))
|
||||
|
||||
|
@ -52,8 +52,9 @@ var serveCmd = &cobra.Command{
|
||||
|
||||
http.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
|
||||
repoParam := r.URL.Query().Get("repo")
|
||||
s := strings.SplitN(repoParam, "/", 3)
|
||||
if len(s) != 3 {
|
||||
const length = 3
|
||||
s := strings.SplitN(repoParam, "/", length)
|
||||
if len(s) != length {
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
repo := pkg.RepoURL{}
|
||||
|
@ -58,8 +58,9 @@ func (r *RepoURL) Set(s string) error {
|
||||
return e
|
||||
}
|
||||
|
||||
split := strings.SplitN(strings.Trim(u.Path, "/"), "/", 2)
|
||||
if len(split) != 2 {
|
||||
const splitLen = 2
|
||||
split := strings.SplitN(strings.Trim(u.Path, "/"), "/", splitLen)
|
||||
if len(split) != splitLen {
|
||||
log.Fatalf("invalid repo flag: [%s], pass the full repository URL", s)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user