From 2f91bdd4a0f5167ef304c220865141c15f2dd563 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 5 Jan 2022 21:50:23 +0100 Subject: [PATCH] gofumpt -w -l -extra . (#661) --- cli/internal/util.go | 2 +- cmd/agent/agent.go | 3 +- cmd/server/server.go | 2 +- pipeline/backend/backend.go | 4 +-- pipeline/backend/types/engine.go | 2 -- pipeline/frontend/yaml/compiler/compiler.go | 2 +- pipeline/frontend/yaml/constraint.go | 4 +-- pipeline/frontend/yaml/types/types_yaml.go | 2 -- server/api/build.go | 2 +- server/api/metrics/prometheus.go | 6 ++-- server/model/repo.go | 2 +- server/model/user_test.go | 2 +- server/queue/fifo.go | 2 +- server/remote/bitbucket/internal/client.go | 3 +- .../remote/bitbucketserver/bitbucketserver.go | 8 +++--- server/remote/bitbucketserver/convert.go | 4 +-- server/remote/bitbucketserver/convert_test.go | 2 +- .../remote/bitbucketserver/internal/client.go | 28 +++++++++---------- server/remote/gitea/gitea.go | 2 +- server/remote/gitea/helper_test.go | 6 ++-- server/remote/gitlab/convert.go | 4 +-- server/remote/gitlab/gitlab.go | 10 +++---- server/remote/gitlab/gitlab_test.go | 6 ++-- server/remote/gitlab/helper.go | 12 ++++---- server/remote/gogs/helper_test.go | 6 ++-- server/router/middleware/session/repo_test.go | 1 - server/shared/buildStatus_test.go | 3 +- server/shared/procBuilder_test.go | 6 ++-- server/shared/procStatus_test.go | 3 +- server/store/datastore/migration/common.go | 6 ++-- .../datastore/migration/migration_test.go | 2 +- server/web/config.go | 2 +- shared/oauth2/oauth2.go | 2 +- version/version.go | 6 ++-- woodpecker-go/woodpecker/client.go | 12 ++++---- 35 files changed, 79 insertions(+), 90 deletions(-) diff --git a/cli/internal/util.go b/cli/internal/util.go index 62d0b1488..74a0b4acc 100644 --- a/cli/internal/util.go +++ b/cli/internal/util.go @@ -75,7 +75,7 @@ func NewClient(c *cli.Context) (woodpecker.Client, error) { // ParseRepo parses the repository owner and name from a string. func ParseRepo(str string) (user, repo string, err error) { - var parts = strings.Split(str, "/") + parts := strings.Split(str, "/") if len(parts) != 2 { err = fmt.Errorf("Error: Invalid or missing repository. eg octocat/hello-world") return diff --git a/cmd/agent/agent.go b/cmd/agent/agent.go index 415e02229..2638585b8 100644 --- a/cmd/agent/agent.go +++ b/cmd/agent/agent.go @@ -93,7 +93,7 @@ func loop(c *cli.Context) error { // grpc.Dial(target, )) - var transport = grpc.WithInsecure() + transport := grpc.WithInsecure() if c.Bool("secure-grpc") { transport = grpc.WithTransportCredentials(grpccredentials.NewTLS(&tls.Config{InsecureSkipVerify: c.Bool("skip-insecure-grpc")})) @@ -111,7 +111,6 @@ func loop(c *cli.Context) error { Timeout: c.Duration("keepalive-timeout"), }), ) - if err != nil { return err } diff --git a/cmd/server/server.go b/cmd/server/server.go index bf7f3ffbc..b9e1e4e29 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -226,7 +226,7 @@ func run(c *cli.Context) error { } dir := cacheDir() - if err := os.MkdirAll(dir, 0700); err != nil { + if err := os.MkdirAll(dir, 0o700); err != nil { return err } diff --git a/pipeline/backend/backend.go b/pipeline/backend/backend.go index 8bc9dad19..63b99a49c 100644 --- a/pipeline/backend/backend.go +++ b/pipeline/backend/backend.go @@ -7,9 +7,7 @@ import ( "github.com/woodpecker-ci/woodpecker/pipeline/backend/types" ) -var ( - engines map[string]types.Engine -) +var engines map[string]types.Engine func init() { engines = make(map[string]types.Engine) diff --git a/pipeline/backend/types/engine.go b/pipeline/backend/types/engine.go index 33c09d55a..8a5984ead 100644 --- a/pipeline/backend/types/engine.go +++ b/pipeline/backend/types/engine.go @@ -9,9 +9,7 @@ import ( // to create and manage container resources. type Engine interface { Name() string - IsAvailable() bool - Load() error // Setup the pipeline environment. diff --git a/pipeline/frontend/yaml/compiler/compiler.go b/pipeline/frontend/yaml/compiler/compiler.go index c1919c33c..807cbbd37 100644 --- a/pipeline/frontend/yaml/compiler/compiler.go +++ b/pipeline/frontend/yaml/compiler/compiler.go @@ -168,7 +168,7 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config { var stage *backend.Stage var group string for i, container := range conf.Pipeline.Containers { - //Skip if local and should not run local + // Skip if local and should not run local if c.local && !container.Constraints.Local.Bool() { continue } diff --git a/pipeline/frontend/yaml/constraint.go b/pipeline/frontend/yaml/constraint.go index daf67e26e..d0b5aa636 100644 --- a/pipeline/frontend/yaml/constraint.go +++ b/pipeline/frontend/yaml/constraint.go @@ -99,7 +99,7 @@ func (c *Constraint) Excludes(v string) bool { // UnmarshalYAML unmarshals the constraint. func (c *Constraint) UnmarshalYAML(value *yaml.Node) error { - var out1 = struct { + out1 := struct { Include types.Stringorslice Exclude types.Stringorslice }{} @@ -177,7 +177,7 @@ func (c *ConstraintMap) UnmarshalYAML(unmarshal func(interface{}) error) error { // UnmarshalYAML unmarshals the constraint. func (c *ConstraintPath) UnmarshalYAML(value *yaml.Node) error { - var out1 = struct { + out1 := struct { Include types.Stringorslice `yaml:"include,omitempty"` Exclude types.Stringorslice `yaml:"exclude,omitempty"` IgnoreMessage string `yaml:"ignore_message,omitempty"` diff --git a/pipeline/frontend/yaml/types/types_yaml.go b/pipeline/frontend/yaml/types/types_yaml.go index 8a36474af..62c09575a 100644 --- a/pipeline/frontend/yaml/types/types_yaml.go +++ b/pipeline/frontend/yaml/types/types_yaml.go @@ -24,7 +24,6 @@ func (s *StringorInt) UnmarshalYAML(unmarshal func(interface{}) error) error { var stringType string if err := unmarshal(&stringType); err == nil { intType, err := strconv.ParseInt(stringType, 10, 64) - if err != nil { return err } @@ -50,7 +49,6 @@ func (s *MemStringorInt) UnmarshalYAML(unmarshal func(interface{}) error) error var stringType string if err := unmarshal(&stringType); err == nil { intType, err := units.RAMInBytes(stringType) - if err != nil { return err } diff --git a/server/api/build.go b/server/api/build.go index 54346016c..93a1c5fe0 100644 --- a/server/api/build.go +++ b/server/api/build.go @@ -473,7 +473,7 @@ func PostBuild(c *gin.Context) { } // Read query string parameters into buildParams, exclude reserved params - var envs = map[string]string{} + envs := map[string]string{} for key, val := range c.Request.URL.Query() { switch key { // Skip some options of the endpoint diff --git a/server/api/metrics/prometheus.go b/server/api/metrics/prometheus.go index 1397e8f38..1658ea083 100644 --- a/server/api/metrics/prometheus.go +++ b/server/api/metrics/prometheus.go @@ -24,10 +24,8 @@ import ( "github.com/woodpecker-ci/woodpecker/server" ) -var ( - // errInvalidToken is returned when the api request token is invalid. - errInvalidToken = errors.New("Invalid or missing token") -) +// errInvalidToken is returned when the api request token is invalid. +var errInvalidToken = errors.New("Invalid or missing token") // PromHandler will pass the call from /api/metrics/prometheus to prometheus func PromHandler() gin.HandlerFunc { diff --git a/server/model/repo.go b/server/model/repo.go index a8cd38738..0d15ccb9b 100644 --- a/server/model/repo.go +++ b/server/model/repo.go @@ -61,7 +61,7 @@ func (r *Repo) ResetVisibility() { // ParseRepo parses the repository owner and name from a string. func ParseRepo(str string) (user, repo string, err error) { - var parts = strings.Split(str, "/") + parts := strings.Split(str, "/") if len(parts) != 2 { err = fmt.Errorf("Error: Invalid or missing repository. eg octocat/hello-world") return diff --git a/server/model/user_test.go b/server/model/user_test.go index fc7e9c39d..8f7cba41f 100644 --- a/server/model/user_test.go +++ b/server/model/user_test.go @@ -17,7 +17,7 @@ package model import "testing" func TestUserValidate(t *testing.T) { - var tests = []struct { + tests := []struct { user User err error }{ diff --git a/server/queue/fifo.go b/server/queue/fifo.go index c3b7bfe52..0fe32fc7f 100644 --- a/server/queue/fifo.go +++ b/server/queue/fifo.go @@ -336,7 +336,7 @@ func (q *fifo) depsInQueue(task *Task) bool { return false } -func (q *fifo) updateDepStatusInQueue(taskID string, status string) { +func (q *fifo) updateDepStatusInQueue(taskID, status string) { var next *list.Element for e := q.pending.Front(); e != nil; e = next { next = e.Next() diff --git a/server/remote/bitbucket/internal/client.go b/server/remote/bitbucket/internal/client.go index 94c47c747..605288959 100644 --- a/server/remote/bitbucket/internal/client.go +++ b/server/remote/bitbucket/internal/client.go @@ -106,7 +106,7 @@ func (c *Client) ListRepos(account string, opts *ListOpts) (*RepoResp, error) { } func (c *Client) ListReposAll(account string) ([]*Repo, error) { - var page = 1 + page := 1 var repos []*Repo for { @@ -164,7 +164,6 @@ func (c *Client) GetPermission(fullName string) (*RepoPerm, error) { out := new(RepoPermResp) uri := fmt.Sprintf(pathPermissions, c.base, fullName) _, err := c.do(uri, get, nil, out) - if err != nil { return nil, err } diff --git a/server/remote/bitbucketserver/bitbucketserver.go b/server/remote/bitbucketserver/bitbucketserver.go index 9d4b6cff3..54c0763d9 100644 --- a/server/remote/bitbucketserver/bitbucketserver.go +++ b/server/remote/bitbucketserver/bitbucketserver.go @@ -111,7 +111,7 @@ func (c *Config) Login(ctx context.Context, res http.ResponseWriter, req *http.R if err != nil { return nil, err } - var code = req.FormValue("oauth_verifier") + code := req.FormValue("oauth_verifier") if len(code) == 0 { http.Redirect(res, req, u, http.StatusSeeOther) return nil, nil @@ -205,9 +205,9 @@ func (c *Config) Netrc(user *model.User, r *model.Repo) (*model.Netrc, error) { if err != nil { return nil, err } - //remove the port + // remove the port tmp := strings.Split(u.Host, ":") - var host = tmp[0] + host := tmp[0] if err != nil { return nil, err @@ -240,7 +240,7 @@ func (c *Config) Hook(r *http.Request) (*model.Repo, *model.Build, error) { return parseHook(r, c.URL) } -func CreateConsumer(URL string, ConsumerKey string, PrivateKey *rsa.PrivateKey) *oauth.Consumer { +func CreateConsumer(URL, ConsumerKey string, PrivateKey *rsa.PrivateKey) *oauth.Consumer { consumer := oauth.NewRSAConsumer( ConsumerKey, PrivateKey, diff --git a/server/remote/bitbucketserver/convert.go b/server/remote/bitbucketserver/convert.go index 392494ea1..6cb40ff26 100644 --- a/server/remote/bitbucketserver/convert.go +++ b/server/remote/bitbucketserver/convert.go @@ -88,7 +88,7 @@ func convertPushHook(hook *internal.PostHook, baseURL string) *model.Build { "refs/tags/", ) - //Ensuring the author label is not longer then 40 for the label of the commit author (default size in the db) + // Ensuring the author label is not longer then 40 for the label of the commit author (default size in the db) authorLabel := hook.Changesets.Values[0].ToCommit.Author.Name if len(authorLabel) > 40 { authorLabel = authorLabel[0:37] + "..." @@ -97,7 +97,7 @@ func convertPushHook(hook *internal.PostHook, baseURL string) *model.Build { build := &model.Build{ Commit: hook.RefChanges[0].ToHash, // TODO check for index value Branch: branch, - Message: hook.Changesets.Values[0].ToCommit.Message, //TODO check for index Values + Message: hook.Changesets.Values[0].ToCommit.Message, // TODO check for index Values Avatar: avatarLink(hook.Changesets.Values[0].ToCommit.Author.EmailAddress), Author: authorLabel, Email: hook.Changesets.Values[0].ToCommit.Author.EmailAddress, diff --git a/server/remote/bitbucketserver/convert_test.go b/server/remote/bitbucketserver/convert_test.go index a6b813256..6ad332bd0 100644 --- a/server/remote/bitbucketserver/convert_test.go +++ b/server/remote/bitbucketserver/convert_test.go @@ -33,7 +33,7 @@ func Test_helper(t *testing.T) { } from.Project.Key = "octocat" - //var links [1]internal.LinkType + // var links [1]internal.LinkType link := internal.CloneLink{ Name: "http", Href: "https://x7hw@server.org/foo/bar.git", diff --git a/server/remote/bitbucketserver/internal/client.go b/server/remote/bitbucketserver/internal/client.go index 8f26de22e..a0ce36260 100644 --- a/server/remote/bitbucketserver/internal/client.go +++ b/server/remote/bitbucketserver/internal/client.go @@ -105,7 +105,7 @@ func (c *Client) FindCurrentUser() (*User, error) { return &user, nil } -func (c *Client) FindRepo(owner string, name string) (*Repo, error) { +func (c *Client) FindRepo(owner, name string) (*Repo, error) { urlString := fmt.Sprintf(pathRepo, c.base, owner, name) response, err := c.doGet(urlString) if response != nil { @@ -130,7 +130,7 @@ func (c *Client) FindRepos() ([]*Repo, error) { return c.paginatedRepos(0) } -func (c *Client) FindRepoPerms(owner string, repo string) (*model.Perm, error) { +func (c *Client) FindRepoPerms(owner, repo string) (*model.Perm, error) { perms := new(model.Perm) // If you don't have access return none right away _, err := c.FindRepo(owner, repo) @@ -150,7 +150,7 @@ func (c *Client) FindRepoPerms(owner string, repo string) (*model.Perm, error) { return perms, nil } -func (c *Client) FindFileForRepo(owner string, repo string, fileName string, ref string) ([]byte, error) { +func (c *Client) FindFileForRepo(owner, repo, fileName, ref string) ([]byte, error) { response, err := c.doGet(fmt.Sprintf(pathSource, c.base, owner, repo, fileName, ref)) if response != nil { defer response.Body.Close() @@ -168,7 +168,7 @@ func (c *Client) FindFileForRepo(owner string, repo string, fileName string, ref return responseBytes, nil } -func (c *Client) CreateHook(owner string, name string, callBackLink string) error { +func (c *Client) CreateHook(owner, name, callBackLink string) error { hookDetails, err := c.GetHookDetails(owner, name) if err != nil { return err @@ -198,7 +198,7 @@ func (c *Client) CreateStatus(revision string, status *BuildStatus) error { return c.doPost(uri, status) } -func (c *Client) DeleteHook(owner string, name string, link string) error { +func (c *Client) DeleteHook(owner, name, link string) error { hookSettings, err := c.GetHooks(owner, name) if err != nil { return err @@ -214,7 +214,7 @@ func (c *Client) DeleteHook(owner string, name string, link string) error { return c.doPut(fmt.Sprintf(pathHookEnabled, c.base, owner, name, hookName), hookBytes) } -func (c *Client) GetHookDetails(owner string, name string) (*HookPluginDetails, error) { +func (c *Client) GetHookDetails(owner, name string) (*HookPluginDetails, error) { urlString := fmt.Sprintf(pathHookDetails, c.base, owner, name, hookName) response, err := c.doGet(urlString) if response != nil { @@ -229,7 +229,7 @@ func (c *Client) GetHookDetails(owner string, name string) (*HookPluginDetails, return &hookDetails, err } -func (c *Client) GetHooks(owner string, name string) (*HookSettings, error) { +func (c *Client) GetHooks(owner, name string) (*HookSettings, error) { urlString := fmt.Sprintf(pathHookSettings, c.base, owner, name, hookName) response, err := c.doGet(urlString) if response != nil { @@ -244,9 +244,9 @@ func (c *Client) GetHooks(owner string, name string) (*HookSettings, error) { return &hookSettings, err } -//TODO: make these as as general do with the action +// TODO: make these as as general do with the action -//Helper function to help create get +// Helper function to help create get func (c *Client) doGet(url string) (*http.Response, error) { request, err := http.NewRequestWithContext(c.ctx, "GET", url, nil) if err != nil { @@ -256,7 +256,7 @@ func (c *Client) doGet(url string) (*http.Response, error) { return c.client.Do(request) } -//Helper function to help create the hook +// Helper function to help create the hook func (c *Client) doPut(url string, body []byte) error { request, err := http.NewRequestWithContext(c.ctx, "PUT", url, bytes.NewBuffer(body)) if err != nil { @@ -273,7 +273,7 @@ func (c *Client) doPut(url string, body []byte) error { return nil } -//Helper function to help create the hook +// Helper function to help create the hook func (c *Client) doPost(url string, status *BuildStatus) error { // write it to the body of the request. var buf io.ReadWriter @@ -296,7 +296,7 @@ func (c *Client) doPost(url string, status *BuildStatus) error { return err } -//Helper function to get repos paginated +// Helper function to get repos paginated func (c *Client) paginatedRepos(start int) ([]*Repo, error) { limit := 1000 requestURL := fmt.Sprintf(pathRepos, c.base, strconv.Itoa(start), strconv.Itoa(limit)) @@ -332,7 +332,7 @@ func filter(vs []string, f func(string) bool) []string { return vsf } -//TODO: find a clean way of doing these next two methods- bitbucket server hooks only support 20 cb hooks +// TODO: find a clean way of doing these next two methods- bitbucket server hooks only support 20 cb hooks func arrayToHookSettings(hooks []string) HookSettings { hookSettings := HookSettings{} for loc, value := range hooks { @@ -378,7 +378,7 @@ func arrayToHookSettings(hooks []string) HookSettings { case 19: hookSettings.HookURL19 = value - //Since there's only 19 hooks it will add to the latest if it doesn't exist :/ + // Since there's only 19 hooks it will add to the latest if it doesn't exist :/ default: hookSettings.HookURL19 = value } diff --git a/server/remote/gitea/gitea.go b/server/remote/gitea/gitea.go index c49f3b9fe..e1726783b 100644 --- a/server/remote/gitea/gitea.go +++ b/server/remote/gitea/gitea.go @@ -250,7 +250,7 @@ func (c *Gitea) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error) } // Gitea SDK forces us to read repo list paginated. - var page = 1 + page := 1 for { all, _, err := client.ListMyRepos( gitea.ListReposOptions{ diff --git a/server/remote/gitea/helper_test.go b/server/remote/gitea/helper_test.go index 330ae483a..efc7dcba7 100644 --- a/server/remote/gitea/helper_test.go +++ b/server/remote/gitea/helper_test.go @@ -216,7 +216,7 @@ func Test_parse(t *testing.T) { }) g.It("Should correct a malformed avatar url", func() { - var urls = []struct { + urls := []struct { Before string After string }{ @@ -245,7 +245,7 @@ func Test_parse(t *testing.T) { }) g.It("Should expand the avatar url", func() { - var urls = []struct { + urls := []struct { Before string After string }{ @@ -263,7 +263,7 @@ func Test_parse(t *testing.T) { }, } - var repo = "http://gitea.io/foo/bar" + repo := "http://gitea.io/foo/bar" for _, url := range urls { got := expandAvatar(repo, url.Before) g.Assert(got).Equal(url.After) diff --git a/server/remote/gitlab/convert.go b/server/remote/gitlab/convert.go index d1f566a22..aa8ba050f 100644 --- a/server/remote/gitlab/convert.go +++ b/server/remote/gitlab/convert.go @@ -29,8 +29,8 @@ import ( func (g *Gitlab) convertGitlabRepo(_repo *gitlab.Project) (*model.Repo, error) { parts := strings.Split(_repo.PathWithNamespace, "/") // TODO(648) save repo id (support nested repos) - var owner = strings.Join(parts[:len(parts)-1], "/") - var name = parts[len(parts)-1] + owner := strings.Join(parts[:len(parts)-1], "/") + name := parts[len(parts)-1] repo := &model.Repo{ Owner: owner, Name: name, diff --git a/server/remote/gitlab/gitlab.go b/server/remote/gitlab/gitlab.go index 0e332bc09..45a5e0bc1 100644 --- a/server/remote/gitlab/gitlab.go +++ b/server/remote/gitlab/gitlab.go @@ -90,7 +90,7 @@ func New(opts Opts) (remote.Remote, error) { // Login authenticates the session and returns the // remote user details. func (g *Gitlab) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) { - var config = &oauth2.Config{ + config := &oauth2.Config{ ClientID: g.ClientID, ClientSecret: g.ClientSecret, Scope: defaultScope, @@ -109,17 +109,17 @@ func (g *Gitlab) Login(ctx context.Context, res http.ResponseWriter, req *http.R } // get the OAuth code - var code = req.FormValue("code") + code := req.FormValue("code") if len(code) == 0 { http.Redirect(res, req, config.AuthCodeURL("drone"), http.StatusSeeOther) return nil, nil } - var trans = &oauth2.Transport{Config: config, Transport: &http.Transport{ + trans := &oauth2.Transport{Config: config, Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: g.SkipVerify}, Proxy: http.ProxyFromEnvironment, }} - var token, err = trans.Exchange(code) + token, err := trans.Exchange(code) if err != nil { return nil, fmt.Errorf("Error exchanging token. %s", err) } @@ -395,7 +395,7 @@ func (g *Gitlab) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) { }, nil } -func (g *Gitlab) getTokenAndWebURL(link string) (token string, webURL string, err error) { +func (g *Gitlab) getTokenAndWebURL(link string) (token, webURL string, err error) { uri, err := url.Parse(link) if err != nil { return "", "", err diff --git a/server/remote/gitlab/gitlab_test.go b/server/remote/gitlab/gitlab_test.go index d15acae05..d98d8ca4f 100644 --- a/server/remote/gitlab/gitlab_test.go +++ b/server/remote/gitlab/gitlab_test.go @@ -52,19 +52,19 @@ func load(config string) *Gitlab { func Test_Gitlab(t *testing.T) { // setup a dummy github server - var server = testdata.NewServer(t) + server := testdata.NewServer(t) defer server.Close() env := server.URL + "?client_id=test&client_secret=test" client := load(env) - var user = model.User{ + user := model.User{ Login: "test_user", Token: "e3b0c44298fc1c149afbf4c8996fb", } - var repo = model.Repo{ + repo := model.Repo{ Name: "diaspora-client", Owner: "diaspora", } diff --git a/server/remote/gitlab/helper.go b/server/remote/gitlab/helper.go index c1e0808c2..8f03abd09 100644 --- a/server/remote/gitlab/helper.go +++ b/server/remote/gitlab/helper.go @@ -39,8 +39,8 @@ func newClient(url, accessToken string, skipVerify bool) (*gitlab.Client, error) // isRead is a helper function that returns true if the // user has Read-only access to the repository. func isRead(proj *gitlab.Project) bool { - var user = proj.Permissions.ProjectAccess - var group = proj.Permissions.GroupAccess + user := proj.Permissions.ProjectAccess + group := proj.Permissions.GroupAccess switch { case proj.Public: @@ -57,8 +57,8 @@ func isRead(proj *gitlab.Project) bool { // isWrite is a helper function that returns true if the // user has Read-Write access to the repository. func isWrite(proj *gitlab.Project) bool { - var user = proj.Permissions.ProjectAccess - var group = proj.Permissions.GroupAccess + user := proj.Permissions.ProjectAccess + group := proj.Permissions.GroupAccess switch { case user != nil && user.AccessLevel >= 30: @@ -73,8 +73,8 @@ func isWrite(proj *gitlab.Project) bool { // isAdmin is a helper function that returns true if the // user has Admin access to the repository. func isAdmin(proj *gitlab.Project) bool { - var user = proj.Permissions.ProjectAccess - var group = proj.Permissions.GroupAccess + user := proj.Permissions.ProjectAccess + group := proj.Permissions.GroupAccess switch { case user != nil && user.AccessLevel >= 40: diff --git a/server/remote/gogs/helper_test.go b/server/remote/gogs/helper_test.go index 79b816c38..467898d3c 100644 --- a/server/remote/gogs/helper_test.go +++ b/server/remote/gogs/helper_test.go @@ -188,7 +188,7 @@ func Test_parse(t *testing.T) { }) g.It("Should correct a malformed avatar url", func() { - var urls = []struct { + urls := []struct { Before string After string }{ @@ -217,7 +217,7 @@ func Test_parse(t *testing.T) { }) g.It("Should expand the avatar url", func() { - var urls = []struct { + urls := []struct { Before string After string }{ @@ -235,7 +235,7 @@ func Test_parse(t *testing.T) { }, } - var repo = "http://gogs.io/foo/bar" + repo := "http://gogs.io/foo/bar" for _, url := range urls { got := expandAvatar(repo, url.Before) g.Assert(got).Equal(url.After) diff --git a/server/router/middleware/session/repo_test.go b/server/router/middleware/session/repo_test.go index 6e2899a34..392fcfdae 100644 --- a/server/router/middleware/session/repo_test.go +++ b/server/router/middleware/session/repo_test.go @@ -19,5 +19,4 @@ import ( ) func TestSetPerm(t *testing.T) { - } diff --git a/server/shared/buildStatus_test.go b/server/shared/buildStatus_test.go index 91ea58b76..9f7d6493d 100644 --- a/server/shared/buildStatus_test.go +++ b/server/shared/buildStatus_test.go @@ -22,8 +22,7 @@ import ( "github.com/woodpecker-ci/woodpecker/server/model" ) -type mockUpdateBuildStore struct { -} +type mockUpdateBuildStore struct{} func (m *mockUpdateBuildStore) UpdateBuild(build *model.Build) error { return nil diff --git a/server/shared/procBuilder_test.go b/server/shared/procBuilder_test.go index bce4bae66..ecf825d04 100644 --- a/server/shared/procBuilder_test.go +++ b/server/shared/procBuilder_test.go @@ -49,7 +49,8 @@ pipeline: image: scratch yyy: ${CI_COMMIT_MESSAGE} `)}, - }} + }, + } if buildItems, err := b.Build(); err != nil { t.Fatal(err) @@ -404,7 +405,8 @@ func TestTree(t *testing.T) { Secs: []*model.Secret{}, Regs: []*model.Registry{}, Link: "", - Yamls: []*remote.FileMeta{{Data: []byte(` + Yamls: []*remote.FileMeta{ + {Data: []byte(` pipeline: build: image: scratch diff --git a/server/shared/procStatus_test.go b/server/shared/procStatus_test.go index 15b4d37e9..8ed111e5c 100644 --- a/server/shared/procStatus_test.go +++ b/server/shared/procStatus_test.go @@ -22,8 +22,7 @@ import ( "github.com/woodpecker-ci/woodpecker/server/model" ) -type mockUpdateProcStore struct { -} +type mockUpdateProcStore struct{} func (m *mockUpdateProcStore) ProcUpdate(build *model.Proc) error { return nil diff --git a/server/store/datastore/migration/common.go b/server/store/datastore/migration/common.go index 6afa6a04e..000df760a 100644 --- a/server/store/datastore/migration/common.go +++ b/server/store/datastore/migration/common.go @@ -212,8 +212,10 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin return nil } -var whitespaces = regexp.MustCompile(`\s+`) -var columnSeparator = regexp.MustCompile(`\s?,\s?`) +var ( + whitespaces = regexp.MustCompile(`\s+`) + columnSeparator = regexp.MustCompile(`\s?,\s?`) +) func removeColumnFromSQLITETableSchema(schema string, names ...string) string { if len(names) == 0 { diff --git a/server/store/datastore/migration/migration_test.go b/server/store/datastore/migration/migration_test.go index 8993c9e09..41ec837ec 100644 --- a/server/store/datastore/migration/migration_test.go +++ b/server/store/datastore/migration/migration_test.go @@ -36,7 +36,7 @@ func createSQLiteDB(t *testing.T) string { t.FailNow() } - if !assert.NoError(t, ioutil.WriteFile(tmpF.Name(), dbF, 0644)) { + if !assert.NoError(t, ioutil.WriteFile(tmpF.Name(), dbF, 0o644)) { t.FailNow() } return tmpF.Name() diff --git a/server/web/config.go b/server/web/config.go index b861f32b3..9dd74ce68 100644 --- a/server/web/config.go +++ b/server/web/config.go @@ -54,7 +54,7 @@ func Config(c *gin.Context) { } // default func map with json parser. - var funcMap = template.FuncMap{ + funcMap := template.FuncMap{ "json": func(v interface{}) string { a, _ := json.Marshal(v) return string(a) diff --git a/shared/oauth2/oauth2.go b/shared/oauth2/oauth2.go index da0394c9e..a22f06c18 100644 --- a/shared/oauth2/oauth2.go +++ b/shared/oauth2/oauth2.go @@ -88,7 +88,7 @@ func (f CacheFile) Token() (*Token, error) { } func (f CacheFile) PutToken(tok *Token) error { - file, err := os.OpenFile(string(f), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) + file, err := os.OpenFile(string(f), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600) if err != nil { return OAuthError{"CacheFile.PutToken", err.Error()} } diff --git a/version/version.go b/version/version.go index 12311591d..d44d28431 100644 --- a/version/version.go +++ b/version/version.go @@ -14,10 +14,8 @@ package version -var ( - // Version of Woodpecker, set with ldflags, from Git tag - Version string -) +// Version of Woodpecker, set with ldflags, from Git tag +var Version string // String returns the Version set at build time or "dev" func String() string { diff --git a/woodpecker-go/woodpecker/client.go b/woodpecker-go/woodpecker/client.go index b89f298fb..42a0f1779 100644 --- a/woodpecker-go/woodpecker/client.go +++ b/woodpecker-go/woodpecker/client.go @@ -114,7 +114,7 @@ func (c *client) UserDel(login string) error { } // Repo returns a repository by name. -func (c *client) Repo(owner string, name string) (*Repo, error) { +func (c *client) Repo(owner, name string) (*Repo, error) { out := new(Repo) uri := fmt.Sprintf(pathRepo, c.addr, owner, name) err := c.get(uri, out) @@ -140,7 +140,7 @@ func (c *client) RepoListOpts(sync, all bool) ([]*Repo, error) { } // RepoPost activates a repository. -func (c *client) RepoPost(owner string, name string) (*Repo, error) { +func (c *client) RepoPost(owner, name string) (*Repo, error) { out := new(Repo) uri := fmt.Sprintf(pathRepo, c.addr, owner, name) err := c.post(uri, nil, out) @@ -148,7 +148,7 @@ func (c *client) RepoPost(owner string, name string) (*Repo, error) { } // RepoChown updates a repository owner. -func (c *client) RepoChown(owner string, name string) (*Repo, error) { +func (c *client) RepoChown(owner, name string) (*Repo, error) { out := new(Repo) uri := fmt.Sprintf(pathChown, c.addr, owner, name) err := c.post(uri, nil, out) @@ -156,7 +156,7 @@ func (c *client) RepoChown(owner string, name string) (*Repo, error) { } // RepoRepair repairs the repository hooks. -func (c *client) RepoRepair(owner string, name string) error { +func (c *client) RepoRepair(owner, name string) error { uri := fmt.Sprintf(pathRepair, c.addr, owner, name) return c.post(uri, nil, nil) } @@ -290,7 +290,7 @@ func (c *client) Registry(owner, name, hostname string) (*Registry, error) { } // RegistryList returns a list of all repository registries. -func (c *client) RegistryList(owner string, name string) ([]*Registry, error) { +func (c *client) RegistryList(owner, name string) ([]*Registry, error) { var out []*Registry uri := fmt.Sprintf(pathRepoRegistries, c.addr, owner, name) err := c.get(uri, &out) @@ -328,7 +328,7 @@ func (c *client) Secret(owner, name, secret string) (*Secret, error) { } // SecretList returns a list of all repository secrets. -func (c *client) SecretList(owner string, name string) ([]*Secret, error) { +func (c *client) SecretList(owner, name string) ([]*Secret, error) { var out []*Secret uri := fmt.Sprintf(pathRepoSecrets, c.addr, owner, name) err := c.get(uri, &out)