Skip to content

Commit

Permalink
ongoing work for updates to checks [Do not review]
Browse files Browse the repository at this point in the history
Signed-off-by: AdamKorcz <[email protected]>
  • Loading branch information
AdamKorcz committed Sep 7, 2023
1 parent 1e313bd commit 691c2f3
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 12 deletions.
28 changes: 26 additions & 2 deletions checks/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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"
)

// CheckContributors is the registered name for Contributors.
Expand All @@ -34,7 +35,30 @@ func init() {

// Contributors run Contributors check.
func Contributors(c *checker.CheckRequest) checker.CheckResult {
rawData, err := raw.Contributors(c.RepoClient)

rawData, err := raw.Contributors(c)
if err != nil {
e := sce.WithMessage(sce.ErrScorecardInternal, err.Error())
return checker.CreateRuntimeErrorResult(CheckContributors, e)
}

// Set the raw results.
pRawResults := getRawResults(c)
pRawResults.ContributorsResults = rawData

// Evaluate the probes.
findings, err := evaluateProbes(c, pRawResults, probes.Contributors)
if err != nil {
e := sce.WithMessage(sce.ErrScorecardInternal, err.Error())
return checker.CreateRuntimeErrorResult(CheckContributors, e)
}

// Return the score evaluation.
return evaluation.Contributors(CheckContributors, findings)



/*rawData, err := raw.Contributors(c.RepoClient)
if err != nil {
e := sce.WithMessage(sce.ErrScorecardInternal, err.Error())
return checker.CreateRuntimeErrorResult(CheckContributors, e)
Expand All @@ -46,5 +70,5 @@ func Contributors(c *checker.CheckRequest) checker.CheckResult {
}
// Return the score evaluation.
return evaluation.Contributors(CheckContributors, c.Dlogger, &rawData)
return evaluation.Contributors(CheckContributors, c.Dlogger, &rawData)*/
}
4 changes: 2 additions & 2 deletions checks/contributors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestContributors(t *testing.T) {
},
},
expected: checker.CheckResult{
Score: 0,
Score: -1,
},
},
{
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestContributors(t *testing.T) {
name: "No contributors",
contrib: []clients.User{},
expected: checker.CheckResult{
Score: 0,
Score: -1,
},
},
{
Expand Down
38 changes: 34 additions & 4 deletions checks/evaluation/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,49 @@ package evaluation

import (
"fmt"
"sort"
"strings"

"github.com/ossf/scorecard/v4/checker"
"github.com/ossf/scorecard/v4/finding"
sce "github.com/ossf/scorecard/v4/errors"
"github.com/ossf/scorecard/v4/probes/contributorsFromOrgOrCompany"
)

const (
minContributionsPerUser = 5
numberCompaniesForTopScore = 3
)

func Contributors(name string,
findings []finding.Finding,
) checker.CheckResult {
expectedProbes := []string{
contributorsFromOrgOrCompany.Probe,
}

if !finding.UniqueProbesEqual(findings, expectedProbes) {
e := sce.WithMessage(sce.ErrScorecardInternal, "invalid probe results")
return checker.CreateRuntimeErrorResult(name, e)
}

// Compute the score.
var numberCompanies int
for i := range findings {
f := &findings[i]
if f.Outcome == finding.OutcomePositive {
numberCompanies++
}
}

reason := fmt.Sprintf("project has %d contributing companies or organizations", numberCompanies)

if numberCompanies >= 3 {
return checker.CreateMaxScoreResult(name, reason)

}
return checker.CreateMinScoreResult(name, reason)
}

// Contributors applies the score policy for the Contributors check.
func Contributors(name string, dl checker.DetailLogger,
/*func Contributors(name string, dl checker.DetailLogger,
r *checker.ContributorsData,
) checker.CheckResult {
if r == nil {
Expand Down Expand Up @@ -73,3 +102,4 @@ func Contributors(name string, dl checker.DetailLogger,
reason := fmt.Sprintf("%d different organizations found", len(entities))
return checker.CreateProportionalScoreResult(name, reason, len(entities), numberCompaniesForTopScore)
}
*/
4 changes: 2 additions & 2 deletions checks/evaluation/contributors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func TestContributors(t *testing.T) {
},
expected: checker.CheckResult{
Version: 2,
Score: 0,
Reason: "0 different organizations found -- score normalized to 0",
Score: -1,
Reason: "0 different organizations found -- score is -1",
},
},
{
Expand Down
4 changes: 3 additions & 1 deletion checks/raw/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
)

// Contributors retrieves the raw data for the Contributors check.
func Contributors(c clients.RepoClient) (checker.ContributorsData, error) {
func Contributors(cr *checker.CheckRequest) (checker.ContributorsData, error) {

c := cr.RepoClient
var users []clients.User

contribs, err := c.ListContributors()
Expand Down
3 changes: 2 additions & 1 deletion checks/raw/contributors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package raw

/*
import (
"testing"
Expand Down Expand Up @@ -161,3 +161,4 @@ func TestContributors(t *testing.T) {
t.Errorf("unexpected contributors data (-want +got):\n%s", diff)
}
}
*/

0 comments on commit 691c2f3

Please sign in to comment.