mirror of
https://github.com/ossf/scorecard.git
synced 2024-11-04 03:52:31 +03:00
Replace checker.CIIBadge
with clients.CIIBadge
(#1945)
Co-authored-by: Azeem Shaikh <azeems@google.com>
This commit is contained in:
parent
108f88d056
commit
1a2f08827f
@ -14,7 +14,11 @@
|
||||
|
||||
package checker
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/ossf/scorecard/v4/clients"
|
||||
)
|
||||
|
||||
// RawResults contains results before a policy
|
||||
// is applied.
|
||||
@ -290,28 +294,9 @@ type ReleaseAsset struct {
|
||||
URL string
|
||||
}
|
||||
|
||||
// CIIBadge corresponds to CII-Best-Practices badges.
|
||||
// https://bestpractices.coreinfrastructure.org/en
|
||||
type CIIBadge string
|
||||
|
||||
const (
|
||||
// CIIBadgeUnknown or non-parsable CII Best Practices badge.
|
||||
CIIBadgeUnknown CIIBadge = "unknown"
|
||||
// CIIBadgeNotFound represents when CII Best Practices returns an empty response for a project.
|
||||
CIIBadgeNotFound CIIBadge = "not_found"
|
||||
// CIIBadgeInProgress state of CII Best Practices badge.
|
||||
CIIBadgeInProgress CIIBadge = "in_progress"
|
||||
// CIIBadgePassing for CII Best Practices badge.
|
||||
CIIBadgePassing CIIBadge = "passing"
|
||||
// CIIBadgeSilver for CII Best Practices badge.
|
||||
CIIBadgeSilver CIIBadge = "silver"
|
||||
// CIIBadgeGold for CII Best Practices badge.
|
||||
CIIBadgeGold CIIBadge = "gold"
|
||||
)
|
||||
|
||||
// CIIBestPracticesData contains data foor CIIBestPractices check.
|
||||
type CIIBestPracticesData struct {
|
||||
Badge CIIBadge
|
||||
Badge clients.BadgeLevel
|
||||
}
|
||||
|
||||
// DangerousWorkflowType represents a type of dangerous workflow.
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ossf/scorecard/v4/checker"
|
||||
"github.com/ossf/scorecard/v4/clients"
|
||||
sce "github.com/ossf/scorecard/v4/errors"
|
||||
)
|
||||
|
||||
@ -39,21 +40,21 @@ func CIIBestPractices(name string, dl checker.DetailLogger, r *checker.CIIBestPr
|
||||
|
||||
var results checker.CheckResult
|
||||
switch r.Badge {
|
||||
case checker.CIIBadgeNotFound:
|
||||
case clients.NotFound:
|
||||
results = checker.CreateMinScoreResult(name, "no badge detected")
|
||||
case checker.CIIBadgeInProgress:
|
||||
case clients.InProgress:
|
||||
msg := fmt.Sprintf("badge detected: %v", r.Badge)
|
||||
results = checker.CreateResultWithScore(name, msg, inProgressScore)
|
||||
case checker.CIIBadgePassing:
|
||||
case clients.Passing:
|
||||
msg := fmt.Sprintf("badge detected: %v", r.Badge)
|
||||
results = checker.CreateResultWithScore(name, msg, passingScore)
|
||||
case checker.CIIBadgeSilver:
|
||||
case clients.Silver:
|
||||
msg := fmt.Sprintf("badge detected: %v", r.Badge)
|
||||
results = checker.CreateResultWithScore(name, msg, silverScore)
|
||||
case checker.CIIBadgeGold:
|
||||
case clients.Gold:
|
||||
msg := fmt.Sprintf("badge detected: %v", r.Badge)
|
||||
results = checker.CreateMaxScoreResult(name, msg)
|
||||
case checker.CIIBadgeUnknown:
|
||||
case clients.Unknown:
|
||||
e := sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("unsupported badge: %v", r.Badge))
|
||||
results = checker.CreateRuntimeErrorResult(name, e)
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ossf/scorecard/v4/checker"
|
||||
"github.com/ossf/scorecard/v4/clients"
|
||||
)
|
||||
|
||||
var errEmptyClient = errors.New("CII client is nil")
|
||||
@ -35,21 +34,7 @@ func CIIBestPractices(c *checker.CheckRequest) (checker.CIIBestPracticesData, er
|
||||
if err != nil {
|
||||
return results, fmt.Errorf("%w", err)
|
||||
}
|
||||
|
||||
switch badge {
|
||||
case clients.NotFound:
|
||||
results.Badge = checker.CIIBadgeNotFound
|
||||
case clients.InProgress:
|
||||
results.Badge = checker.CIIBadgeInProgress
|
||||
case clients.Passing:
|
||||
results.Badge = checker.CIIBadgePassing
|
||||
case clients.Silver:
|
||||
results.Badge = checker.CIIBadgeSilver
|
||||
case clients.Gold:
|
||||
results.Badge = checker.CIIBadgeGold
|
||||
case clients.Unknown:
|
||||
results.Badge = checker.CIIBadgeUnknown
|
||||
}
|
||||
results.Badge = badge
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
@ -37,6 +37,26 @@ const (
|
||||
// https://bestpractices.coreinfrastructure.org/en
|
||||
type BadgeLevel uint
|
||||
|
||||
// String returns a string value for BadgeLevel enum.
|
||||
func (badge BadgeLevel) String() string {
|
||||
switch badge {
|
||||
case Unknown:
|
||||
return "Unknown"
|
||||
case NotFound:
|
||||
return "not_found"
|
||||
case InProgress:
|
||||
return "in_progress"
|
||||
case Passing:
|
||||
return "passing"
|
||||
case Silver:
|
||||
return "silver"
|
||||
case Gold:
|
||||
return "gold"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// CIIBestPracticesClient interface returns the BadgeLevel for a repo URL.
|
||||
type CIIBestPracticesClient interface {
|
||||
GetBadgeLevel(ctx context.Context, uri string) (BadgeLevel, error)
|
||||
|
@ -395,7 +395,7 @@ func (r *jsonScorecardRawResult) setDefaultCommitData(commits []checker.DefaultB
|
||||
|
||||
//nolint:unparam
|
||||
func (r *jsonScorecardRawResult) addOssfBestPracticesRawResults(cbp *checker.CIIBestPracticesData) error {
|
||||
r.Results.OssfBestPractices.Badge = string(cbp.Badge)
|
||||
r.Results.OssfBestPractices.Badge = cbp.Badge.String()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user