diff --git a/checks/branch_protection_test.go b/checks/branch_protection_test.go index d0c6f087fcd..d56a4cce2bd 100644 --- a/checks/branch_protection_test.go +++ b/checks/branch_protection_test.go @@ -174,7 +174,7 @@ func TestReleaseAndDevBranchProtected(t *testing.T) { Error: nil, Score: 4, NumberOfWarn: 9, - NumberOfInfo: 11, + NumberOfInfo: 12, NumberOfDebug: 0, }, defaultBranch: main, @@ -232,7 +232,7 @@ func TestReleaseAndDevBranchProtected(t *testing.T) { Error: nil, Score: 8, NumberOfWarn: 4, - NumberOfInfo: 16, + NumberOfInfo: 18, NumberOfDebug: 0, }, defaultBranch: main, diff --git a/checks/evaluation/branch_protection.go b/checks/evaluation/branch_protection.go index 97a0b509bfe..ab221246b33 100644 --- a/checks/evaluation/branch_protection.go +++ b/checks/evaluation/branch_protection.go @@ -454,7 +454,11 @@ func codeownerBranchProtection(f *finding.Finding, doLogging bool, dl checker.De var score, max int if f.Outcome == finding.OutcomePositive { info(dl, doLogging, f.Message) - score++ + if f.Values["CodeownersFiles"] == 0 { + warn(dl, doLogging, "codeowners branch protection is being ignored - but no codeowners file found in repo") + } else { + score++ + } } else { warn(dl, doLogging, f.Message) } diff --git a/checks/evaluation/branch_protection_test.go b/checks/evaluation/branch_protection_test.go index f2dfbf201f2..98a211f3e0b 100644 --- a/checks/evaluation/branch_protection_test.go +++ b/checks/evaluation/branch_protection_test.go @@ -521,7 +521,8 @@ func TestBranchProtection(t *testing.T) { Probe: "requiresCodeOwnersReview", Outcome: finding.OutcomePositive, Values: map[string]int{ - "main": 1, + "main": 1, + "CodeownersFiles": 2, }, }, { @@ -1227,7 +1228,8 @@ func TestBranchProtection(t *testing.T) { Probe: "requiresCodeOwnersReview", Outcome: finding.OutcomePositive, Values: map[string]int{ - "main": 1, + "main": 1, + "CodeownersFiles": 2, }, }, { @@ -1315,7 +1317,8 @@ func TestBranchProtection(t *testing.T) { Probe: "requiresCodeOwnersReview", Outcome: finding.OutcomePositive, Values: map[string]int{ - "main": 1, + "main": 1, + "CodeownersFiles": 2, }, }, { @@ -1403,7 +1406,8 @@ func TestBranchProtection(t *testing.T) { Probe: "requiresCodeOwnersReview", Outcome: finding.OutcomePositive, Values: map[string]int{ - "main": 1, + "main": 1, + "CodeownersFiles": 2, }, }, { @@ -1481,7 +1485,8 @@ func TestBranchProtection(t *testing.T) { Probe: "requiresCodeOwnersReview", Outcome: finding.OutcomePositive, Values: map[string]int{ - "main2": 1, + "main2": 1, + "CodeownersFiles": 2, }, }, { diff --git a/probes/requiresCodeOwnersReview/impl.go b/probes/requiresCodeOwnersReview/impl.go index 44f4bc92c0b..429b3c8163f 100644 --- a/probes/requiresCodeOwnersReview/impl.go +++ b/probes/requiresCodeOwnersReview/impl.go @@ -63,9 +63,6 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) { case !*reqOwnerReviews: text = fmt.Sprintf("codeowners review is not required on branch '%s'", *branch.Name) outcome = finding.OutcomeNegative - case len(r.CodeownersFiles) == 0: - text = "codeowners review is required - but no codeowners file found in repo" - outcome = finding.OutcomeNegative default: text = fmt.Sprintf("codeowner review is required on branch '%s'", *branch.Name) outcome = finding.OutcomePositive