enable score results by default (#788)

* enable v2

* linnter
This commit is contained in:
laurentsimon 2021-07-30 08:21:09 -07:00 committed by GitHub
parent 29594d4294
commit 577061b5e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 87 deletions

View File

@ -67,11 +67,6 @@ or ./scorecard --{npm,pypi,rubgems}=<package_name> [--checks=check1,...] [--show
Short: "Security Scorecards",
Long: "A program that shows security scorecard for an open source software.",
Run: func(cmd *cobra.Command, args []string) {
// UPGRADEv2: to remove.
_, v2 := os.LookupEnv("SCORECARD_V2")
if v2 {
fmt.Printf("*** USING v2 MIGRATION CODE ***\n\n")
}
cfg := zap.NewProductionConfig()
cfg.Level.SetLevel(*logLevel)
logger, err := cfg.Build()
@ -160,14 +155,10 @@ or ./scorecard --{npm,pypi,rubgems}=<package_name> [--checks=check1,...] [--show
fmt.Println("\nRESULTS\n-------")
}
// UPGRADEv2: support CSV/JSON.
switch format {
case formatDefault:
// UPGRADEv2: to remove.
if v2 {
err = repoResult.AsString2(showDetails, *logLevel, os.Stdout)
} else {
err = repoResult.AsString(showDetails, *logLevel, os.Stdout)
}
err = repoResult.AsString(showDetails, *logLevel, os.Stdout)
case formatCSV:
err = repoResult.AsCSV(showDetails, *logLevel, os.Stdout)
case formatJSON:

View File

@ -20,7 +20,6 @@ import (
"fmt"
"io"
"os"
"sort"
"strconv"
"strings"
@ -94,77 +93,10 @@ func (r *ScorecardResult) AsCSV(showDetails bool, logLevel zapcore.Level, writer
return nil
}
// UPGRADEv2: will be removed.
func (r *ScorecardResult) AsString(showDetails bool, logLevel zapcore.Level, writer io.Writer) error {
sortedChecks := make([]checker.CheckResult, len(r.Checks))
//nolint
for i, checkResult := range r.Checks {
sortedChecks[i] = checkResult
}
sort.Slice(sortedChecks, func(i, j int) bool {
if sortedChecks[i].Pass == sortedChecks[j].Pass {
return sortedChecks[i].Name < sortedChecks[j].Name
}
return sortedChecks[i].Pass
})
data := make([][]string, len(sortedChecks))
//nolint
for i, row := range sortedChecks {
const withdetails = 4
const withoutdetails = 3
var x []string
if showDetails {
x = make([]string, withdetails)
} else {
x = make([]string, withoutdetails)
}
x[0] = displayResult(row.Pass)
x[1] = strconv.Itoa(row.Confidence)
x[2] = row.Name
if showDetails {
//nolint
if row.Version == 2 {
details, show := detailsToString(row.Details2, logLevel)
if show {
x[3] = details
}
} else {
x[3] = strings.Join(row.Details, "\n")
}
}
data[i] = x
}
fmt.Fprintf(writer, "Repo: %s\n", r.Repo)
table := tablewriter.NewWriter(os.Stdout)
header := []string{"Status", "Confidence", "Name"}
if showDetails {
header = append(header, "Details")
}
table.SetHeader(header)
table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: true})
table.SetRowSeparator("-")
table.SetRowLine(true)
table.SetCenterSeparator("|")
table.AppendBulk(data)
table.Render()
return nil
}
// UPGRADEv2: new code.
func (r *ScorecardResult) AsString2(showDetails bool, logLevel zapcore.Level, writer io.Writer) error {
data := make([][]string, len(r.Checks))
//nolint
// UPGRADEv2: not needed after upgrade.
for i, row := range r.Checks {
//nolint
if row.Version != 2 {
continue
}
const withdetails = 5
const withoutdetails = 4
var x []string
@ -243,11 +175,3 @@ func typeToString(cd checker.DetailType) string {
return "Debug"
}
}
// UPGRADEv2: not needed after upgrade.
func displayResult(result bool) string {
if result {
return "Pass"
}
return "Fail"
}