Skip to content

Commit

Permalink
gofumpt -w -l -extra . (woodpecker-ci#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 authored Jan 5, 2022
1 parent dec0eee commit 2f91bdd
Show file tree
Hide file tree
Showing 35 changed files with 79 additions and 90 deletions.
2 changes: 1 addition & 1 deletion cli/internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions cmd/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")}))
Expand All @@ -111,7 +111,6 @@ func loop(c *cli.Context) error {
Timeout: c.Duration("keepalive-timeout"),
}),
)

if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 1 addition & 3 deletions pipeline/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions pipeline/backend/types/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
// to create and manage container resources.
type Engine interface {
Name() string

IsAvailable() bool

Load() error

// Setup the pipeline environment.
Expand Down
2 changes: 1 addition & 1 deletion pipeline/frontend/yaml/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pipeline/frontend/yaml/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}{}
Expand Down Expand Up @@ -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"`
Expand Down
2 changes: 0 additions & 2 deletions pipeline/frontend/yaml/types/types_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion server/api/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions server/api/metrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server/model/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/model/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package model
import "testing"

func TestUserValidate(t *testing.T) {
var tests = []struct {
tests := []struct {
user User
err error
}{
Expand Down
2 changes: 1 addition & 1 deletion server/queue/fifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions server/remote/bitbucket/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions server/remote/bitbucketserver/bitbucketserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions server/remote/bitbucketserver/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] + "..."
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/remote/bitbucketserver/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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://[email protected]/foo/bar.git",
Expand Down
28 changes: 14 additions & 14 deletions server/remote/bitbucketserver/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
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 @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions server/remote/gitea/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}{
Expand Down Expand Up @@ -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
}{
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions server/remote/gitlab/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 2f91bdd

Please sign in to comment.