Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ Remove the old Details field from CheckResult #1906

Merged
merged 1 commit into from May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 5 additions & 10 deletions checker/check_result.go
Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions checker/check_runner.go
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions cron/format/json.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions cron/format/json_test.go
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -193,7 +193,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
Expand All @@ -210,7 +210,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name2",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailInfo,
Msg: checker.LogMessage{
Expand Down Expand Up @@ -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{
Expand All @@ -283,7 +283,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
Expand All @@ -300,7 +300,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name2",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailInfo,
Msg: checker.LogMessage{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions pkg/json.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions pkg/json_test.go
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -192,7 +192,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
Expand All @@ -209,7 +209,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name2",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailInfo,
Msg: checker.LogMessage{
Expand Down Expand Up @@ -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{
Expand All @@ -282,7 +282,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailWarn,
Msg: checker.LogMessage{
Expand All @@ -299,7 +299,7 @@ func TestJSONOutput(t *testing.T) {
Name: "Check-Name2",
},
{
Details2: []checker.CheckDetail{
Details: []checker.CheckDetail{
{
Type: checker.DetailInfo,
Msg: checker.LogMessage{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions pkg/sarif.go
Expand Up @@ -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>`.
Expand Down Expand Up @@ -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.
Expand Down