From 8ef3c1d9b36be6def036550ae62083d8f5b4f565 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Tue, 2 Jul 2019 16:10:39 +0200 Subject: [PATCH] gitsources: fix linter errors Fix errors reported by default golangci-lint linters --- internal/gitsources/agolagit/agolagit.go | 13 ------------- internal/gitsources/gitea/parse.go | 4 +++- internal/gitsources/github/parse.go | 3 --- internal/gitsources/gitlab/gitlab.go | 12 +++--------- internal/gitsources/gitlab/parse.go | 5 ----- 5 files changed, 6 insertions(+), 31 deletions(-) diff --git a/internal/gitsources/agolagit/agolagit.go b/internal/gitsources/agolagit/agolagit.go index 7aa1311..111d179 100644 --- a/internal/gitsources/agolagit/agolagit.go +++ b/internal/gitsources/agolagit/agolagit.go @@ -16,7 +16,6 @@ package agolagit import ( "crypto/tls" - "encoding/json" "fmt" "io" "io/ioutil" @@ -114,18 +113,6 @@ func (c *Client) getResponse(method, path string, query url.Values, header http. return resp, nil } -func (c *Client) getParsedResponse(method, path string, query url.Values, header http.Header, ibody io.Reader, obj interface{}) (*http.Response, error) { - resp, err := c.getResponse(method, path, query, header, ibody) - if err != nil { - return resp, err - } - defer resp.Body.Close() - - d := json.NewDecoder(resp.Body) - - return resp, d.Decode(obj) -} - func (c *Client) GetUserInfo() (*gitsource.UserInfo, error) { return nil, nil } diff --git a/internal/gitsources/gitea/parse.go b/internal/gitsources/gitea/parse.go index ab94c50..5150854 100644 --- a/internal/gitsources/gitea/parse.go +++ b/internal/gitsources/gitea/parse.go @@ -60,7 +60,9 @@ func (c *Client) ParseWebhook(r *http.Request, secret string) (*types.WebhookDat return nil, errors.Errorf("wrong webhook signature") } h := hmac.New(sha256.New, []byte(secret)) - h.Write(data) + if _, err := h.Write(data); err != nil { + return nil, errors.Errorf("failed to calculate webhook signature") + } cs := h.Sum(nil) if !hmac.Equal(cs, ds) { return nil, errors.Errorf("wrong webhook signature") diff --git a/internal/gitsources/github/parse.go b/internal/gitsources/github/parse.go index 679b05b..1e2705c 100644 --- a/internal/gitsources/github/parse.go +++ b/internal/gitsources/github/parse.go @@ -28,9 +28,6 @@ import ( ) const ( - hookPush = "push" - hookPullRequest = "pull_request" - prStateOpen = "open" prActionOpen = "opened" diff --git a/internal/gitsources/gitlab/gitlab.go b/internal/gitsources/gitlab/gitlab.go index 84031ea..93bd044 100644 --- a/internal/gitsources/gitlab/gitlab.go +++ b/internal/gitsources/gitlab/gitlab.go @@ -90,7 +90,9 @@ func New(opts Opts) (*Client, error) { } httpClient := &http.Client{Transport: transport} client := gitlab.NewOAuthClient(httpClient, opts.Token) - client.SetBaseURL(opts.APIURL) + if err := client.SetBaseURL(opts.APIURL); err != nil { + return nil, errors.Errorf("failed to set gitlab client base url: %w", err) + } return &Client{ client: client, @@ -303,10 +305,6 @@ func (c *Client) GetRef(repopath, ref string) (*gitsource.Ref, error) { return nil, err } - if err != nil { - return nil, err - } - return &gitsource.Ref{ Ref: ref, CommitSHA: remoteBranch.Commit.ID, @@ -319,10 +317,6 @@ func (c *Client) GetRef(repopath, ref string) (*gitsource.Ref, error) { return nil, err } - if err != nil { - return nil, err - } - return &gitsource.Ref{ Ref: ref, CommitSHA: remoteTag.Commit.ID, diff --git a/internal/gitsources/gitlab/parse.go b/internal/gitsources/gitlab/parse.go index f2d4c25..a0b5cce 100644 --- a/internal/gitsources/gitlab/parse.go +++ b/internal/gitsources/gitlab/parse.go @@ -35,11 +35,6 @@ const ( hookPush = "Push Hook" hookTagPush = "Tag Push Hook" hookPullRequest = "Merge Request Hook" - - prStateOpen = "open" - - prActionOpen = "opened" - prActionSync = "synchronized" ) func (c *Client) ParseWebhook(r *http.Request, secret string) (*types.WebhookData, error) {