Skip to content

Commit

Permalink
🌱 Add branch protection evaluation
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Korczynski <adam@adalogics.com>
  • Loading branch information
AdamKorcz committed Dec 29, 2023
1 parent 6a226ce commit 99a2df2
Show file tree
Hide file tree
Showing 19 changed files with 2,048 additions and 671 deletions.
18 changes: 13 additions & 5 deletions checks/branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/ossf/scorecard/v4/checks/evaluation"
"github.com/ossf/scorecard/v4/checks/raw"
sce "github.com/ossf/scorecard/v4/errors"
"github.com/ossf/scorecard/v4/probes"
"github.com/ossf/scorecard/v4/probes/zrunner"
)

// CheckBranchProtection is the exported name for Branch-Protected check.
Expand All @@ -34,17 +36,23 @@ func init() {

// BranchProtection runs the Branch-Protection check.
func BranchProtection(c *checker.CheckRequest) checker.CheckResult {
rawData, err := raw.BranchProtection(c.RepoClient)
rawData, err := raw.BranchProtection(c)
if err != nil {
e := sce.WithMessage(sce.ErrScorecardInternal, err.Error())
return checker.CreateRuntimeErrorResult(CheckBranchProtection, e)
}

// Return raw results.
if c.RawResults != nil {
c.RawResults.BranchProtectionResults = rawData
// Set the raw results.
pRawResults := getRawResults(c)
pRawResults.BranchProtectionResults = rawData

// Evaluate the probes.
findings, err := zrunner.Run(pRawResults, probes.BranchProtection)
if err != nil {
e := sce.WithMessage(sce.ErrScorecardInternal, err.Error())
return checker.CreateRuntimeErrorResult(CheckBranchProtection, e)

Check warning on line 53 in checks/branch_protection.go

View check run for this annotation

Codecov / codecov/patch

checks/branch_protection.go#L52-L53

Added lines #L52 - L53 were not covered by tests
}

// Return the score evaluation.
return evaluation.BranchProtection(CheckBranchProtection, c.Dlogger, &rawData)
return evaluation.BranchProtection(CheckBranchProtection, findings, c.Dlogger)
}
Loading

0 comments on commit 99a2df2

Please sign in to comment.