Skip to content

Commit

Permalink
Replace clients.Contributor with clients.User
Browse files Browse the repository at this point in the history
  • Loading branch information
azeemsgoogle committed May 25, 2022
1 parent 25c7e1c commit aecf394
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 47 deletions.
2 changes: 1 addition & 1 deletion checker/raw_result.go
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions checks/contributors_test.go
Expand Up @@ -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{
{
Expand All @@ -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"},
Expand Down Expand Up @@ -140,15 +140,15 @@ func TestContributors(t *testing.T) {
{
err: nil,
name: "No contributors",
contrib: []clients.Contributor{},
contrib: []clients.User{},
expected: checker.CheckResult{
Score: 0,
},
},
{
err: errors.New("error"),
name: "Error getting contributors",
contrib: []clients.Contributor{},
contrib: []clients.User{},
expected: checker.CheckResult{
Score: -1,
},
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions checks/raw/contributors.go
Expand Up @@ -24,16 +24,16 @@ 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 {
return checker.ContributorsData{}, fmt.Errorf("Client.Repositories.ListContributors: %w", err)
}

for _, contrib := range contribs {
user := clients.Contributor{
User: contrib.User,
user := clients.User{
Login: contrib.Login,
NumContributions: contrib.NumContributions,
}

Expand Down
2 changes: 1 addition & 1 deletion clients/commit.go
Expand Up @@ -21,6 +21,6 @@ type Commit struct {
CommittedDate time.Time
Message string
SHA string
Committer User
AssociatedMergeRequest PullRequest
Committer User
}
23 changes: 0 additions & 23 deletions clients/contributor.go

This file was deleted.

2 changes: 1 addition & 1 deletion clients/githubrepo/client.go
Expand Up @@ -135,7 +135,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()
}

Expand Down
10 changes: 4 additions & 6 deletions clients/githubrepo/contributors.go
Expand Up @@ -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) {
Expand All @@ -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.
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion clients/localdir/client.go
Expand Up @@ -182,7 +182,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)
}

Expand Down
4 changes: 2 additions & 2 deletions clients/mockclients/repo_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clients/repo_client.go
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion clients/user.go
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/json_raw_results.go
Expand Up @@ -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,
}

Expand Down

0 comments on commit aecf394

Please sign in to comment.