checker

package
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxResultConfidence  = 10
	HalfResultConfidence = 5
	MinResultConfidence  = 0
)

UPGRADEv2: to remove.

View Source
const (
	MaxResultScore          = 10
	MinResultScore          = 0
	InconclusiveResultScore = -1
)

nolint

Variables

View Source
var ErrorDemoninatorZero = errors.New("internal error: denominator is 0")

ErrorDemoninatorZero indicates the denominator for a proportional result is 0. UPGRADEv2: to remove.

Functions

func AggregateScores

func AggregateScores(scores ...int) int

AggregateScores adds up all scores and normalizes the result. Each score contributes equally.

func AggregateScoresWithWeight

func AggregateScoresWithWeight(scores map[int]int) int

AggregateScoresWithWeight adds up all scores and normalizes the result. The caller is responsible for ensuring the sum of weights is 10.

func Bool2int

func Bool2int(b bool) int

func CreateProportionalScore

func CreateProportionalScore(b, t int) int

CreateProportionalScore() creates a proportional score.

func NormalizeReason

func NormalizeReason(reason string, score int) string

Types

type CheckDetail

type CheckDetail struct {
	Type DetailType // Any of DetailWarn, DetailInfo, DetailDebug.
	Msg  string     // A short string explaining why the details was recorded/logged..
}

CheckDetail contains information for each detail.

type CheckFn

type CheckFn func(*CheckRequest) CheckResult

func MultiCheckAnd

func MultiCheckAnd(fns ...CheckFn) CheckFn

MultiCheckAnd means all checks must succeed. This returns a conservative result where the worst result is returned.

func MultiCheckAnd2

func MultiCheckAnd2(fns ...CheckFn) CheckFn

func MultiCheckOr

func MultiCheckOr(fns ...CheckFn) CheckFn

UPGRADEv2: will be removed. MultiCheckOr returns the best check result out of several ones performed.

func MultiCheckOr2

func MultiCheckOr2(fns ...CheckFn) CheckFn

type CheckNameToFnMap

type CheckNameToFnMap map[string]CheckFn

type CheckRequest

type CheckRequest struct {
	Ctx         context.Context
	Client      *github.Client
	GraphClient *githubv4.Client
	HTTPClient  *http.Client
	RepoClient  clients.RepoClient
	// UPGRADEv2: Logf will be removed.
	Logf        func(s string, f ...interface{})
	Dlogger     DetailLogger
	Owner, Repo string
}

type CheckResult

type CheckResult struct {
	// Old structure
	Error       error `json:"-"`
	Name        string
	Details     []string
	Confidence  int
	Pass        bool
	ShouldRetry bool `json:"-"`

	// UPGRADEv2: New structure. Omitting unchanged Name field
	// for simplicity.
	Version  int           `json:"-"` // Default value of 0 indicates old structure.
	Error2   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)
}

nolint

func CreateInconclusiveResult

func CreateInconclusiveResult(name, reason string) CheckResult

CreateInconclusiveResult is used when the check runs without runtime errors, but we don't have enough evidence to set a score.

func CreateMaxScoreResult

func CreateMaxScoreResult(name, reason string) CheckResult

CreateMaxScoreResult is used when the check runs without runtime errors and we can assign a maximum score to the result.

func CreateMinScoreResult

func CreateMinScoreResult(name, reason string) CheckResult

CreateMinScoreResult is used when the check runs without runtime errors and we can assign a minimum score to the result.

func CreateProportionalScoreResult

func CreateProportionalScoreResult(name, reason string, b, t int) CheckResult

CreateProportionalScoreResult is used when the check runs without runtime errors and we assign a proportional score. This may be used if a check contains multiple tests and we want to assign a score proportional the the number of tests that succeeded.

func CreateResultWithScore

func CreateResultWithScore(name, reason string, score int) CheckResult

CreateResultWithScore is used when the check runs without runtime errors and we want to assign a specific score.

func CreateRuntimeErrorResult

func CreateRuntimeErrorResult(name string, e error) CheckResult

CreateRuntimeErrorResult is used when the check fails to run because of a runtime error.

func MakeAndResult

func MakeAndResult(checks ...CheckResult) CheckResult

MakeAndResult means all checks must succeed. This returns a conservative result where the worst result is returned.

func MakeAndResult2

func MakeAndResult2(checks ...CheckResult) CheckResult

UPGRADEv2: functions below will be renamed.

func MakeFailResult

func MakeFailResult(name string, err error) CheckResult

func MakeInconclusiveResult

func MakeInconclusiveResult(name string, err error) CheckResult

func MakeOrResult

func MakeOrResult(c *CheckRequest, checks ...CheckResult) CheckResult

func MakePassResult

func MakePassResult(name string) CheckResult

func MakeProportionalResult

func MakeProportionalResult(name string, numerator int, denominator int,
	threshold float32) CheckResult

func MakeRetryResult

func MakeRetryResult(name string, err error) CheckResult

type DetailLogger

type DetailLogger interface {
	Info(desc string, args ...interface{})
	Warn(desc string, args ...interface{})
	Debug(desc string, args ...interface{})
}

type DetailType

type DetailType int

Types of details.

const (
	DetailInfo DetailType = iota
	DetailWarn
	DetailDebug
)

type Runner

type Runner struct {
	CheckName    string
	Repo         string
	CheckRequest CheckRequest
}

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, f CheckFn) CheckResult

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL