:warn: Remove the old Details field from CheckResult (#1906)

https://github.com/ossf/scorecard/issues/1393

Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
This commit is contained in:
Naveen 2022-05-12 14:58:12 -05:00 committed by GitHub
parent b9f333bc2a
commit 0275a94a3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 55 additions and 63 deletions

View File

@ -66,17 +66,12 @@ const (
// CheckResult captures result from a check run.
// nolint:govet
type CheckResult struct {
// TODO(#1393): Remove old structure after deprecation.
Name string
Details []string
// UPGRADEv2: New structure. Omitting unchanged Name field
// for simplicity.
Version int `json:"-"` // Default value of 0 indicates old structure.
Error error `json:"-"` // Runtime error indicate a filure to run the check.
Details2 []CheckDetail `json:"-"` // Details of tests and sub-checks
Score int `json:"-"` // {[-1,0...10], -1 = Inconclusive}
Reason string `json:"-"` // A sentence describing the check result (score, etc)
Version int
Error error
Details []CheckDetail
Score int
Reason string
}
// Remediation represents a remediation.

View File

@ -120,10 +120,7 @@ func (r *Runner) Run(ctx context.Context, c Check) CheckResult {
// Set details.
// TODO(#1393): Remove.
res.Details2 = l.Flush()
for _, d := range res.Details2 {
res.Details = append(res.Details, d.Msg.Text)
}
res.Details = l.Flush()
if err := logStats(ctx, startTime, &res); err != nil {
panic(err)

View File

@ -99,8 +99,8 @@ func AsJSON(r *pkg.ScorecardResult, showDetails bool, logLevel log.Level, writer
Name: checkResult.Name,
}
if showDetails {
for i := range checkResult.Details2 {
d := checkResult.Details2[i]
for i := range checkResult.Details {
d := checkResult.Details[i]
m := pkg.DetailToString(&d, logLevel)
if m == "" {
continue
@ -159,8 +159,8 @@ func AsJSON2(r *pkg.ScorecardResult, showDetails bool,
Score: checkResult.Score,
}
if showDetails {
for i := range checkResult.Details2 {
d := checkResult.Details2[i]
for i := range checkResult.Details {
d := checkResult.Details[i]
m := pkg.DetailToString(&d, logLevel)
if m == "" {
continue

View File

@ -104,7 +104,7 @@ func TestJSONOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -141,7 +141,7 @@ func TestJSONOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -177,7 +177,7 @@ func TestJSONOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -193,7 +193,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -210,7 +210,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name2",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailInfo,
Msg: checker.LogMessage{
@ -267,7 +267,7 @@ func TestJSONOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -283,7 +283,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -300,7 +300,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name2",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailInfo,
Msg: checker.LogMessage{
@ -357,7 +357,7 @@ func TestJSONOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -394,7 +394,7 @@ func TestJSONOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{

View File

@ -98,8 +98,8 @@ func (r *ScorecardResult) AsJSON(showDetails bool, logLevel log.Level, writer io
Name: checkResult.Name,
}
if showDetails {
for i := range checkResult.Details2 {
d := checkResult.Details2[i]
for i := range checkResult.Details {
d := checkResult.Details[i]
m := DetailToString(&d, logLevel)
if m == "" {
continue
@ -156,8 +156,8 @@ func (r *ScorecardResult) AsJSON2(showDetails bool,
Score: checkResult.Score,
}
if showDetails {
for i := range checkResult.Details2 {
d := checkResult.Details2[i]
for i := range checkResult.Details {
d := checkResult.Details[i]
m := DetailToString(&d, logLevel)
if m == "" {
continue

View File

@ -103,7 +103,7 @@ func TestJSONOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -140,7 +140,7 @@ func TestJSONOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -176,7 +176,7 @@ func TestJSONOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -192,7 +192,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -209,7 +209,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name2",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailInfo,
Msg: checker.LogMessage{
@ -266,7 +266,7 @@ func TestJSONOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -282,7 +282,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -299,7 +299,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name2",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailInfo,
Msg: checker.LogMessage{
@ -356,7 +356,7 @@ func TestJSONOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -393,7 +393,7 @@ func TestJSONOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{

View File

@ -532,7 +532,7 @@ func messageWithScore(msg string, score int) string {
}
func createDefaultLocationMessage(check *checker.CheckResult, score int) string {
details := filterOutDetailType(check.Details2, checker.DetailInfo)
details := filterOutDetailType(check.Details, checker.DetailInfo)
s, b := detailsToString(details, log.WarnLevel)
if b {
// Warning: GitHub UX needs a single `\n` to turn it into a `<br>`.
@ -608,7 +608,7 @@ func (r *ScorecardResult) AsSARIF(showDetails bool, logLevel log.Level,
// would change, and the result management system would erroneously report it as a new result."
// Create locations.
locs := detailsToLocations(check.Details2, showDetails, minScore, check.Score)
locs := detailsToLocations(check.Details, showDetails, minScore, check.Score)
// Add default location if no locations are present.
// Note: GitHub needs at least one location to show the results.

View File

@ -157,7 +157,7 @@ func TestSARIFOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -211,7 +211,7 @@ func TestSARIFOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -261,7 +261,7 @@ func TestSARIFOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -314,7 +314,7 @@ func TestSARIFOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -330,7 +330,7 @@ func TestSARIFOutput(t *testing.T) {
Name: "Check-Name",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -347,7 +347,7 @@ func TestSARIFOutput(t *testing.T) {
Name: "Check-Name2",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailInfo,
Msg: checker.LogMessage{
@ -421,7 +421,7 @@ func TestSARIFOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -437,7 +437,7 @@ func TestSARIFOutput(t *testing.T) {
Name: "Check-Name",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -454,7 +454,7 @@ func TestSARIFOutput(t *testing.T) {
Name: "Check-Name2",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailInfo,
Msg: checker.LogMessage{
@ -520,7 +520,7 @@ func TestSARIFOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -568,7 +568,7 @@ func TestSARIFOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -620,7 +620,7 @@ func TestSARIFOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -636,7 +636,7 @@ func TestSARIFOutput(t *testing.T) {
Name: "Check-Name",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -653,7 +653,7 @@ func TestSARIFOutput(t *testing.T) {
Name: "Check-Name2",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailInfo,
Msg: checker.LogMessage{
@ -731,7 +731,7 @@ func TestSARIFOutput(t *testing.T) {
Date: date,
Checks: []checker.CheckResult{
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -748,7 +748,7 @@ func TestSARIFOutput(t *testing.T) {
Name: "Check-Name4",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -775,7 +775,7 @@ func TestSARIFOutput(t *testing.T) {
Name: "Check-Name",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
@ -802,7 +802,7 @@ func TestSARIFOutput(t *testing.T) {
Name: "Check-Name5",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{

View File

@ -169,7 +169,7 @@ func (r *ScorecardResult) AsString(showDetails bool, logLevel log.Level,
x[1] = row.Name
x[2] = row.Reason
if showDetails {
details, show := detailsToString(row.Details2, logLevel)
details, show := detailsToString(row.Details, logLevel)
if show {
x[3] = details
}