Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Replace clients.Contributor with clients.User #1957

Merged
merged 2 commits into from May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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()
}

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 @@ -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)
}

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