diff --git a/.golangci.yml b/.golangci.yml index 3cb31b8a3..7375d708b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -13,6 +13,7 @@ linters: - typecheck - errcheck - bidichk + - whitespace run: timeout: 5m diff --git a/agent/runner.go b/agent/runner.go index 9be11a244..9b1d1523a 100644 --- a/agent/runner.go +++ b/agent/runner.go @@ -139,7 +139,6 @@ func (r *Runner) Run(ctx context.Context) error { var uploads sync.WaitGroup defaultLogger := pipeline.LogFunc(func(proc *backend.Step, rc multipart.Reader) error { - loglogger := logger.With(). Str("image", proc.Image). Str("stage", proc.Alias). diff --git a/cli/build/build_queue.go b/cli/build/build_queue.go index 184eeeb6f..cb8ad7d47 100644 --- a/cli/build/build_queue.go +++ b/cli/build/build_queue.go @@ -22,7 +22,6 @@ var buildQueueCmd = &cli.Command{ } func buildQueue(c *cli.Context) error { - client, err := internal.NewClient(c) if err != nil { return err diff --git a/cmd/server/server.go b/cmd/server/server.go index 7d1b16344..3bccc47cc 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -50,7 +50,6 @@ import ( ) func run(c *cli.Context) error { - if c.Bool("pretty") { log.Logger = log.Output( zerolog.ConsoleWriter{ @@ -151,7 +150,6 @@ func run(c *cli.Context) error { // start the grpc server g.Go(func() error { - lis, err := net.Listen("tcp", c.String("grpc-addr")) if err != nil { log.Err(err).Msg("") @@ -252,7 +250,6 @@ func run(c *cli.Context) error { } func setupEvilGlobals(c *cli.Context, v store.Store, r remote.Remote) { - // storage server.Config.Storage.Files = v server.Config.Storage.Config = v diff --git a/pipeline/frontend/yaml/compiler/compiler.go b/pipeline/frontend/yaml/compiler/compiler.go index c574f5444..446cde851 100644 --- a/pipeline/frontend/yaml/compiler/compiler.go +++ b/pipeline/frontend/yaml/compiler/compiler.go @@ -161,7 +161,6 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config { name := fmt.Sprintf("%s_services_%d", c.prefix, i) step := c.createProcess(name, container, "services") stage.Steps = append(stage.Steps, step) - } config.Stages = append(config.Stages, stage) } diff --git a/pipeline/frontend/yaml/config_test.go b/pipeline/frontend/yaml/config_test.go index 9220135e0..92888e3f9 100644 --- a/pipeline/frontend/yaml/config_test.go +++ b/pipeline/frontend/yaml/config_test.go @@ -13,7 +13,6 @@ func TestParse(t *testing.T) { g.Describe("Parser", func() { g.Describe("Given a yaml file", func() { - g.It("Should unmarshal a string", func() { out, err := ParseString(sampleYaml) if err != nil { diff --git a/pipeline/frontend/yaml/matrix/matrix.go b/pipeline/frontend/yaml/matrix/matrix.go index 6c353f091..ecee2c4e8 100644 --- a/pipeline/frontend/yaml/matrix/matrix.go +++ b/pipeline/frontend/yaml/matrix/matrix.go @@ -29,7 +29,6 @@ func (a Axis) String() string { // Parse parses the Yaml matrix definition. func Parse(data []byte) ([]Axis, error) { - axis, err := parseList(data) if err == nil && len(axis) != 0 { return axis, nil diff --git a/pipeline/frontend/yaml/matrix/matrix_test.go b/pipeline/frontend/yaml/matrix/matrix_test.go index 45ea0e172..d2776c09c 100644 --- a/pipeline/frontend/yaml/matrix/matrix_test.go +++ b/pipeline/frontend/yaml/matrix/matrix_test.go @@ -7,10 +7,8 @@ import ( ) func TestMatrix(t *testing.T) { - g := goblin.Goblin(t) g.Describe("Calculate matrix", func() { - axis, _ := ParseString(fakeMatrix) g.It("Should calculate permutations", func() { diff --git a/pipeline/frontend/yaml/types/bool_test.go b/pipeline/frontend/yaml/types/bool_test.go index e9e199b47..f1e87219f 100644 --- a/pipeline/frontend/yaml/types/bool_test.go +++ b/pipeline/frontend/yaml/types/bool_test.go @@ -12,7 +12,6 @@ func TestBoolTrue(t *testing.T) { g.Describe("Yaml bool type", func() { g.Describe("given a yaml file", func() { - g.It("should unmarshal true", func() { in := []byte("true") out := BoolTrue{} diff --git a/pipeline/frontend/yaml/types/types_yaml.go b/pipeline/frontend/yaml/types/types_yaml.go index 1c1f5d26f..24504ecbd 100644 --- a/pipeline/frontend/yaml/types/types_yaml.go +++ b/pipeline/frontend/yaml/types/types_yaml.go @@ -91,7 +91,6 @@ type SliceorMap map[string]string // UnmarshalYAML implements the Unmarshaller interface. func (s *SliceorMap) UnmarshalYAML(unmarshal func(interface{}) error) error { - var sliceType []interface{} if err := unmarshal(&sliceType); err == nil { parts := map[string]string{} diff --git a/pipeline/frontend/yaml/types/ulimit_test.go b/pipeline/frontend/yaml/types/ulimit_test.go index dee76e087..0abd1c700 100644 --- a/pipeline/frontend/yaml/types/ulimit_test.go +++ b/pipeline/frontend/yaml/types/ulimit_test.go @@ -49,7 +49,6 @@ func TestMarshalUlimit(t *testing.T) { } for _, ulimit := range ulimits { - bytes, err := yaml.Marshal(ulimit.ulimits) assert.Nil(t, err) diff --git a/server/api/login.go b/server/api/login.go index f8bbcf527..8794076ff 100644 --- a/server/api/login.go +++ b/server/api/login.go @@ -71,7 +71,6 @@ func HandleAuth(c *gin.Context) { // get the user from the database u, err := store_.GetUserLogin(tmpuser.Login) if err != nil { - // if self-registration is disabled we should return a not authorized error if !config.Open && !config.IsAdmin(tmpuser) { log.Error().Msgf("cannot register %s. registration closed", tmpuser.Login) diff --git a/server/grpc/rpc.go b/server/grpc/rpc.go index e59b46e44..93ea6825d 100644 --- a/server/grpc/rpc.go +++ b/server/grpc/rpc.go @@ -431,7 +431,6 @@ func (s *RPC) updateRemoteStatus(ctx context.Context, repo *model.Repo, build *m if err := s.store.UpdateUser(user); err != nil { log.Error().Err(err).Msg("fail to save user to store after refresh oauth token") } - } } uri := fmt.Sprintf("%s/%s/%d", server.Config.Server.Host, repo.FullName, build.Number) diff --git a/server/model/cc_test.go b/server/model/cc_test.go index b5081c23e..de4b7b8f5 100644 --- a/server/model/cc_test.go +++ b/server/model/cc_test.go @@ -22,10 +22,8 @@ import ( ) func TestCC(t *testing.T) { - g := goblin.Goblin(t) g.Describe("CC", func() { - g.It("Should create a project", func() { now := time.Now().Unix() now_fmt := time.Unix(now, 0).Format(time.RFC3339) diff --git a/server/model/secret_test.go b/server/model/secret_test.go index 55ade9191..259b35250 100644 --- a/server/model/secret_test.go +++ b/server/model/secret_test.go @@ -21,10 +21,8 @@ import ( ) func TestSecret(t *testing.T) { - g := goblin.Goblin(t) g.Describe("Secret", func() { - g.It("should match event", func() { secret := Secret{} secret.Events = []string{"pull_request"} diff --git a/server/remote/bitbucket/bitbucket_test.go b/server/remote/bitbucket/bitbucket_test.go index 1a8af9960..1a9a6b1e7 100644 --- a/server/remote/bitbucket/bitbucket_test.go +++ b/server/remote/bitbucket/bitbucket_test.go @@ -38,7 +38,6 @@ func Test_bitbucket(t *testing.T) { g := goblin.Goblin(t) ctx := context.Background() g.Describe("Bitbucket client", func() { - g.After(func() { s.Close() }) @@ -269,7 +268,6 @@ func Test_bitbucket(t *testing.T) { g.Assert(err).IsNil() g.Assert(r.FullName).Equal("user_name/repo_name") }) - }) } diff --git a/server/remote/bitbucket/convert_test.go b/server/remote/bitbucket/convert_test.go index 6491cf785..8ba4245ff 100644 --- a/server/remote/bitbucket/convert_test.go +++ b/server/remote/bitbucket/convert_test.go @@ -26,10 +26,8 @@ import ( ) func Test_helper(t *testing.T) { - g := goblin.Goblin(t) g.Describe("Bitbucket converter", func() { - g.It("should convert passing status", func() { g.Assert(convertStatus(model.StatusSuccess)).Equal(statusSuccess) }) diff --git a/server/remote/bitbucket/parse_test.go b/server/remote/bitbucket/parse_test.go index 4ad4891a1..171c8e7a9 100644 --- a/server/remote/bitbucket/parse_test.go +++ b/server/remote/bitbucket/parse_test.go @@ -25,10 +25,8 @@ import ( ) func Test_parser(t *testing.T) { - g := goblin.Goblin(t) g.Describe("Bitbucket parser", func() { - g.It("Should ignore unsupported hook", func() { buf := bytes.NewBufferString(fixtures.HookPush) req, _ := http.NewRequest("POST", "/hook", buf) @@ -42,7 +40,6 @@ func Test_parser(t *testing.T) { }) g.Describe("Given a pull request hook payload", func() { - g.It("Should return err when malformed", func() { buf := bytes.NewBufferString("[]") req, _ := http.NewRequest("POST", "/hook", buf) @@ -79,7 +76,6 @@ func Test_parser(t *testing.T) { }) g.Describe("Given a push hook payload", func() { - g.It("Should return err when malformed", func() { buf := bytes.NewBufferString("[]") req, _ := http.NewRequest("POST", "/hook", buf) diff --git a/server/remote/bitbucketserver/bitbucketserver.go b/server/remote/bitbucketserver/bitbucketserver.go index 6f5466b75..b3b89806a 100644 --- a/server/remote/bitbucketserver/bitbucketserver.go +++ b/server/remote/bitbucketserver/bitbucketserver.go @@ -129,7 +129,6 @@ func (c *Config) Login(ctx context.Context, res http.ResponseWriter, req *http.R } return convertUser(user, accessToken), nil - } // Auth is not supported by the Stash driver. diff --git a/server/remote/bitbucketserver/convert.go b/server/remote/bitbucketserver/convert.go index 2089ad1da..384a1f30a 100644 --- a/server/remote/bitbucketserver/convert.go +++ b/server/remote/bitbucketserver/convert.go @@ -72,7 +72,6 @@ func convertDesc(status model.StatusValue) string { // convertRepo is a helper function used to convert a Bitbucket server repository // structure to the common Woodpecker repository structure. func convertRepo(from *internal.Repo) *model.Repo { - repo := model.Repo{ Name: from.Slug, Owner: from.Project.Key, @@ -98,7 +97,6 @@ func convertRepo(from *internal.Repo) *model.Repo { } } return &repo - } // convertPushHook is a helper function used to convert a Bitbucket push diff --git a/server/remote/bitbucketserver/convert_test.go b/server/remote/bitbucketserver/convert_test.go index f8a01fb8e..a6b813256 100644 --- a/server/remote/bitbucketserver/convert_test.go +++ b/server/remote/bitbucketserver/convert_test.go @@ -25,10 +25,8 @@ import ( ) func Test_helper(t *testing.T) { - g := goblin.Goblin(t) g.Describe("Bitbucket Server converter", func() { - g.It("should convert repository", func() { from := &internal.Repo{ Slug: "hello-world", diff --git a/server/remote/bitbucketserver/internal/client.go b/server/remote/bitbucketserver/internal/client.go index 568537af6..2f2525dc9 100644 --- a/server/remote/bitbucketserver/internal/client.go +++ b/server/remote/bitbucketserver/internal/client.go @@ -103,7 +103,6 @@ func (c *Client) FindCurrentUser() (*User, error) { } return &user, nil - } func (c *Client) FindRepo(owner string, name string) (*Repo, error) { @@ -178,7 +177,6 @@ func (c *Client) CreateHook(owner string, name string, callBackLink string) erro return err } hooks = hookSettingsToArray(hookSettings) - } if !stringInSlice(callBackLink, hooks) { hooks = append(hooks, callBackLink) @@ -195,13 +193,11 @@ func (c *Client) CreateStatus(revision string, status *BuildStatus) error { } func (c *Client) DeleteHook(owner string, name string, link string) error { - hookSettings, err := c.GetHooks(owner, name) if err != nil { return err } putHooks := filter(hookSettingsToArray(hookSettings), func(item string) bool { - return !strings.Contains(item, link) }) putHookSettings := arrayToHookSettings(putHooks) diff --git a/server/remote/coding/coding_test.go b/server/remote/coding/coding_test.go index d958905c3..dae813858 100644 --- a/server/remote/coding/coding_test.go +++ b/server/remote/coding/coding_test.go @@ -37,7 +37,6 @@ func Test_coding(t *testing.T) { ctx := context.Background() g := goblin.Goblin(t) g.Describe("Coding", func() { - g.After(func() { s.Close() }) @@ -229,7 +228,6 @@ func Test_coding(t *testing.T) { g.Assert(r.FullName).Equal("demo1/test1") }) }) - }) } diff --git a/server/remote/coding/hook_test.go b/server/remote/coding/hook_test.go index 41d566355..eb035f36a 100644 --- a/server/remote/coding/hook_test.go +++ b/server/remote/coding/hook_test.go @@ -27,12 +27,9 @@ import ( ) func Test_hook(t *testing.T) { - g := goblin.Goblin(t) g.Describe("Coding hook", func() { - g.It("Should parse hook", func() { - reader := ioutil.NopCloser(strings.NewReader(fixtures.PushHook)) r := &http.Request{ Header: map[string][]string{ @@ -107,7 +104,6 @@ func Test_hook(t *testing.T) { }) g.It("Should parse push hook", func() { - repo := &model.Repo{ Owner: "demo1", Name: "test1", @@ -143,7 +139,6 @@ func Test_hook(t *testing.T) { }) g.It("Should parse pull request hook", func() { - repo := &model.Repo{ Owner: "demo1", Name: "test2", @@ -173,7 +168,6 @@ func Test_hook(t *testing.T) { }) g.It("Should parse merge request hook", func() { - repo := &model.Repo{ Owner: "demo1", Name: "test1", @@ -201,6 +195,5 @@ func Test_hook(t *testing.T) { g.Assert(actualRepo).Equal(repo) g.Assert(actualBuild).Equal(build) }) - }) } diff --git a/server/remote/coding/util_test.go b/server/remote/coding/util_test.go index 4cd98a607..ae3ac410e 100644 --- a/server/remote/coding/util_test.go +++ b/server/remote/coding/util_test.go @@ -21,10 +21,8 @@ import ( ) func Test_util(t *testing.T) { - g := goblin.Goblin(t) g.Describe("Coding util", func() { - g.It("Should form project full name", func() { g.Assert(projectFullName("gk", "prj")).Equal("gk/prj") }) diff --git a/server/remote/gitea/gitea_test.go b/server/remote/gitea/gitea_test.go index 79a430674..9df48dc6b 100644 --- a/server/remote/gitea/gitea_test.go +++ b/server/remote/gitea/gitea_test.go @@ -38,7 +38,6 @@ func Test_gitea(t *testing.T) { ctx := context.Background() g := goblin.Goblin(t) g.Describe("Gitea", func() { - g.After(func() { s.Close() }) diff --git a/server/remote/gitea/helper_test.go b/server/remote/gitea/helper_test.go index 202ea90fa..330ae483a 100644 --- a/server/remote/gitea/helper_test.go +++ b/server/remote/gitea/helper_test.go @@ -26,10 +26,8 @@ import ( ) func Test_parse(t *testing.T) { - g := goblin.Goblin(t) g.Describe("Gitea", func() { - g.It("Should parse push hook payload", func() { buf := bytes.NewBufferString(fixtures.HookPush) hook, err := parsePush(buf) @@ -108,7 +106,6 @@ func Test_parse(t *testing.T) { g.Assert(build.Message).Equal(hook.Commits[0].Message) g.Assert(build.Avatar).Equal("http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87") g.Assert(build.Author).Equal(hook.Sender.Login) - }) g.It("Should return a Repo struct from a push hook", func() { @@ -146,7 +143,6 @@ func Test_parse(t *testing.T) { g.Assert(build.Message).Equal(hook.PullRequest.Title) g.Assert(build.Avatar).Equal("http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87") g.Assert(build.Author).Equal(hook.PullRequest.User.Username) - }) g.It("Should return a Repo struct from a pull_request hook", func() { @@ -220,7 +216,6 @@ func Test_parse(t *testing.T) { }) g.It("Should correct a malformed avatar url", func() { - var urls = []struct { Before string After string diff --git a/server/remote/github/convert_test.go b/server/remote/github/convert_test.go index b3f320e78..cb408bc4e 100644 --- a/server/remote/github/convert_test.go +++ b/server/remote/github/convert_test.go @@ -24,10 +24,8 @@ import ( ) func Test_helper(t *testing.T) { - g := goblin.Goblin(t) g.Describe("GitHub converter", func() { - g.It("should convert passing status", func() { g.Assert(convertStatus(model.StatusSuccess)).Equal(statusSuccess) }) diff --git a/server/remote/github/github_test.go b/server/remote/github/github_test.go index ba6dece3b..fa4099ed7 100644 --- a/server/remote/github/github_test.go +++ b/server/remote/github/github_test.go @@ -38,7 +38,6 @@ func Test_github(t *testing.T) { ctx := context.Background() g := goblin.Goblin(t) g.Describe("GitHub", func() { - g.After(func() { s.Close() }) diff --git a/server/remote/github/parse_test.go b/server/remote/github/parse_test.go index 7cf285368..696d6c247 100644 --- a/server/remote/github/parse_test.go +++ b/server/remote/github/parse_test.go @@ -26,10 +26,8 @@ import ( ) func Test_parser(t *testing.T) { - g := goblin.Goblin(t) g.Describe("GitHub parser", func() { - g.It("should ignore unsupported hook events", func() { buf := bytes.NewBufferString(fixtures.HookPullRequest) req, _ := http.NewRequest("POST", "/hook", buf) @@ -109,6 +107,5 @@ func Test_parser(t *testing.T) { g.Assert(b.Event).Equal(model.EventDeploy) }) }) - }) } diff --git a/server/remote/gogs/gogs_test.go b/server/remote/gogs/gogs_test.go index 5d07adb31..8e95774b5 100644 --- a/server/remote/gogs/gogs_test.go +++ b/server/remote/gogs/gogs_test.go @@ -38,7 +38,6 @@ func Test_gogs(t *testing.T) { ctx := context.Background() g := goblin.Goblin(t) g.Describe("Gogs", func() { - g.After(func() { s.Close() }) diff --git a/server/remote/gogs/helper_test.go b/server/remote/gogs/helper_test.go index 6a6335fcc..79b816c38 100644 --- a/server/remote/gogs/helper_test.go +++ b/server/remote/gogs/helper_test.go @@ -26,10 +26,8 @@ import ( ) func Test_parse(t *testing.T) { - g := goblin.Goblin(t) g.Describe("Gogs", func() { - g.It("Should parse push hook payload", func() { buf := bytes.NewBufferString(fixtures.HookPush) hook, err := parsePush(buf) @@ -105,7 +103,6 @@ func Test_parse(t *testing.T) { g.Assert(build.Message).Equal(hook.Commits[0].Message) g.Assert(build.Avatar).Equal("http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87") g.Assert(build.Author).Equal(hook.Sender.Login) - }) g.It("Should return a Repo struct from a push hook", func() { @@ -130,7 +127,6 @@ func Test_parse(t *testing.T) { g.Assert(build.Message).Equal(hook.PullRequest.Title) g.Assert(build.Avatar).Equal("http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87") g.Assert(build.Author).Equal(hook.PullRequest.User.Username) - }) g.It("Should return a Repo struct from a pull_request hook", func() { @@ -192,7 +188,6 @@ func Test_parse(t *testing.T) { }) g.It("Should correct a malformed avatar url", func() { - var urls = []struct { Before string After string diff --git a/server/router/middleware/session/repo.go b/server/router/middleware/session/repo.go index 33b9b068a..5230e16cd 100644 --- a/server/router/middleware/session/repo.go +++ b/server/router/middleware/session/repo.go @@ -132,7 +132,6 @@ func SetPerm() gin.HandlerFunc { if user != nil { log.Debug().Msgf("%s granted %+v permission to %s", user.Login, perm, repo.FullName) - } else { log.Debug().Msgf("Guest granted %+v to %s", perm, repo.FullName) } @@ -181,7 +180,6 @@ func MustPush(c *gin.Context) { c.AbortWithStatus(http.StatusNotFound) log.Debug().Msgf("User %s denied write access to %s", user.Login, c.Request.URL.Path) - } else { c.AbortWithStatus(http.StatusUnauthorized) log.Debug().Msgf("Guest denied write access to %s %s", diff --git a/server/shared/procBuilder_test.go b/server/shared/procBuilder_test.go index 3fb8cd39f..7cd45f10f 100644 --- a/server/shared/procBuilder_test.go +++ b/server/shared/procBuilder_test.go @@ -454,5 +454,4 @@ func TestSanitizePath(t *testing.T) { t.Fatal("Path hasn't been sanitized correctly") } } - } diff --git a/server/store/datastore/repo_test.go b/server/store/datastore/repo_test.go index 278037e19..d9f53b548 100644 --- a/server/store/datastore/repo_test.go +++ b/server/store/datastore/repo_test.go @@ -30,7 +30,6 @@ func TestRepos(t *testing.T) { g := goblin.Goblin(t) g.Describe("Repo", func() { - // before each test be sure to purge the package // table data from the database. g.BeforeEach(func() { diff --git a/server/store/datastore/users_test.go b/server/store/datastore/users_test.go index 4a5030db7..67c407286 100644 --- a/server/store/datastore/users_test.go +++ b/server/store/datastore/users_test.go @@ -28,7 +28,6 @@ func TestUsers(t *testing.T) { g := goblin.Goblin(t) g.Describe("User", func() { - // before each test be sure to purge the package // table data from the database. g.BeforeEach(func() { diff --git a/shared/token/token.go b/shared/token/token.go index 81391aa6b..96bd848ad 100644 --- a/shared/token/token.go +++ b/shared/token/token.go @@ -82,7 +82,6 @@ func ParseRequest(r *http.Request, fn SecretFunc) (*Token, error) { } func CheckCsrf(r *http.Request, fn SecretFunc) error { - // get and options requests are always // enabled, without CSRF checks. switch r.Method {