diff --git a/checker/raw_result.go b/checker/raw_result.go index cb50e86cff7..c0c9eeeddc4 100644 --- a/checker/raw_result.go +++ b/checker/raw_result.go @@ -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 diff --git a/checks/contributors_test.go b/checks/contributors_test.go index c0cb205692b..df81343db9b 100644 --- a/checks/contributors_test.go +++ b/checks/contributors_test.go @@ -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 } diff --git a/checks/raw/contributors.go b/checks/raw/contributors.go index b02e2b6443a..9f149abad5f 100644 --- a/checks/raw/contributors.go +++ b/checks/raw/contributors.go @@ -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, } diff --git a/clients/commit.go b/clients/commit.go index 3ff5cc13994..184eeeda6d0 100644 --- a/clients/commit.go +++ b/clients/commit.go @@ -21,6 +21,6 @@ type Commit struct { CommittedDate time.Time Message string SHA string - Committer User AssociatedMergeRequest PullRequest + Committer User } diff --git a/clients/contributor.go b/clients/contributor.go deleted file mode 100644 index 20aab69f878..00000000000 --- a/clients/contributor.go +++ /dev/null @@ -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 -} diff --git a/clients/githubrepo/client.go b/clients/githubrepo/client.go index 3394674d6b7..4dbb8894bae 100644 --- a/clients/githubrepo/client.go +++ b/clients/githubrepo/client.go @@ -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() } diff --git a/clients/githubrepo/contributors.go b/clients/githubrepo/contributors.go index 25d83d9a686..7b25adce8c5 100644 --- a/clients/githubrepo/contributors.go +++ b/clients/githubrepo/contributors.go @@ -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) } diff --git a/clients/localdir/client.go b/clients/localdir/client.go index 0a4c5a61a23..158161662d5 100644 --- a/clients/localdir/client.go +++ b/clients/localdir/client.go @@ -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) } diff --git a/clients/mockclients/repo_client.go b/clients/mockclients/repo_client.go index 8c57778b5b2..71bc7cbd399 100644 --- a/clients/mockclients/repo_client.go +++ b/clients/mockclients/repo_client.go @@ -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 } diff --git a/clients/repo_client.go b/clients/repo_client.go index 8957e883c8a..78f51c94918 100644 --- a/clients/repo_client.go +++ b/clients/repo_client.go @@ -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) diff --git a/clients/user.go b/clients/user.go index a7508d7cd14..e342605aeeb 100644 --- a/clients/user.go +++ b/clients/user.go @@ -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. diff --git a/pkg/json_raw_results.go b/pkg/json_raw_results.go index 8d756456e1d..7d94d9aee9f 100644 --- a/pkg/json_raw_results.go +++ b/pkg/json_raw_results.go @@ -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, }