mirror of
https://github.com/ossf/scorecard.git
synced 2024-08-15 03:10:33 +03:00
Replace clients.Contributor
with clients.User
(#1957)
Co-authored-by: Azeem Shaikh <azeems@google.com>
This commit is contained in:
parent
f712144d00
commit
1d9cd05476
@ -65,7 +65,7 @@ type CodeReviewData struct {
|
||||
|
||||
// ContributorsData represents contributor information.
|
||||
type ContributorsData struct {
|
||||
Users []clients.Contributor
|
||||
Users []clients.User
|
||||
}
|
||||
|
||||
// VulnerabilitiesData contains the raw results
|
||||
|
@ -34,13 +34,13 @@ func TestContributors(t *testing.T) {
|
||||
tests := []struct {
|
||||
err error
|
||||
name string
|
||||
contrib []clients.Contributor
|
||||
contrib []clients.User
|
||||
expected checker.CheckResult
|
||||
}{
|
||||
{
|
||||
err: nil,
|
||||
name: "Two contributors without company",
|
||||
contrib: []clients.Contributor{
|
||||
contrib: []clients.User{
|
||||
{
|
||||
Organizations: []clients.User{
|
||||
{
|
||||
@ -59,7 +59,7 @@ func TestContributors(t *testing.T) {
|
||||
{
|
||||
err: nil,
|
||||
name: "Valid contributors with enough contributors and companies",
|
||||
contrib: []clients.Contributor{
|
||||
contrib: []clients.User{
|
||||
{
|
||||
|
||||
Companies: []string{"company1"},
|
||||
@ -140,7 +140,7 @@ func TestContributors(t *testing.T) {
|
||||
{
|
||||
err: nil,
|
||||
name: "No contributors",
|
||||
contrib: []clients.Contributor{},
|
||||
contrib: []clients.User{},
|
||||
expected: checker.CheckResult{
|
||||
Score: 0,
|
||||
},
|
||||
@ -148,7 +148,7 @@ func TestContributors(t *testing.T) {
|
||||
{
|
||||
err: errors.New("error"),
|
||||
name: "Error getting contributors",
|
||||
contrib: []clients.Contributor{},
|
||||
contrib: []clients.User{},
|
||||
expected: checker.CheckResult{
|
||||
Score: -1,
|
||||
},
|
||||
@ -161,7 +161,7 @@ func TestContributors(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctrl := gomock.NewController(t)
|
||||
mockRepo := mockrepo.NewMockRepoClient(ctrl)
|
||||
mockRepo.EXPECT().ListContributors().DoAndReturn(func() ([]clients.Contributor, error) {
|
||||
mockRepo.EXPECT().ListContributors().DoAndReturn(func() ([]clients.User, error) {
|
||||
if tt.err != nil {
|
||||
return nil, tt.err
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
|
||||
// Contributors retrieves the raw data for the Contributors check.
|
||||
func Contributors(c clients.RepoClient) (checker.ContributorsData, error) {
|
||||
var users []clients.Contributor
|
||||
var users []clients.User
|
||||
|
||||
contribs, err := c.ListContributors()
|
||||
if err != nil {
|
||||
@ -32,8 +32,8 @@ func Contributors(c clients.RepoClient) (checker.ContributorsData, error) {
|
||||
}
|
||||
|
||||
for _, contrib := range contribs {
|
||||
user := clients.Contributor{
|
||||
User: contrib.User,
|
||||
user := clients.User{
|
||||
Login: contrib.Login,
|
||||
NumContributions: contrib.NumContributions,
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,6 @@ type Commit struct {
|
||||
CommittedDate time.Time
|
||||
Message string
|
||||
SHA string
|
||||
Committer User
|
||||
AssociatedMergeRequest PullRequest
|
||||
Committer User
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
// 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 clients
|
||||
|
||||
// Contributor represents a contributor to a repo.
|
||||
type Contributor struct {
|
||||
Companies []string
|
||||
User User
|
||||
Organizations []User
|
||||
NumContributions int
|
||||
}
|
@ -138,7 +138,7 @@ func (client *Client) ListReleases() ([]clients.Release, error) {
|
||||
}
|
||||
|
||||
// ListContributors implements RepoClient.ListContributors.
|
||||
func (client *Client) ListContributors() ([]clients.Contributor, error) {
|
||||
func (client *Client) ListContributors() ([]clients.User, error) {
|
||||
return client.contributors.getContributors()
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ type contributorsHandler struct {
|
||||
ctx context.Context
|
||||
errSetup error
|
||||
repourl *repoURL
|
||||
contributors []clients.Contributor
|
||||
contributors []clients.User
|
||||
}
|
||||
|
||||
func (handler *contributorsHandler) init(ctx context.Context, repourl *repoURL) {
|
||||
@ -58,11 +58,9 @@ func (handler *contributorsHandler) setup() error {
|
||||
if contrib.GetLogin() == "" {
|
||||
continue
|
||||
}
|
||||
contributor := clients.Contributor{
|
||||
contributor := clients.User{
|
||||
NumContributions: contrib.GetContributions(),
|
||||
User: clients.User{
|
||||
Login: contrib.GetLogin(),
|
||||
},
|
||||
Login: contrib.GetLogin(),
|
||||
}
|
||||
orgs, _, err := handler.ghClient.Organizations.List(handler.ctx, contrib.GetLogin(), nil)
|
||||
// This call can fail due to token scopes. So ignore error.
|
||||
@ -85,7 +83,7 @@ func (handler *contributorsHandler) setup() error {
|
||||
return handler.errSetup
|
||||
}
|
||||
|
||||
func (handler *contributorsHandler) getContributors() ([]clients.Contributor, error) {
|
||||
func (handler *contributorsHandler) getContributors() ([]clients.User, error) {
|
||||
if err := handler.setup(); err != nil {
|
||||
return nil, fmt.Errorf("error during contributorsHandler.setup: %w", err)
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ func (client *localDirClient) ListReleases() ([]clients.Release, error) {
|
||||
}
|
||||
|
||||
// ListContributors implements RepoClient.ListContributors.
|
||||
func (client *localDirClient) ListContributors() ([]clients.Contributor, error) {
|
||||
func (client *localDirClient) ListContributors() ([]clients.User, error) {
|
||||
return nil, fmt.Errorf("ListContributors: %w", clients.ErrUnsupportedFeature)
|
||||
}
|
||||
|
||||
|
@ -168,10 +168,10 @@ func (mr *MockRepoClientMockRecorder) ListCommits() *gomock.Call {
|
||||
}
|
||||
|
||||
// ListContributors mocks base method.
|
||||
func (m *MockRepoClient) ListContributors() ([]clients.Contributor, error) {
|
||||
func (m *MockRepoClient) ListContributors() ([]clients.User, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ListContributors")
|
||||
ret0, _ := ret[0].([]clients.Contributor)
|
||||
ret0, _ := ret[0].([]clients.User)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ type RepoClient interface {
|
||||
ListCommits() ([]Commit, error)
|
||||
ListIssues() ([]Issue, error)
|
||||
ListReleases() ([]Release, error)
|
||||
ListContributors() ([]Contributor, error)
|
||||
ListContributors() ([]User, error)
|
||||
ListSuccessfulWorkflowRuns(filename string) ([]WorkflowRun, error)
|
||||
ListCheckRunsForRef(ref string) ([]CheckRun, error)
|
||||
ListStatuses(ref string) ([]Status, error)
|
||||
|
@ -16,7 +16,10 @@ package clients
|
||||
|
||||
// User represents a Git user.
|
||||
type User struct {
|
||||
Login string
|
||||
Login string
|
||||
Companies []string
|
||||
Organizations []User
|
||||
NumContributions int
|
||||
}
|
||||
|
||||
// RepoAssociation is how a user is associated with a repository.
|
||||
|
@ -247,7 +247,7 @@ func (r *jsonScorecardRawResult) addContributorsRawResults(cr *checker.Contribut
|
||||
|
||||
for _, user := range cr.Users {
|
||||
u := jsonUser{
|
||||
Login: user.User.Login,
|
||||
Login: user.Login,
|
||||
NumContributions: user.NumContributions,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user