-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6406cfd
commit 66135c9
Showing
5 changed files
with
263 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2021 Security Scorecard Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package evaluation | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
"strings" | ||
|
||
"github.com/ossf/scorecard/v4/checker" | ||
sce "github.com/ossf/scorecard/v4/errors" | ||
) | ||
|
||
const ( | ||
minContributionsPerUser = 5 | ||
numberCompaniesForTopScore = 3 | ||
) | ||
|
||
// Contributors applies the score policy for the Contributors check. | ||
func Contributors(name string, dl checker.DetailLogger, | ||
r *checker.ContributorsData, | ||
) checker.CheckResult { | ||
if r == nil { | ||
e := sce.WithMessage(sce.ErrScorecardInternal, "empty raw data") | ||
return checker.CreateRuntimeErrorResult(name, e) | ||
} | ||
|
||
entities := make(map[string]bool) | ||
|
||
for _, user := range r.Users { | ||
if user.NumContributions < minContributionsPerUser { | ||
continue | ||
} | ||
|
||
for _, org := range user.Organizations { | ||
entities[org.Login] = true | ||
} | ||
|
||
for _, comp := range user.Companies { | ||
entities[comp.Name] = true | ||
} | ||
} | ||
|
||
names := []string{} | ||
for c := range entities { | ||
names = append(names, c) | ||
} | ||
|
||
sort.Strings(names) | ||
|
||
if len(name) > 0 { | ||
dl.Info(&checker.LogMessage{ | ||
Text: fmt.Sprintf("contributors work for %v", strings.Join(names, ",")), | ||
}) | ||
} else { | ||
dl.Warn(&checker.LogMessage{ | ||
Text: "no contributors have an org or company", | ||
}) | ||
} | ||
|
||
reason := fmt.Sprintf("%d different organizations found", len(entities)) | ||
return checker.CreateProportionalScoreResult(name, reason, len(entities), numberCompaniesForTopScore) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2020 Security Scorecard Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package raw | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/ossf/scorecard/v4/checker" | ||
"github.com/ossf/scorecard/v4/clients" | ||
) | ||
|
||
// Contributors retrieves the raw data for the Contributors check. | ||
func Contributors(c clients.RepoClient) (checker.ContributorsData, error) { | ||
var users []checker.User | ||
|
||
contribs, err := c.ListContributors() | ||
if err != nil { | ||
return checker.ContributorsData{}, fmt.Errorf("Client.Repositories.ListContributors: %w", err) | ||
} | ||
|
||
for _, contrib := range contribs { | ||
user := checker.User{ | ||
Login: contrib.User.Login, | ||
NumContributions: uint(contrib.NumContributions), | ||
} | ||
|
||
for _, org := range contrib.Organizations { | ||
if org.Login != "" && !orgContains(user.Organizations, org.Login) { | ||
user.Organizations = append(user.Organizations, | ||
checker.Organization{ | ||
Login: org.Login, | ||
}, | ||
) | ||
} | ||
} | ||
|
||
company := contrib.Company | ||
if company != "" { | ||
company = strings.ToLower(company) | ||
company = strings.ReplaceAll(company, "inc.", "") | ||
company = strings.ReplaceAll(company, "llc", "") | ||
company = strings.ReplaceAll(company, ",", "") | ||
company = strings.TrimLeft(company, "@") | ||
company = strings.Trim(company, " ") | ||
if company != "" && !companyContains(user.Companies, company) { | ||
user.Companies = append(user.Companies, | ||
checker.Company{ | ||
Name: company, | ||
}, | ||
) | ||
} | ||
} | ||
|
||
users = append(users, user) | ||
} | ||
|
||
return checker.ContributorsData{Users: users}, nil | ||
} | ||
|
||
func companyContains(cs []checker.Company, name string) bool { | ||
for _, a := range cs { | ||
if a.Name == name { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func orgContains(os []checker.Organization, login string) bool { | ||
for _, a := range os { | ||
if a.Login == login { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
Oops, something went wrong.