Skip to content

Commit

Permalink
add feature gate check
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <[email protected]>
  • Loading branch information
cpanato committed Mar 30, 2022
1 parent b3be53e commit ae28356
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion checks/evaluation/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ func Webhooks(name string, dl checker.DetailLogger,
}

return checker.CreateProportionalScoreResult(name,
fmt.Sprintf("%d/%d hook(s) with no secrets configured detected", hasNoSecretCount, len(r.Webhook)), hasNoSecretCount, len(r.Webhook))
fmt.Sprintf("%d/%d hook(s) with no secrets configured detected",
hasNoSecretCount, len(r.Webhook)), hasNoSecretCount, len(r.Webhook))
}
13 changes: 13 additions & 0 deletions checks/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package checks

import (
"os"

"github.com/ossf/scorecard/v4/checker"
"github.com/ossf/scorecard/v4/checks/evaluation"
"github.com/ossf/scorecard/v4/checks/raw"
Expand All @@ -36,6 +38,17 @@ func init() {

// WebHooks run Webhooks check.
func WebHooks(c *checker.CheckRequest) checker.CheckResult {
// TODO: remove this check when v6 is released
_, enabled := os.LookupEnv("SCORECARD_V6")
if !enabled {
c.Dlogger.Warn(&checker.LogMessage{
Text: "SCORECARD_V6 is not set, not running the Webhook check",
})

e := sce.WithMessage(sce.ErrorUnsupportedCheck, "SCORECARD_V6 is not set, not running the Webhook check")
return checker.CreateRuntimeErrorResult(CheckWebHooks, e)
}

rawData, err := raw.WebHook(c)
if err != nil {
e := sce.WithMessage(sce.ErrScorecardInternal, err.Error())
Expand Down
2 changes: 2 additions & 0 deletions checks/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package checks

import (
"context"
"os"
"testing"

"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -101,6 +102,7 @@ func TestWebhooks(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

os.Setenv("SCORECARD_V6", "true")
ctrl := gomock.NewController(t)
mockRepo := mockrepo.NewMockRepoClient(ctrl)

Expand Down

0 comments on commit ae28356

Please sign in to comment.