mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-17 11:57:12 +03:00
⚠️ rename annotation IsExempted to Annotations (#4230)
Signed-off-by: Spencer Schrock <sschrock@google.com>
This commit is contained in:
parent
eb03180231
commit
59c4aa980f
@ -257,13 +257,15 @@ func LogFinding(dl DetailLogger, f *finding.Finding, level DetailType) {
|
||||
}
|
||||
}
|
||||
|
||||
// IsExempted verifies if a given check in the results is exempted in annotations.
|
||||
func (check *CheckResult) IsExempted(c config.Config) (bool, []string) {
|
||||
// Annotations returns the applicable annotations for a given configuration.
|
||||
// Any annotations on checks with a maximum score are assumed to be out of
|
||||
// date and skipped.
|
||||
func (check *CheckResult) Annotations(c config.Config) []string {
|
||||
// If check has a maximum score, then there it doesn't make sense anymore to reason the check
|
||||
// This may happen if the check score was once low but then the problem was fixed on Scorecard side
|
||||
// or on the maintainers side
|
||||
if check.Score == MaxResultScore {
|
||||
return false, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// Collect all annotation reasons for this check
|
||||
@ -282,6 +284,5 @@ func (check *CheckResult) IsExempted(c config.Config) (bool, []string) {
|
||||
}
|
||||
}
|
||||
|
||||
// A check is considered exempted if it has annotation reasons
|
||||
return (len(reasons) > 0), reasons
|
||||
return reasons
|
||||
}
|
||||
|
@ -811,15 +811,14 @@ func TestCreateRuntimeErrorResult(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsExempted(t *testing.T) {
|
||||
func TestAnnotations(t *testing.T) {
|
||||
t.Parallel()
|
||||
type args struct {
|
||||
check CheckResult
|
||||
config config.Config
|
||||
}
|
||||
type want struct {
|
||||
reasons []config.Reason
|
||||
isExempted bool
|
||||
reasons []config.Reason
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -845,7 +844,6 @@ func TestIsExempted(t *testing.T) {
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
isExempted: true,
|
||||
reasons: []config.Reason{
|
||||
config.TestData,
|
||||
},
|
||||
@ -875,9 +873,7 @@ func TestIsExempted(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
isExempted: false,
|
||||
},
|
||||
want: want{},
|
||||
},
|
||||
{
|
||||
name: "No checks exempted",
|
||||
@ -888,9 +884,7 @@ func TestIsExempted(t *testing.T) {
|
||||
},
|
||||
config: config.Config{},
|
||||
},
|
||||
want: want{
|
||||
isExempted: false,
|
||||
},
|
||||
want: want{},
|
||||
},
|
||||
{
|
||||
name: "Exemption is outdated",
|
||||
@ -910,9 +904,7 @@ func TestIsExempted(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
isExempted: false,
|
||||
},
|
||||
want: want{},
|
||||
},
|
||||
{
|
||||
name: "Multiple exemption reasons in a single annotation",
|
||||
@ -934,7 +926,6 @@ func TestIsExempted(t *testing.T) {
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
isExempted: true,
|
||||
reasons: []config.Reason{
|
||||
config.TestData,
|
||||
config.Remediated,
|
||||
@ -972,7 +963,6 @@ func TestIsExempted(t *testing.T) {
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
isExempted: true,
|
||||
reasons: []config.Reason{
|
||||
config.TestData,
|
||||
config.Remediated,
|
||||
@ -984,10 +974,7 @@ func TestIsExempted(t *testing.T) {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
isExempted, reasons := tt.args.check.IsExempted(tt.args.config)
|
||||
if isExempted != tt.want.isExempted {
|
||||
t.Fatalf("IsExempted() = %v, want %v", isExempted, tt.want.isExempted)
|
||||
}
|
||||
reasons := tt.args.check.Annotations(tt.args.config)
|
||||
wantReasons := []string{}
|
||||
if tt.want.reasons != nil {
|
||||
for _, r := range tt.want.reasons {
|
||||
|
@ -186,10 +186,7 @@ func (r *ScorecardResult) AsJSON2(writer io.Writer, checkDocs docs.Doc, opt *AsJ
|
||||
}
|
||||
}
|
||||
if opt.Annotations {
|
||||
exempted, reasons := checkResult.IsExempted(r.Config)
|
||||
if exempted {
|
||||
tmpResult.Annotations = reasons
|
||||
}
|
||||
tmpResult.Annotations = append(tmpResult.Annotations, checkResult.Annotations(r.Config)...)
|
||||
}
|
||||
out.Checks = append(out.Checks, tmpResult)
|
||||
}
|
||||
|
@ -671,7 +671,7 @@ func (r *ScorecardResult) AsSARIF(showDetails bool, logLevel log.Level,
|
||||
}
|
||||
|
||||
// Skip checks that are annotated
|
||||
if exempted, _ := check.IsExempted(r.Config); exempted {
|
||||
if len(check.Annotations(r.Config)) > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ func (r *ScorecardResult) AsString(writer io.Writer, checkDocs docChecks.Doc, op
|
||||
}
|
||||
x = append(x, doc)
|
||||
if opt.Annotations {
|
||||
_, reasons := row.IsExempted(r.Config)
|
||||
reasons := row.Annotations(r.Config)
|
||||
x = append(x, strings.Join(reasons, "\n"))
|
||||
}
|
||||
data[i] = x
|
||||
|
Loading…
Reference in New Issue
Block a user