Skip to content

Commit

Permalink
Fix few linter warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Soule BA <[email protected]>
  • Loading branch information
souleb committed Nov 19, 2021
1 parent f3378ec commit e5c9808
Show file tree
Hide file tree
Showing 34 changed files with 140 additions and 107 deletions.
8 changes: 4 additions & 4 deletions github/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ var _ = Describe("GitHub Provider", func() {
if err == nil && !actionTaken {
err = errors.New("expecting action taken to be true")
}
return retryOp.Retry(err, fmt.Sprintf("reconcile user repository: %s", repoRef.RepositoryName))
return retryOp.IsRetryable(err, fmt.Sprintf("reconcile user repository: %s", repoRef.RepositoryName))
}, time.Second*90, retryOp.Interval()).Should(BeTrue())

Expect(actionTaken).To(BeTrue())
Expand All @@ -410,7 +410,7 @@ var _ = Describe("GitHub Provider", func() {
if err == nil && !actionTaken {
err = errors.New("expecting action taken to be true")
}
return retryOp.Retry(err, fmt.Sprintf("reconcile repository: %s", newRepo.Repository().GetRepository()))
return retryOp.IsRetryable(err, fmt.Sprintf("reconcile repository: %s", newRepo.Repository().GetRepository()))
}, retryOp.Timeout(), retryOp.Interval()).Should(BeTrue())

