MCPcopy
hub / github.com/ossf/scorecard / Run

Function Run

probes/requiresApproversForPullRequests/impl.go:45–91  ·  view source on GitHub ↗
(raw *checker.RawResults)

Source from the content-addressed store, hash-verified

43var errWrongValue = errors.New("wrong value, should not happen")
44
45func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
46 if raw == nil {
47 return nil, "", fmt.Errorf("%w: raw", uerror.ErrNil)
48 }
49
50 r := raw.BranchProtectionResults
51 var findings []finding.Finding
52
53 if len(r.Branches) == 0 {
54 f, err := finding.NewWith(fs, Probe, "no branches found", nil, finding.OutcomeNotApplicable)
55 if err != nil {
56 return nil, Probe, fmt.Errorf("create finding: %w", err)
57 }
58 findings = append(findings, *f)
59 return findings, Probe, nil
60 }
61
62 for i := range r.Branches {
63 branch := &r.Branches[i]
64
65 nilMsg := fmt.Sprintf("could not determine whether branch '%s' has required approving review count", *branch.Name)
66 falseMsg := fmt.Sprintf("branch '%s' does not require approvers", *branch.Name)
67
68 p := branch.BranchProtectionRule.PullRequestRule.RequiredApprovingReviewCount
69
70 f, err := finding.NewWith(fs, Probe, "", nil, finding.OutcomeNotAvailable)
71 if err != nil {
72 return nil, Probe, fmt.Errorf("create finding: %w", err)
73 }
74 f = f.WithValue(BranchNameKey, *branch.Name)
75 switch {
76 case p == nil:
77 f = f.WithMessage(nilMsg).WithOutcome(finding.OutcomeNotAvailable)
78 case *p > 0:
79 msg := fmt.Sprintf("required approving review count is %d on branch '%s'", *p, *branch.Name)
80 f = f.WithMessage(msg).WithOutcome(finding.OutcomeTrue)
81 f = f.WithValue(RequiredReviewersKey, strconv.Itoa(int(*p)))
82 case *p == 0:
83 f = f.WithMessage(falseMsg).WithOutcome(finding.OutcomeFalse)
84 f = f.WithValue(RequiredReviewersKey, strconv.Itoa(int(*p)))
85 default:
86 return nil, Probe, fmt.Errorf("create finding: %w", errWrongValue)
87 }
88 findings = append(findings, *f)
89 }
90 return findings, Probe, nil
91}

Callers 1

Test_RunFunction · 0.70

Calls 4

NewWithFunction · 0.92
WithValueMethod · 0.80
WithOutcomeMethod · 0.80
WithMessageMethod · 0.80

Tested by 1

Test_RunFunction · 0.56