Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linter staticcheck #535

Merged
merged 3 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ linters:
- bidichk
- misspell
- whitespace
- staticcheck

run:
timeout: 5m
Expand Down
9 changes: 6 additions & 3 deletions cli/loglevel/loglevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ func logLevel(c *cli.Context) error {
ll, err = client.SetLogLevel(&woodpecker.LogLevel{
Level: lvl.String(),
})
if err != nil {
return err
}
} else {
ll, err = client.LogLevel()
}
if err != nil {
return err
if err != nil {
return err
}
}

log.Info().Msgf("Logging level: %s", ll.Level)
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"context"
"fmt"
"os"
"time"
Expand Down Expand Up @@ -352,7 +353,7 @@ func setupMetrics(g *errgroup.Group, store_ store.Store) {

g.Go(func() error {
for {
stats := server.Config.Services.Queue.Info(nil)
stats := server.Config.Services.Queue.Info(context.TODO())
pendingJobs.Set(float64(stats.Stats.Pending))
waitingJobs.Set(float64(stats.Stats.WaitingOnDeps))
runningJobs.Set(float64(stats.Stats.Running))
Expand Down
6 changes: 3 additions & 3 deletions pipeline/backend/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ func (e *engine) Wait(ctx context.Context, proc *backend.Step) (*backend.State,
if err != nil {
return nil, err
}
if info.State.Running {
// todo
}
// if info.State.Running {
// TODO
// }

return &backend.State{
Exited: true,
Expand Down
2 changes: 1 addition & 1 deletion server/grpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (s *RPC) Update(c context.Context, id string, state rpc.State) error {
return err
}

if proc, err = shared.UpdateProcStatus(s.store, *proc, state, build.Started); err != nil {
if _, err = shared.UpdateProcStatus(s.store, *proc, state, build.Started); err != nil {
log.Error().Msgf("error: rpc.update: cannot update proc: %s", err)
}

Expand Down
4 changes: 2 additions & 2 deletions server/pubsub/pub.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func New() Publisher {

func (p *publisher) Create(c context.Context, dest string) error {
p.Lock()
t, ok := p.topics[dest]
_, ok := p.topics[dest]
if !ok {
t = newTopic(dest)
t := newTopic(dest)
p.topics[dest] = t
}
p.Unlock()
Expand Down
4 changes: 3 additions & 1 deletion server/queue/fifo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,9 @@ func TestWaitingVsPending(t *testing.T) {
}

assert.NoError(t, q.Error(noContext, got.ID, fmt.Errorf("exitcode 1, there was an error")))
got, _ = q.Poll(noContext, func(*Task) bool { return true })
got, err := q.Poll(noContext, func(*Task) bool { return true })
assert.NoError(t, err)
assert.EqualValues(t, task2, got)

6543 marked this conversation as resolved.
Show resolved Hide resolved
info = q.Info(noContext)
if info.Stats.WaitingOnDeps != 0 {
Expand Down
9 changes: 9 additions & 0 deletions server/remote/bitbucketserver/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func (c *Client) FindRepo(owner string, name string) (*Repo, error) {
log.Err(err).Msg("")
}
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
repo := Repo{}
err = json.Unmarshal(contents, &repo)
if err != nil {
Expand Down Expand Up @@ -184,6 +187,9 @@ func (c *Client) CreateHook(owner string, name string, callBackLink string) erro

putHookSettings := arrayToHookSettings(hooks)
hookBytes, err := json.Marshal(putHookSettings)
if err != nil {
return err
}
return c.doPut(fmt.Sprintf(pathHookEnabled, c.base, owner, name, hookName), hookBytes)
}

Expand All @@ -202,6 +208,9 @@ func (c *Client) DeleteHook(owner string, name string, link string) error {
})
putHookSettings := arrayToHookSettings(putHooks)
hookBytes, err := json.Marshal(putHookSettings)
if err != nil {
return err
}
return c.doPut(fmt.Sprintf(pathHookEnabled, c.base, owner, name, hookName), hookBytes)
}

Expand Down
2 changes: 1 addition & 1 deletion server/remote/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *Gitea) Login(ctx context.Context, w http.ResponseWriter, req *http.Requ
return nil, nil
}

token, err := config.Exchange(oauth2.NoContext, code)
token, err := config.Exchange(ctx, code)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions server/remote/github/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ func convertPushHook(from *webhook) *model.Build {
if len(build.Author) == 0 {
build.Author = from.Head.Author.Username
}
if len(build.Email) == 0 {
// default to gravatar?
}
// if len(build.Email) == 0 {
// TODO: default to gravatar?
// }
if strings.HasPrefix(build.Ref, "refs/tags/") {
// just kidding, this is actually a tag event. Why did this come as a push
// event we'll never know!
Expand Down
3 changes: 1 addition & 2 deletions server/remote/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,11 @@ func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model
}

var files []*remote.FileMeta
var errors []error

for i := 0; i < len(data); i++ {
select {
case err := <-errc:
errors = append(errors, err)
return nil, err
case fileMeta := <-fc:
files = append(files, fileMeta)
}
Expand Down