Expect(actionTaken).To(BeTrue())
Expand All @@ -435,7 +435,7 @@ var _ = Describe("GitHub Provider", func() {
Eventually(func() bool {
var err error
userRepo, err = c.UserRepositories().Get(ctx, userRepoRef)
return retryOp.Retry(err, fmt.Sprintf("get user repository: %s", userRepoRef.RepositoryName))
return retryOp.IsRetryable(err, fmt.Sprintf("get user repository: %s", userRepoRef.RepositoryName))
}, retryOp.Timeout(), retryOp.Interval()).Should(BeTrue())

defaultBranch := userRepo.Get().DefaultBranch
Expand All @@ -448,7 +448,7 @@ var _ = Describe("GitHub Provider", func() {
if err == nil && len(commits) == 0 {
err = errors.New("empty commits list")
}
return retryOp.Retry(err, fmt.Sprintf("get commits, repository: %s", userRepo.Repository().GetRepository()))
return retryOp.IsRetryable(err, fmt.Sprintf("get commits, repository: %s", userRepo.Repository().GetRepository()))
}, retryOp.Timeout(), retryOp.Interval()).Should(BeTrue())

latestCommit := commits[0]
Expand Down
2 changes: 1 addition & 1 deletion gitlab/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ func (c *Client) UserRepositories() gitprovider.UserRepositoriesClient {
}

// HasTokenPermission returns true if the given token has the given permissions.
func (c *Client) HasTokenPermission(ctx context.Context, permission gitprovider.TokenPermission) (bool, error) {
func (c *Client) HasTokenPermission(_ context.Context, _ gitprovider.TokenPermission) (bool, error) {
return false, gitprovider.ErrNoProviderSupport
}
3 changes: 2 additions & 1 deletion gitlab/client_repository_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package gitlab

import (
"context"

"github.com/fluxcd/go-git-providers/gitprovider"
"github.com/xanzy/go-gitlab"
)
Expand All @@ -32,7 +33,7 @@ type BranchClient struct {
}

// Create creates a branch with the given specifications.
func (c *BranchClient) Create(ctx context.Context, branch, sha string) error {
func (c *BranchClient) Create(_ context.Context, branch, sha string) error {

ref := &gitlab.CreateBranchOptions{
Ref: &sha,
Expand Down
10 changes: 5 additions & 5 deletions gitlab/client_repository_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type CommitClient struct {
}

// ListPage lists repository commits of the given page and page size.
func (c *CommitClient) ListPage(ctx context.Context, branch string, perPage, page int) ([]gitprovider.Commit, error) {
dks, err := c.listPage(ctx, branch, perPage, page)
func (c *CommitClient) ListPage(_ context.Context, branch string, perPage, page int) ([]gitprovider.Commit, error) {
dks, err := c.listPage(branch, perPage, page)
if err != nil {
return nil, err
}
Expand All @@ -47,9 +47,9 @@ func (c *CommitClient) ListPage(ctx context.Context, branch string, perPage, pag
return commits, nil
}

func (c *CommitClient) listPage(ctx context.Context, branch string, perPage, page int) ([]*commitType, error) {
func (c *CommitClient) listPage(branch string, perPage, page int) ([]*commitType, error) {
// GET /repos/{owner}/{repo}/commits
apiObjs, err := c.c.ListCommitsPage(ctx, getRepoPath(c.ref), branch, perPage, page)
apiObjs, err := c.c.ListCommitsPage(getRepoPath(c.ref), branch, perPage, page)
if err != nil {
return nil, err
}
Expand All @@ -64,7 +64,7 @@ func (c *CommitClient) listPage(ctx context.Context, branch string, perPage, pag
}

// Create creates a commit with the given specifications.
func (c *CommitClient) Create(ctx context.Context, branch string, message string, files []gitprovider.CommitFile) (gitprovider.Commit, error) {
func (c *CommitClient) Create(_ context.Context, branch string, message string, files []gitprovider.CommitFile) (gitprovider.Commit, error) {

if len(files) == 0 {
return nil, fmt.Errorf("no files added")
Expand Down
24 changes: 12 additions & 12 deletions gitlab/client_repository_deploykey.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ type DeployKeyClient struct {
// Get returns the repository at the given path.
//
// ErrNotFound is returned if the resource does not exist.
func (c *DeployKeyClient) Get(ctx context.Context, deployKeyName string) (gitprovider.DeployKey, error) {
return c.get(ctx, deployKeyName)
func (c *DeployKeyClient) Get(_ context.Context, deployKeyName string) (gitprovider.DeployKey, error) {
return c.get(deployKeyName)
}

func (c *DeployKeyClient) get(ctx context.Context, deployKeyName string) (*deployKey, error) {
deployKeys, err := c.list(ctx)
func (c *DeployKeyClient) get(deployKeyName string) (*deployKey, error) {
deployKeys, err := c.list()
if err != nil {
return nil, err
}
Expand All @@ -59,8 +59,8 @@ func (c *DeployKeyClient) get(ctx context.Context, deployKeyName string) (*deplo
//
// List returns all available repository deploy keys for the given type,
// using multiple paginated requests if needed.
func (c *DeployKeyClient) List(ctx context.Context) ([]gitprovider.DeployKey, error) {
dks, err := c.list(ctx)
func (c *DeployKeyClient) List(_ context.Context) ([]gitprovider.DeployKey, error) {
dks, err := c.list()
if err != nil {
return nil, err
}
Expand All @@ -72,9 +72,9 @@ func (c *DeployKeyClient) List(ctx context.Context) ([]gitprovider.DeployKey, er
return keys, nil
}

func (c *DeployKeyClient) list(ctx context.Context) ([]*deployKey, error) {
func (c *DeployKeyClient) list() ([]*deployKey, error) {
// GET /repos/{owner}/{repo}/keys
apiObjs, err := c.c.ListKeys(ctx, getRepoPath(c.ref))
apiObjs, err := c.c.ListKeys(getRepoPath(c.ref))
if err != nil {
return nil, err
}
Expand All @@ -92,8 +92,8 @@ func (c *DeployKeyClient) list(ctx context.Context) ([]*deployKey, error) {
// Create creates a deploy key with the given specifications.
//
// ErrAlreadyExists will be returned if the resource already exists.
func (c *DeployKeyClient) Create(ctx context.Context, req gitprovider.DeployKeyInfo) (gitprovider.DeployKey, error) {
apiObj, err := createDeployKey(ctx, c.c, c.ref, req)
func (c *DeployKeyClient) Create(_ context.Context, req gitprovider.DeployKeyInfo) (gitprovider.DeployKey, error) {
apiObj, err := createDeployKey(c.c, c.ref, req)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -138,12 +138,12 @@ func (c *DeployKeyClient) Reconcile(ctx context.Context, req gitprovider.DeployK
return actual, true, actual.Update(ctx)
}

func createDeployKey(ctx context.Context, c gitlabClient, ref gitprovider.RepositoryRef, req gitprovider.DeployKeyInfo) (*gitlab.DeployKey, error) {
func createDeployKey(c gitlabClient, ref gitprovider.RepositoryRef, req gitprovider.DeployKeyInfo) (*gitlab.DeployKey, error) {
// First thing, validate and default the request to ensure a valid and fully-populated object
// (to minimize any possible diffs between desired and actual state)
if err := gitprovider.ValidateAndDefaultInfo(&req); err != nil {
return nil, err
}

return c.CreateKey(ctx, fmt.Sprintf("%s/%s", ref.GetIdentity(), ref.GetRepository()), deployKeyToAPI(&req))
return c.CreateKey(fmt.Sprintf("%s/%s", ref.GetIdentity(), ref.GetRepository()), deployKeyToAPI(&req))
}
8 changes: 4 additions & 4 deletions gitlab/client_repository_pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type PullRequestClient struct {
}

// List lists all pull requests in the repository
func (c *PullRequestClient) List(ctx context.Context) ([]gitprovider.PullRequest, error) {
func (c *PullRequestClient) List(_ context.Context) ([]gitprovider.PullRequest, error) {
mrs, _, err := c.c.Client().MergeRequests.ListProjectMergeRequests(getRepoPath(c.ref), nil)
if err != nil {
return nil, err
Expand All @@ -54,7 +54,7 @@ func (c *PullRequestClient) List(ctx context.Context) ([]gitprovider.PullRequest
}

// Create creates a pull request with the given specifications.
func (c *PullRequestClient) Create(ctx context.Context, title, branch, baseBranch, description string) (gitprovider.PullRequest, error) {
func (c *PullRequestClient) Create(_ context.Context, title, branch, baseBranch, description string) (gitprovider.PullRequest, error) {

prOpts := &gitlab.CreateMergeRequestOptions{
Title: &title,
Expand All @@ -72,7 +72,7 @@ func (c *PullRequestClient) Create(ctx context.Context, title, branch, baseBranc
}

// Get retrieves an existing pull request by number
func (c *PullRequestClient) Get(ctx context.Context, number int) (gitprovider.PullRequest, error) {
func (c *PullRequestClient) Get(_ context.Context, number int) (gitprovider.PullRequest, error) {

mr, _, err := c.c.Client().MergeRequests.GetMergeRequest(getRepoPath(c.ref), number, &gitlab.GetMergeRequestsOptions{})
if err != nil {
Expand All @@ -83,7 +83,7 @@ func (c *PullRequestClient) Get(ctx context.Context, number int) (gitprovider.Pu
}

// Merge merges a pull request with the given specifications.
func (c *PullRequestClient) Merge(ctx context.Context, number int, mergeMethod gitprovider.MergeMethod, message string) error {
func (c *PullRequestClient) Merge(_ context.Context, number int, mergeMethod gitprovider.MergeMethod, message string) error {
if err := c.waitForMergeRequestToBeMergeable(number); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion gitlab/client_repository_teamaccess.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *TeamAccessClient) Create(ctx context.Context, req gitprovider.TeamAcces
if err != nil {
return nil, err
}
if err := c.c.ShareProject(ctx, getRepoPath(c.ref), group.ID, gitlabPermission); err != nil {
if err := c.c.ShareProject(getRepoPath(c.ref), group.ID, gitlabPermission); err != nil {
return nil, err
}

Expand Down
24 changes: 12 additions & 12 deletions gitlab/gitlabclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,28 @@ type gitlabClient interface {

// ListKeys is a wrapper for "GET /projects/{project}/deploy_keys".
// This function handles pagination, HTTP error wrapping, and validates the server result.
ListKeys(ctx context.Context, projectName string) ([]*gitlab.DeployKey, error)
ListKeys(projectName string) ([]*gitlab.DeployKey, error)
// CreateProjectKey is a wrapper for "POST /projects/{project}/deploy_keys".
// This function handles HTTP error wrapping, and validates the server result.
CreateKey(ctx context.Context, projectName string, req *gitlab.DeployKey) (*gitlab.DeployKey, error)
CreateKey(projectName string, req *gitlab.DeployKey) (*gitlab.DeployKey, error)
// DeleteKey is a wrapper for "DELETE /projects/{project}/deploy_keys/{key_id}".
// This function handles HTTP error wrapping.
DeleteKey(ctx context.Context, projectName string, keyID int) error
DeleteKey(projectName string, keyID int) error

// Team related methods

// ShareGroup is a wrapper for ""
// This function handles HTTP error wrapping, and validates the server result.
ShareProject(ctx context.Context, projectName string, groupID, groupAccess int) error
ShareProject(projectName string, groupID, groupAccess int) error
// UnshareProject is a wrapper for ""
// This function handles HTTP error wrapping, and validates the server result.
UnshareProject(ctx context.Context, projectName string, groupID int) error
UnshareProject(projectName string, groupID int) error

// Commits

// ListCommitsPage is a wrapper for "GET /projects/{project}/repository/commits".
// This function handles pagination, HTTP error wrapping.
ListCommitsPage(ctx context.Context, projectName, branch string, perPage int, page int) ([]*gitlab.Commit, error)
ListCommitsPage(projectName, branch string, perPage int, page int) ([]*gitlab.Commit, error)
}

// gitlabClientImpl is a wrapper around *gitlab.Client, which implements higher-level methods,
Expand Down Expand Up @@ -329,7 +329,7 @@ func (c *gitlabClientImpl) DeleteProject(ctx context.Context, projectName string
return err
}

func (c *gitlabClientImpl) ListKeys(ctx context.Context, projectName string) ([]*gitlab.DeployKey, error) {
func (c *gitlabClientImpl) ListKeys(projectName string) ([]*gitlab.DeployKey, error) {
apiObjs := []*gitlab.DeployKey{}
opts := &gitlab.ListProjectDeployKeysOptions{}
err := allDeployKeyPages(opts, func() (*gitlab.Response, error) {
Expand All @@ -350,7 +350,7 @@ func (c *gitlabClientImpl) ListKeys(ctx context.Context, projectName string) ([]
return apiObjs, nil
}

func (c *gitlabClientImpl) CreateKey(ctx context.Context, projectName string, req *gitlab.DeployKey) (*gitlab.DeployKey, error) {
func (c *gitlabClientImpl) CreateKey(projectName string, req *gitlab.DeployKey) (*gitlab.DeployKey, error) {
opts := &gitlab.AddDeployKeyOptions{
Title: &req.Title,
Key: &req.Key,
Expand All @@ -367,13 +367,13 @@ func (c *gitlabClientImpl) CreateKey(ctx context.Context, projectName string, re
return apiObj, nil
}

func (c *gitlabClientImpl) DeleteKey(ctx context.Context, projectName string, keyID int) error {
func (c *gitlabClientImpl) DeleteKey(projectName string, keyID int) error {
// DELETE /projects/{project}/deploy_keys
_, err := c.c.DeployKeys.DeleteDeployKey(projectName, keyID)
return handleHTTPError(err)
}

func (c *gitlabClientImpl) ShareProject(ctx context.Context, projectName string, groupIDObj, groupAccessObj int) error {
func (c *gitlabClientImpl) ShareProject(projectName string, groupIDObj, groupAccessObj int) error {
groupAccess := gitlab.AccessLevel(gitlab.AccessLevelValue(groupAccessObj))
groupID := &groupIDObj
opt := &gitlab.ShareWithGroupOptions{
Expand All @@ -385,12 +385,12 @@ func (c *gitlabClientImpl) ShareProject(ctx context.Context, projectName string,
return handleHTTPError(err)
}

func (c *gitlabClientImpl) UnshareProject(ctx context.Context, projectName string, groupID int) error {
func (c *gitlabClientImpl) UnshareProject(projectName string, groupID int) error {
_, err := c.c.Projects.DeleteSharedProjectFromGroup(projectName, groupID)
return handleHTTPError(err)
}

func (c *gitlabClientImpl) ListCommitsPage(ctx context.Context, projectName string, branch string, perPage int, page int) ([]*gitlab.Commit, error) {
func (c *gitlabClientImpl) ListCommitsPage(projectName string, branch string, perPage int, page int) ([]*gitlab.Commit, error) {
apiObjs := make([]*gitlab.Commit, 0)

opts := gitlab.ListCommitsOptions{
Expand Down
6 changes: 3 additions & 3 deletions gitlab/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ var _ = Describe("GitLab Provider", func() {
AutoInit: gitprovider.BoolVar(true),
LicenseTemplate: gitprovider.LicenseTemplateVar(gitprovider.LicenseTemplateMIT),
})
return retryOp.Retry(err, fmt.Sprintf("reconcile org repository: %s", repoRef.RepositoryName))
return retryOp.IsRetryable(err, fmt.Sprintf("reconcile org repository: %s", repoRef.RepositoryName))
}, retryOp.Timeout(), retryOp.Interval()).Should(BeTrue())

Expect(actionTaken).To(BeTrue())
Expand Down Expand Up @@ -722,7 +722,7 @@ var _ = Describe("GitLab Provider", func() {
AutoInit: gitprovider.BoolVar(true),
LicenseTemplate: gitprovider.LicenseTemplateVar(gitprovider.LicenseTemplateMIT),
})
return retryOp.Retry(err, fmt.Sprintf("new user repository: %s", repoRef.RepositoryName))
return retryOp.IsRetryable(err, fmt.Sprintf("new user repository: %s", repoRef.RepositoryName))
}, retryOp.Timeout(), retryOp.Interval()).Should(BeTrue())

// Expect the create to succeed, and have modified the state. Also validate the newRepo data
Expand Down Expand Up @@ -757,7 +757,7 @@ var _ = Describe("GitLab Provider", func() {
if err == nil && len(commits) == 0 {
err = errors.New("empty commits list")
}
return retryOp.Retry(err, fmt.Sprintf("get commits, repository: %s", userRepo.Repository().GetRepository()))
return retryOp.IsRetryable(err, fmt.Sprintf("get commits, repository: %s", userRepo.Repository().GetRepository()))
}, retryOp.Timeout(), retryOp.Interval()).Should(BeTrue())

latestCommit := commits[0]
Expand Down
14 changes: 7 additions & 7 deletions gitlab/resource_deploykey.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ func (dk *deployKey) Update(ctx context.Context) error {
if err := dk.Delete(ctx); err != nil {
return err
}
return dk.createIntoSelf(ctx)
return dk.createIntoSelf()
}

// Delete deletes a deploy key from the repository.
//
// ErrNotFound is returned if the resource does not exist.
func (dk *deployKey) Delete(ctx context.Context) error {
func (dk *deployKey) Delete(_ context.Context) error {
// We can use the same DeployKey ID that we got from the GET calls. Make sure it's non-nil.
// This _should never_ happen, but just check for it anyways to avoid panicing.
if dk.k.ID == 0 {
return fmt.Errorf("didn't expect ID to be 0: %w", gitprovider.ErrUnexpectedEvent)
}

return dk.c.c.DeleteKey(ctx, getRepoPath(dk.c.ref), dk.k.ID)
return dk.c.c.DeleteKey(getRepoPath(dk.c.ref), dk.k.ID)
}

// Reconcile makes sure the desired state in this object (called "req" here) becomes
Expand All @@ -103,11 +103,11 @@ func (dk *deployKey) Delete(ctx context.Context) error {
//
// The internal API object will be overridden with the received server data if actionTaken == true.
func (dk *deployKey) Reconcile(ctx context.Context) (bool, error) {
actual, err := dk.c.get(ctx, dk.k.Title)
actual, err := dk.c.get(dk.k.Title)
if err != nil {
// Create if not found
if errors.Is(err, gitprovider.ErrNotFound) {
return true, dk.createIntoSelf(ctx)
return true, dk.createIntoSelf()
}

// Unexpected path, Get should succeed or return NotFound
Expand All @@ -126,9 +126,9 @@ func (dk *deployKey) Reconcile(ctx context.Context) (bool, error) {
return true, dk.Update(ctx)
}

func (dk *deployKey) createIntoSelf(ctx context.Context) error {
func (dk *deployKey) createIntoSelf() error {
// POST /repos/{owner}/{repo}/keys
apiObj, err := dk.c.c.CreateKey(ctx, getRepoPath(dk.c.ref), &dk.k)
apiObj, err := dk.c.c.CreateKey(getRepoPath(dk.c.ref), &dk.k)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions gitlab/resource_teamaccess.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (ta *teamAccess) Delete(ctx context.Context) error {
if err != nil {
return err
}
return ta.c.c.UnshareProject(ctx, getRepoPath(ta.c.ref), group.ID)
return ta.c.c.UnshareProject(getRepoPath(ta.c.ref), group.ID)
}

func (ta *teamAccess) Update(ctx context.Context) error {
Expand All @@ -74,7 +74,7 @@ func (ta *teamAccess) Update(ctx context.Context) error {
if err != nil {
return err
}
err = ta.c.c.UnshareProject(ctx, getRepoPath(ta.c.ref), group.ID)
err = ta.c.c.UnshareProject(getRepoPath(ta.c.ref), group.ID)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit e5c9808

Please sign in to comment.