Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Add branch protection evaluation #3759

Merged
merged 25 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e81a9ae
:seedling: Add branch protection evaluation
AdamKorcz Dec 28, 2023
6a79f17
make helper for getting the branchName
AdamKorcz Jan 8, 2024
c29bb43
move check for branch name
AdamKorcz Jan 8, 2024
627fdae
define size of slice
AdamKorcz Jan 8, 2024
e06bb06
add probe for protected branches.
AdamKorcz Jan 9, 2024
de9a374
change 'basicNonAdminProtection' to 'deleteAndForcePushProtection'
AdamKorcz Jan 10, 2024
3676de3
fix markdown in text field in def.yml
AdamKorcz Jan 10, 2024
2999537
remove duplicate conditional
AdamKorcz Jan 10, 2024
d34ae27
remove redundant 'protected' value from 'requiresCodeOwnersReview' probe
AdamKorcz Jan 10, 2024
5c98388
remove protected values from probes
AdamKorcz Jan 10, 2024
75c18eb
Bring back negative outcome in case of 0 codeowners files
AdamKorcz Jan 14, 2024
48c1b53
log based on whether branches are protected
AdamKorcz Jan 14, 2024
2d26086
remove unnecessary test
AdamKorcz Feb 5, 2024
00acf66
debug failing tests
AdamKorcz Feb 5, 2024
175d28f
Fix failing tests
AdamKorcz Feb 6, 2024
aeb5a55
rename test
AdamKorcz Feb 6, 2024
e5b1666
update to with latest upstream changes
AdamKorcz Feb 19, 2024
21fdf63
fix linting issues
AdamKorcz Feb 22, 2024
a4896eb
remove tests that represent impossible scenarios
AdamKorcz Feb 24, 2024
93fbbc1
remove protected finding value
spencerschrock Feb 27, 2024
6280031
Revert "debug failing tests"
spencerschrock Feb 27, 2024
b51e620
use branchName key for branch name
spencerschrock Feb 27, 2024
8358285
include number of reviews in INFO
spencerschrock Feb 27, 2024
6123cef
reduce info count by 1
spencerschrock Feb 27, 2024
f706b69
Merge branch 'main' into pr/AdamKorcz/3759
spencerschrock Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"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 @@

// 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)
}
4 changes: 2 additions & 2 deletions checks/branch_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
Error: nil,
Score: 4,
NumberOfWarn: 9,
NumberOfInfo: 12,
NumberOfInfo: 11,
spencerschrock marked this conversation as resolved.
Show resolved Hide resolved
NumberOfDebug: 0,
},
defaultBranch: main,
Expand Down Expand Up @@ -232,7 +232,7 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
Error: nil,
Score: 8,
NumberOfWarn: 4,
NumberOfInfo: 18,
NumberOfInfo: 16,
NumberOfDebug: 0,
},
defaultBranch: main,
Expand Down
Loading
Loading