Skip to content

Commit

Permalink
force push: re-apply changes after big probes PR
Browse files Browse the repository at this point in the history
Signed-off-by: Diogo Teles Sant'Anna <[email protected]>
  • Loading branch information
diogoteles08 committed Mar 21, 2024
1 parent c1066d9 commit e19af7e
Showing 1 changed file with 117 additions and 117 deletions.
234 changes: 117 additions & 117 deletions checks/evaluation/branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,64 +235,79 @@ func getBranchName(f *finding.Finding) (string, error) {
return name, nil
}

func sumUpScoreForTier(t tier, scoresData []levelScore) int {
sum := 0
for i := range scoresData {
score := scoresData[i]
switch t {
case Tier1:
sum += score.scores.basic
case Tier2:
sum += score.scores.review + score.scores.adminReview
case Tier3:
sum += score.scores.context
case Tier4:
sum += score.scores.thoroughReview + score.scores.codeownerReview
case Tier5:
sum += score.scores.adminThoroughReview
}
func deleteAndForcePushProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
logWithoutDebug(f, doLogging, dl)
if f.Outcome == finding.OutcomePositive {
score++
}
return sum
max++

return score, max
}

func logWithDebug(f *finding.Finding, doLogging bool, dl checker.DetailLogger) {
switch f.Outcome {
case finding.OutcomeNotAvailable:
debug(dl, doLogging, f.Message)
case finding.OutcomePositive:
info(dl, doLogging, f.Message)
case finding.OutcomeNegative:
warn(dl, doLogging, f.Message)
default:
// To satisfy linter
func adminThoroughReviewProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int

logWithDebug(f, doLogging, dl)
if f.Outcome == finding.OutcomePositive {
score++
}
if f.Outcome != finding.OutcomeNotAvailable {
max++
}
return score, max
}

func logWithoutDebug(f *finding.Finding, doLogging bool, dl checker.DetailLogger) {
switch f.Outcome {
case finding.OutcomePositive:
info(dl, doLogging, f.Message)
case finding.OutcomeNegative:
func nonAdminThoroughReviewProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
if f.Outcome == finding.OutcomePositive {
noOfRequiredReviews, _ := strconv.Atoi(f.Values["numberOfRequiredReviewers"]) //nolint:errcheck
if noOfRequiredReviews >= minReviews {
info(dl, doLogging, f.Message)
score++

Check warning on line 268 in checks/evaluation/branch_protection.go

View check run for this annotation

Codecov / codecov/patch

checks/evaluation/branch_protection.go#L267-L268

Added lines #L267 - L268 were not covered by tests
} else {
warn(dl, doLogging, f.Message)
}
} else if f.Outcome == finding.OutcomeNegative {
warn(dl, doLogging, f.Message)
default:
// To satisfy linter
}
max++
return score, max
}

func logInfoOrWarn(f *finding.Finding, doLogging bool, dl checker.DetailLogger) {
switch f.Outcome {
case finding.OutcomePositive:
func codeownerBranchProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
if f.Outcome == finding.OutcomePositive {
info(dl, doLogging, f.Message)
default:
score++
} else {
warn(dl, doLogging, f.Message)
}
max++
return score, max
}

func normalizeScore(score, max, level int) float64 {
if max == 0 {
return float64(level)
func adminReviewProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
if f.Outcome == finding.OutcomePositive {
score++
}
return float64(score*level) / float64(max)
logWithDebug(f, doLogging, dl)
if f.Outcome != finding.OutcomeNotAvailable {
max++
}
return score, max
}

func nonAdminContextProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
logInfoOrWarn(f, doLogging, dl)
if f.Outcome == finding.OutcomePositive {
score++
}
max++
return score, max
}

func computeFinalScore(scores []levelScore) (int, error) {
Expand Down Expand Up @@ -351,6 +366,66 @@ func computeFinalScore(scores []levelScore) (int, error) {
return int(score), nil
}

func sumUpScoreForTier(t tier, scoresData []levelScore) int {
sum := 0
for i := range scoresData {
score := scoresData[i]
switch t {
case Tier1:
sum += score.scores.basic
case Tier2:
sum += score.scores.review + score.scores.adminReview
case Tier3:
sum += score.scores.context
case Tier4:
sum += score.scores.thoroughReview + score.scores.codeownerReview
case Tier5:
sum += score.scores.adminThoroughReview

Check warning on line 383 in checks/evaluation/branch_protection.go

View check run for this annotation

Codecov / codecov/patch

checks/evaluation/branch_protection.go#L382-L383

Added lines #L382 - L383 were not covered by tests
}
}
return sum
}

func normalizeScore(score, max, level int) float64 {
if max == 0 {
return float64(level)
}

Check warning on line 392 in checks/evaluation/branch_protection.go

View check run for this annotation

Codecov / codecov/patch

checks/evaluation/branch_protection.go#L391-L392

Added lines #L391 - L392 were not covered by tests
return float64(score*level) / float64(max)
}

func logWithDebug(f *finding.Finding, doLogging bool, dl checker.DetailLogger) {
switch f.Outcome {
case finding.OutcomeNotAvailable:
debug(dl, doLogging, f.Message)
case finding.OutcomePositive:
info(dl, doLogging, f.Message)
case finding.OutcomeNegative:
warn(dl, doLogging, f.Message)
default:

Check warning on line 404 in checks/evaluation/branch_protection.go

View check run for this annotation

Codecov / codecov/patch

checks/evaluation/branch_protection.go#L404

Added line #L404 was not covered by tests
// To satisfy linter
}
}

func logWithoutDebug(f *finding.Finding, doLogging bool, dl checker.DetailLogger) {
switch f.Outcome {
case finding.OutcomePositive:
info(dl, doLogging, f.Message)
case finding.OutcomeNegative:
warn(dl, doLogging, f.Message)
default:
// To satisfy linter
}
}

func logInfoOrWarn(f *finding.Finding, doLogging bool, dl checker.DetailLogger) {
switch f.Outcome {
case finding.OutcomePositive:
info(dl, doLogging, f.Message)
default:
warn(dl, doLogging, f.Message)
}
}

func info(dl checker.DetailLogger, doLogging bool, desc string, args ...interface{}) {
if !doLogging {
return
Expand Down Expand Up @@ -380,78 +455,3 @@ func warn(dl checker.DetailLogger, doLogging bool, desc string, args ...interfac
Text: fmt.Sprintf(desc, args...),
})
}

func deleteAndForcePushProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
logWithoutDebug(f, doLogging, dl)
if f.Outcome == finding.OutcomePositive {
score++
}
max++

return score, max
}

func nonAdminContextProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
logInfoOrWarn(f, doLogging, dl)
if f.Outcome == finding.OutcomePositive {
score++
}
max++
return score, max
}

func adminReviewProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
if f.Outcome == finding.OutcomePositive {
score++
}
logWithDebug(f, doLogging, dl)
if f.Outcome != finding.OutcomeNotAvailable {
max++
}
return score, max
}

func adminThoroughReviewProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int

logWithDebug(f, doLogging, dl)
if f.Outcome == finding.OutcomePositive {
score++
}
if f.Outcome != finding.OutcomeNotAvailable {
max++
}
return score, max
}

func nonAdminThoroughReviewProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
if f.Outcome == finding.OutcomePositive {
noOfRequiredReviews, _ := strconv.Atoi(f.Values["numberOfRequiredReviewers"]) //nolint:errcheck
if noOfRequiredReviews >= minReviews {
info(dl, doLogging, f.Message)
score++
} else {
warn(dl, doLogging, f.Message)
}
} else if f.Outcome == finding.OutcomeNegative {
warn(dl, doLogging, f.Message)
}
max++
return score, max
}

func codeownerBranchProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
if f.Outcome == finding.OutcomePositive {
info(dl, doLogging, f.Message)
score++
} else {
warn(dl, doLogging, f.Message)
}
max++
return score, max
}

0 comments on commit e19af7e

Please sign in to comment.