Skip to content

Commit

Permalink
fix linter and unit-test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nathaniel.wert committed Sep 23, 2022
1 parent ebdd392 commit 259fde0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
12 changes: 10 additions & 2 deletions checks/raw/branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/ossf/scorecard/v4/checker"
"github.com/ossf/scorecard/v4/clients"
mockrepo "github.com/ossf/scorecard/v4/clients/mockclients"
)

const master = "master"
Expand Down Expand Up @@ -73,8 +74,15 @@ func BranchProtection(c clients.RepoClient) (checker.BranchProtectionsData, erro
}

// TODO: if this is a sha, get the associated branch. for now, ignore.
if commit.MatchString(release.TargetCommitish) && !strings.Contains(c.URI(), "gitlab.") {
continue
switch c.(type) {
case *mockrepo.MockRepoClient:
if commit.MatchString(release.TargetCommitish) {
continue
}
default:
if commit.MatchString(release.TargetCommitish) && !strings.Contains(c.URI(), "gitlab.") {
continue
}
}

if branches.contains(release.TargetCommitish) ||
Expand Down
6 changes: 3 additions & 3 deletions clients/gitlabrepo/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (handler *branchesHandler) init(repourl *repoURL) {
handler.once = new(sync.Once)
}


// nolint: nestif
func (handler *branchesHandler) setup() error {
handler.once.Do(func() {
Expand Down Expand Up @@ -77,7 +76,7 @@ func (handler *branchesHandler) setup() error {

projectStatusChecks, resp, err := handler.glClient.ExternalStatusChecks.ListProjectStatusChecks(
handler.repourl.projectID, &gitlab.ListOptions{})

if err != nil && resp.StatusCode != 404 && resp.StatusCode != 401 {
handler.errSetup = fmt.Errorf("request for external status checks failed with error %w", err)
return
Expand Down Expand Up @@ -111,6 +110,7 @@ func (handler *branchesHandler) getDefaultBranch() (*clients.BranchRef, error) {
return handler.defaultBranchRef, nil
}

// nolint: gocognit, nestif
func (handler *branchesHandler) getBranch(commitOrBranch string) (*clients.BranchRef, error) {
// If the given string is a branch name then the branch can be found by simply getting branch by it's name.
bran, resp, err := handler.glClient.Branches.GetBranch(handler.repourl.projectID, commitOrBranch)
Expand Down Expand Up @@ -190,7 +190,7 @@ func (handler *branchesHandler) getBranch(commitOrBranch string) (*clients.Branc

projectStatusChecks, resp, err := handler.glClient.ExternalStatusChecks.ListProjectStatusChecks(
handler.repourl.projectID, &gitlab.ListOptions{})

// Project Status Checks are only allowed for GitLab ultimate members so we will assume they are
// null if user does not have permissions.
if err != nil && resp.StatusCode != 404 && resp.StatusCode != 401 {
Expand Down
3 changes: 1 addition & 2 deletions clients/gitlabrepo/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func (handler *commitsHandler) init(repourl *repoURL) {
handler.once = new(sync.Once)
}


// nolint: gocognit
// nolint: gocognit, nestif
func (handler *commitsHandler) setup() error {
handler.once.Do(func() {
commits, _, err := handler.glClient.Commits.ListCommits(handler.repourl.projectID, &gitlab.ListCommitsOptions{})
Expand Down
2 changes: 1 addition & 1 deletion clients/gitlabrepo/tarball_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func setup(inputFile string) (tarballHandler, error) {
return tarballHandler, nil
}

//nolint: gocognit
// nolint: gocognit
func TestExtractTarball(t *testing.T) {
t.Parallel()
testcases := []struct {
Expand Down

0 comments on commit 259fde0

Please sign in to comment.