Skip to content

Commit ebd485a

Browse files
committed
Fix lint
Signed-off-by: Jamie Magee <[email protected]>
1 parent a9f1986 commit ebd485a

File tree

6 files changed

+53
-31
lines changed

6 files changed

+53
-31
lines changed

clients/azuredevopsrepo/branches.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"sync"
2121

2222
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/git"
23+
2324
"github.com/ossf/scorecard/v5/clients"
2425
)
2526

@@ -62,7 +63,6 @@ func (handler *branchesHandler) setup() error {
6263
handler.errSetup = nil
6364
})
6465
return handler.errSetup
65-
6666
}
6767

6868
func (handler *branchesHandler) getDefaultBranch() (*clients.BranchRef, error) {

clients/azuredevopsrepo/branches_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ import (
2424
)
2525

2626
func TestGetDefaultBranch(t *testing.T) {
27+
t.Parallel()
2728
tests := []struct {
28-
name string
2929
setupMock func() fnQueryBranch
30-
expectedError bool
30+
name string
3131
expectedName string
32+
expectedError bool
3233
}{
3334
{
3435
name: "successful branch retrieval",
@@ -53,6 +54,7 @@ func TestGetDefaultBranch(t *testing.T) {
5354

5455
for _, tt := range tests {
5556
t.Run(tt.name, func(t *testing.T) {
57+
t.Parallel()
5658
handler := &branchesHandler{
5759
queryBranch: tt.setupMock(),
5860
once: new(sync.Once),

clients/azuredevopsrepo/client.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,24 @@ import (
2626

2727
"github.com/microsoft/azure-devops-go-api/azuredevops/v7"
2828
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/git"
29+
2930
"github.com/ossf/scorecard/v5/clients"
3031
)
3132

3233
var (
33-
_ clients.RepoClient = &Client{}
34-
errInputRepoType = errors.New("input repo should be of type azuredevopsrepo.Repo")
34+
_ clients.RepoClient = &Client{}
35+
errInputRepoType = errors.New("input repo should be of type azuredevopsrepo.Repo")
36+
errDefaultBranchNotFound = errors.New("default branch not found")
3537
)
3638

3739
type Client struct {
38-
repourl *Repo
3940
azdoClient git.Client
40-
once sync.Once
41+
ctx context.Context
42+
repourl *Repo
4143
branches *branchesHandler
4244
commits *commitsHandler
43-
ctx context.Context
4445
commitDepth int
46+
once sync.Once
4547
}
4648

4749
func (c *Client) InitRepo(inputRepo clients.Repo, commitSHA string, commitDepth int) error {
@@ -135,7 +137,7 @@ func (c *Client) GetDefaultBranchName() (string, error) {
135137
return c.repourl.defaultBranch, nil
136138
}
137139

138-
return "", fmt.Errorf("%s", "default branch name is empty")
140+
return "", fmt.Errorf("%w", errDefaultBranchNotFound)
139141
}
140142

141143
func (c *Client) GetDefaultBranch() (*clients.BranchRef, error) {

clients/azuredevopsrepo/client_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424

2525
type mockGitClient struct {
2626
git.Client
27-
isDisabled bool
2827
err error
28+
isDisabled bool
2929
}
3030

3131
func (m *mockGitClient) GetRepository(ctx context.Context, args git.GetRepositoryArgs) (*git.GitRepository, error) {
@@ -36,10 +36,11 @@ func (m *mockGitClient) GetRepository(ctx context.Context, args git.GetRepositor
3636
}
3737

3838
func TestIsArchived(t *testing.T) {
39+
t.Parallel()
3940
tests := []struct {
41+
err error
4042
name string
4143
isDisabled bool
42-
err error
4344
want bool
4445
wantErr bool
4546
}{
@@ -65,6 +66,7 @@ func TestIsArchived(t *testing.T) {
6566

6667
for _, tt := range tests {
6768
t.Run(tt.name, func(t *testing.T) {
69+
t.Parallel()
6870
client := &Client{
6971
azdoClient: &mockGitClient{
7072
isDisabled: tt.isDisabled,

clients/azuredevopsrepo/commits.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,28 @@ package azuredevopsrepo
1616

1717
import (
1818
"context"
19+
"errors"
1920
"fmt"
2021
"sync"
2122

2223
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/git"
24+
2325
"github.com/ossf/scorecard/v5/clients"
2426
)
2527

28+
var errMultiplePullRequests = errors.New("expected 1 pull request for commit, got multiple")
29+
2630
type commitsHandler struct {
2731
gitClient git.Client
2832
ctx context.Context
29-
once *sync.Once
3033
errSetup error
34+
once *sync.Once
3135
repourl *Repo
3236
commitsRaw *[]git.GitCommitRef
3337
pullRequestsRaw *git.GitPullRequestQuery
34-
commitDepth int
3538
getCommits fnGetCommits
3639
getPullRequestQuery fnGetPullRequestQuery
40+
commitDepth int
3741
}
3842

3943
func (handler *commitsHandler) init(ctx context.Context, repourl *Repo, commitDepth int) {
@@ -81,8 +85,8 @@ func (handler *commitsHandler) setup() error {
8185
}
8286

8387
commitIds := make([]string, len(*commits))
84-
for i, commit := range *commits {
85-
commitIds[i] = *commit.CommitId
88+
for i := range *commits {
89+
commitIds[i] = *(*commits)[i].CommitId
8690
}
8791

8892
pullRequestQuery := git.GetPullRequestQueryArgs{
@@ -117,7 +121,8 @@ func (handler *commitsHandler) listCommits() ([]clients.Commit, error) {
117121
}
118122

119123
commits := make([]clients.Commit, len(*handler.commitsRaw))
120-
for i, commit := range *handler.commitsRaw {
124+
for i := range *handler.commitsRaw {
125+
commit := &(*handler.commitsRaw)[i]
121126
commits[i] = clients.Commit{
122127
SHA: *commit.CommitId,
123128
Message: *commit.Comment,
@@ -134,13 +139,14 @@ func (handler *commitsHandler) listCommits() ([]clients.Commit, error) {
134139
return nil, fmt.Errorf("error during commitsHandler.listPullRequests: %w", err)
135140
}
136141

137-
for i, commit := range commits {
142+
for i := range commits {
143+
commit := &commits[i]
138144
associatedPullRequest, ok := pullRequests[commit.SHA]
139145
if !ok {
140146
continue
141147
}
142148

143-
commits[i].AssociatedMergeRequest = associatedPullRequest
149+
commit.AssociatedMergeRequest = associatedPullRequest
144150
}
145151

146152
return commits, nil
@@ -159,7 +165,7 @@ func (handler *commitsHandler) listPullRequests() (map[string]clients.PullReques
159165
}
160166

161167
if len(azdoPullRequests) > 1 {
162-
return nil, fmt.Errorf("expected 1 pull request for commit %s, got %d", commit, len(azdoPullRequests))
168+
return nil, errMultiplePullRequests
163169
}
164170

165171
azdoPullRequest := azdoPullRequests[0]

cmd/root.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,28 @@ func printCheckResults(enabledChecks checker.CheckNameToFnMap) {
221221
func makeRepo(uri string) (clients.Repo, error) {
222222
var repo clients.Repo
223223
var errGitHub, errGitLab, errAzureDevOps error
224-
if repo, errGitHub = githubrepo.MakeGithubRepo(uri); errGitHub != nil {
225-
if repo, errGitLab = gitlabrepo.MakeGitlabRepo(uri); errGitLab != nil {
226-
_, experimental := os.LookupEnv("SCORECARD_EXPERIMENTAL")
227-
if experimental {
228-
repo, errAzureDevOps = azuredevopsrepo.MakeAzureDevOpsRepo(uri)
229-
if errAzureDevOps != nil {
230-
return nil, fmt.Errorf("unable to parse as github, gitlab, or azuredevops: %w", errors.Join(errGitHub, errGitLab, errAzureDevOps))
231-
}
232-
} else {
233-
return nil, fmt.Errorf("unable to parse as github or gitlab: %w", errors.Join(errGitHub, errGitLab))
234-
}
224+
var compositeErr error
225+
226+
repo, errGitHub = githubrepo.MakeGithubRepo(uri)
227+
if errGitHub == nil {
228+
return repo, nil
229+
}
230+
compositeErr = errors.Join(compositeErr, errGitHub)
231+
232+
repo, errGitLab = gitlabrepo.MakeGitlabRepo(uri)
233+
if errGitLab == nil {
234+
return repo, nil
235+
}
236+
compositeErr = errors.Join(compositeErr, errGitLab)
237+
238+
_, experimental := os.LookupEnv("SCORECARD_EXPERIMENTAL")
239+
if experimental {
240+
repo, errAzureDevOps = azuredevopsrepo.MakeAzureDevOpsRepo(uri)
241+
if errAzureDevOps == nil {
242+
return repo, nil
235243
}
244+
compositeErr = errors.Join(compositeErr, errAzureDevOps)
236245
}
237-
return repo, nil
246+
247+
return nil, fmt.Errorf("unable to parse as github, gitlab, or azuredevops: %w", compositeErr)
238248
}

0 commit comments

Comments
 (0)