@@ -31,16 +31,22 @@ const checkRetries = 3
3131
3232// Runner runs a check with retries.
3333type Runner struct {
34- CheckRequest CheckRequest
3534 CheckName string
3635 Repo string
36+ CheckRequest CheckRequest
3737}
3838
3939// CheckFn defined for convenience.
4040type CheckFn func (* CheckRequest ) CheckResult
4141
42+ // Check defines a Scorecard check fn and its supported request types.
43+ type Check struct {
44+ Fn CheckFn
45+ SupportedRequestTypes []RequestType
46+ }
47+
4248// CheckNameToFnMap defined here for convenience.
43- type CheckNameToFnMap map [string ]CheckFn
49+ type CheckNameToFnMap map [string ]Check
4450
4551func logStats (ctx context.Context , startTime time.Time , result * CheckResult ) error {
4652 runTimeInSecs := time .Now ().Unix () - startTime .Unix ()
@@ -57,7 +63,15 @@ func logStats(ctx context.Context, startTime time.Time, result *CheckResult) err
5763}
5864
5965// Run runs a given check.
60- func (r * Runner ) Run (ctx context.Context , f CheckFn ) CheckResult {
66+ func (r * Runner ) Run (ctx context.Context , c Check ) CheckResult {
67+ // Sanity check.
68+ unsupported := ListUnsupported (r .CheckRequest .RequiredTypes , c .SupportedRequestTypes )
69+ if len (unsupported ) != 0 {
70+ return CreateRuntimeErrorResult (r .CheckName ,
71+ sce .WithMessage (sce .ErrorUnsupportedCheck ,
72+ fmt .Sprintf ("requiredType: %s not supported by check %s" , fmt .Sprint (unsupported ), r .CheckName )))
73+ }
74+
6175 ctx , err := tag .New (ctx , tag .Upsert (stats .CheckName , r .CheckName ))
6276 if err != nil {
6377 panic (err )
@@ -71,7 +85,7 @@ func (r *Runner) Run(ctx context.Context, f CheckFn) CheckResult {
7185 checkRequest .Ctx = ctx
7286 l = logger {}
7387 checkRequest .Dlogger = & l
74- res = f (& checkRequest )
88+ res = c . Fn (& checkRequest )
7589 if res .Error2 != nil && errors .Is (res .Error2 , sce .ErrRepoUnreachable ) {
7690 checkRequest .Dlogger .Warn ("%v" , res .Error2 )
7791 continue
0 commit comments