1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-24 08:02:18 +02:00

gofumpt -w -l -extra . (#661)

This commit is contained in:
6543 2022-01-05 21:50:23 +01:00 committed by GitHub
parent dec0eeeed7
commit 2f91bdd4a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 79 additions and 90 deletions

View File

@ -75,7 +75,7 @@ func NewClient(c *cli.Context) (woodpecker.Client, error) {
// ParseRepo parses the repository owner and name from a string. // ParseRepo parses the repository owner and name from a string.
func ParseRepo(str string) (user, repo string, err error) { func ParseRepo(str string) (user, repo string, err error) {
var parts = strings.Split(str, "/") parts := strings.Split(str, "/")
if len(parts) != 2 { if len(parts) != 2 {
err = fmt.Errorf("Error: Invalid or missing repository. eg octocat/hello-world") err = fmt.Errorf("Error: Invalid or missing repository. eg octocat/hello-world")
return return

View File

@ -93,7 +93,7 @@ func loop(c *cli.Context) error {
// grpc.Dial(target, )) // grpc.Dial(target, ))
var transport = grpc.WithInsecure() transport := grpc.WithInsecure()
if c.Bool("secure-grpc") { if c.Bool("secure-grpc") {
transport = grpc.WithTransportCredentials(grpccredentials.NewTLS(&tls.Config{InsecureSkipVerify: c.Bool("skip-insecure-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"), Timeout: c.Duration("keepalive-timeout"),
}), }),
) )
if err != nil { if err != nil {
return err return err
} }

View File

@ -226,7 +226,7 @@ func run(c *cli.Context) error {
} }
dir := cacheDir() dir := cacheDir()
if err := os.MkdirAll(dir, 0700); err != nil { if err := os.MkdirAll(dir, 0o700); err != nil {
return err return err
} }

View File

@ -7,9 +7,7 @@ import (
"github.com/woodpecker-ci/woodpecker/pipeline/backend/types" "github.com/woodpecker-ci/woodpecker/pipeline/backend/types"
) )
var ( var engines map[string]types.Engine
engines map[string]types.Engine
)
func init() { func init() {
engines = make(map[string]types.Engine) engines = make(map[string]types.Engine)

View File

@ -9,9 +9,7 @@ import (
// to create and manage container resources. // to create and manage container resources.
type Engine interface { type Engine interface {
Name() string Name() string
IsAvailable() bool IsAvailable() bool
Load() error Load() error
// Setup the pipeline environment. // Setup the pipeline environment.

View File

@ -168,7 +168,7 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config {
var stage *backend.Stage var stage *backend.Stage
var group string var group string
for i, container := range conf.Pipeline.Containers { 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() { if c.local && !container.Constraints.Local.Bool() {
continue continue
} }

View File

@ -99,7 +99,7 @@ func (c *Constraint) Excludes(v string) bool {
// UnmarshalYAML unmarshals the constraint. // UnmarshalYAML unmarshals the constraint.
func (c *Constraint) UnmarshalYAML(value *yaml.Node) error { func (c *Constraint) UnmarshalYAML(value *yaml.Node) error {
var out1 = struct { out1 := struct {
Include types.Stringorslice Include types.Stringorslice
Exclude types.Stringorslice Exclude types.Stringorslice
}{} }{}
@ -177,7 +177,7 @@ func (c *ConstraintMap) UnmarshalYAML(unmarshal func(interface{}) error) error {
// UnmarshalYAML unmarshals the constraint. // UnmarshalYAML unmarshals the constraint.
func (c *ConstraintPath) UnmarshalYAML(value *yaml.Node) error { func (c *ConstraintPath) UnmarshalYAML(value *yaml.Node) error {
var out1 = struct { out1 := struct {
Include types.Stringorslice `yaml:"include,omitempty"` Include types.Stringorslice `yaml:"include,omitempty"`
Exclude types.Stringorslice `yaml:"exclude,omitempty"` Exclude types.Stringorslice `yaml:"exclude,omitempty"`
IgnoreMessage string `yaml:"ignore_message,omitempty"` IgnoreMessage string `yaml:"ignore_message,omitempty"`

View File

@ -24,7 +24,6 @@ func (s *StringorInt) UnmarshalYAML(unmarshal func(interface{}) error) error {
var stringType string var stringType string
if err := unmarshal(&stringType); err == nil { if err := unmarshal(&stringType); err == nil {
intType, err := strconv.ParseInt(stringType, 10, 64) intType, err := strconv.ParseInt(stringType, 10, 64)
if err != nil { if err != nil {
return err return err
} }
@ -50,7 +49,6 @@ func (s *MemStringorInt) UnmarshalYAML(unmarshal func(interface{}) error) error
var stringType string var stringType string
if err := unmarshal(&stringType); err == nil { if err := unmarshal(&stringType); err == nil {
intType, err := units.RAMInBytes(stringType) intType, err := units.RAMInBytes(stringType)
if err != nil { if err != nil {
return err return err
} }

View File

@ -473,7 +473,7 @@ func PostBuild(c *gin.Context) {
} }
// Read query string parameters into buildParams, exclude reserved params // 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() { for key, val := range c.Request.URL.Query() {
switch key { switch key {
// Skip some options of the endpoint // Skip some options of the endpoint

View File

@ -24,10 +24,8 @@ import (
"github.com/woodpecker-ci/woodpecker/server" "github.com/woodpecker-ci/woodpecker/server"
) )
var ( // errInvalidToken is returned when the api request token is invalid.
// errInvalidToken is returned when the api request token is invalid. var errInvalidToken = errors.New("Invalid or missing token")
errInvalidToken = errors.New("Invalid or missing token")
)
// PromHandler will pass the call from /api/metrics/prometheus to prometheus // PromHandler will pass the call from /api/metrics/prometheus to prometheus
func PromHandler() gin.HandlerFunc { func PromHandler() gin.HandlerFunc {

View File

@ -61,7 +61,7 @@ func (r *Repo) ResetVisibility() {
// ParseRepo parses the repository owner and name from a string. // ParseRepo parses the repository owner and name from a string.
func ParseRepo(str string) (user, repo string, err error) { func ParseRepo(str string) (user, repo string, err error) {
var parts = strings.Split(str, "/") parts := strings.Split(str, "/")
if len(parts) != 2 { if len(parts) != 2 {
err = fmt.Errorf("Error: Invalid or missing repository. eg octocat/hello-world") err = fmt.Errorf("Error: Invalid or missing repository. eg octocat/hello-world")
return return

View File

@ -17,7 +17,7 @@ package model
import "testing" import "testing"
func TestUserValidate(t *testing.T) { func TestUserValidate(t *testing.T) {
var tests = []struct { tests := []struct {
user User user User
err error err error
}{ }{

View File

@ -336,7 +336,7 @@ func (q *fifo) depsInQueue(task *Task) bool {
return false return false
} }
func (q *fifo) updateDepStatusInQueue(taskID string, status string) { func (q *fifo) updateDepStatusInQueue(taskID, status string) {
var next *list.Element var next *list.Element
for e := q.pending.Front(); e != nil; e = next { for e := q.pending.Front(); e != nil; e = next {
next = e.Next() next = e.Next()

View File

@ -106,7 +106,7 @@ func (c *Client) ListRepos(account string, opts *ListOpts) (*RepoResp, error) {
} }
func (c *Client) ListReposAll(account string) ([]*Repo, error) { func (c *Client) ListReposAll(account string) ([]*Repo, error) {
var page = 1 page := 1
var repos []*Repo var repos []*Repo
for { for {
@ -164,7 +164,6 @@ func (c *Client) GetPermission(fullName string) (*RepoPerm, error) {
out := new(RepoPermResp) out := new(RepoPermResp)
uri := fmt.Sprintf(pathPermissions, c.base, fullName) uri := fmt.Sprintf(pathPermissions, c.base, fullName)
_, err := c.do(uri, get, nil, out) _, err := c.do(uri, get, nil, out)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -111,7 +111,7 @@ func (c *Config) Login(ctx context.Context, res http.ResponseWriter, req *http.R
if err != nil { if err != nil {
return nil, err return nil, err
} }
var code = req.FormValue("oauth_verifier") code := req.FormValue("oauth_verifier")
if len(code) == 0 { if len(code) == 0 {
http.Redirect(res, req, u, http.StatusSeeOther) http.Redirect(res, req, u, http.StatusSeeOther)
return nil, nil return nil, nil
@ -205,9 +205,9 @@ func (c *Config) Netrc(user *model.User, r *model.Repo) (*model.Netrc, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
//remove the port // remove the port
tmp := strings.Split(u.Host, ":") tmp := strings.Split(u.Host, ":")
var host = tmp[0] host := tmp[0]
if err != nil { if err != nil {
return nil, err return nil, err
@ -240,7 +240,7 @@ func (c *Config) Hook(r *http.Request) (*model.Repo, *model.Build, error) {
return parseHook(r, c.URL) 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( consumer := oauth.NewRSAConsumer(
ConsumerKey, ConsumerKey,
PrivateKey, PrivateKey,

View File

@ -88,7 +88,7 @@ func convertPushHook(hook *internal.PostHook, baseURL string) *model.Build {
"refs/tags/", "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 authorLabel := hook.Changesets.Values[0].ToCommit.Author.Name
if len(authorLabel) > 40 { if len(authorLabel) > 40 {
authorLabel = authorLabel[0:37] + "..." authorLabel = authorLabel[0:37] + "..."
@ -97,7 +97,7 @@ func convertPushHook(hook *internal.PostHook, baseURL string) *model.Build {
build := &model.Build{ build := &model.Build{
Commit: hook.RefChanges[0].ToHash, // TODO check for index value Commit: hook.RefChanges[0].ToHash, // TODO check for index value
Branch: branch, 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), Avatar: avatarLink(hook.Changesets.Values[0].ToCommit.Author.EmailAddress),
Author: authorLabel, Author: authorLabel,
Email: hook.Changesets.Values[0].ToCommit.Author.EmailAddress, Email: hook.Changesets.Values[0].ToCommit.Author.EmailAddress,

View File

@ -33,7 +33,7 @@ func Test_helper(t *testing.T) {
} }
from.Project.Key = "octocat" from.Project.Key = "octocat"
//var links [1]internal.LinkType // var links [1]internal.LinkType
link := internal.CloneLink{ link := internal.CloneLink{
Name: "http", Name: "http",
Href: "https://x7hw@server.org/foo/bar.git", Href: "https://x7hw@server.org/foo/bar.git",

View File

@ -105,7 +105,7 @@ func (c *Client) FindCurrentUser() (*User, error) {
return &user, nil 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) urlString := fmt.Sprintf(pathRepo, c.base, owner, name)
response, err := c.doGet(urlString) response, err := c.doGet(urlString)
if response != nil { if response != nil {
@ -130,7 +130,7 @@ func (c *Client) FindRepos() ([]*Repo, error) {
return c.paginatedRepos(0) 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) perms := new(model.Perm)
// If you don't have access return none right away // If you don't have access return none right away
_, err := c.FindRepo(owner, repo) _, err := c.FindRepo(owner, repo)
@ -150,7 +150,7 @@ func (c *Client) FindRepoPerms(owner string, repo string) (*model.Perm, error) {
return perms, nil 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)) response, err := c.doGet(fmt.Sprintf(pathSource, c.base, owner, repo, fileName, ref))
if response != nil { if response != nil {
defer response.Body.Close() defer response.Body.Close()
@ -168,7 +168,7 @@ func (c *Client) FindFileForRepo(owner string, repo string, fileName string, ref
return responseBytes, nil 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) hookDetails, err := c.GetHookDetails(owner, name)
if err != nil { if err != nil {
return err return err
@ -198,7 +198,7 @@ func (c *Client) CreateStatus(revision string, status *BuildStatus) error {
return c.doPost(uri, status) 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) hookSettings, err := c.GetHooks(owner, name)
if err != nil { if err != nil {
return err 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) 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) urlString := fmt.Sprintf(pathHookDetails, c.base, owner, name, hookName)
response, err := c.doGet(urlString) response, err := c.doGet(urlString)
if response != nil { if response != nil {
@ -229,7 +229,7 @@ func (c *Client) GetHookDetails(owner string, name string) (*HookPluginDetails,
return &hookDetails, err 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) urlString := fmt.Sprintf(pathHookSettings, c.base, owner, name, hookName)
response, err := c.doGet(urlString) response, err := c.doGet(urlString)
if response != nil { if response != nil {
@ -244,9 +244,9 @@ func (c *Client) GetHooks(owner string, name string) (*HookSettings, error) {
return &hookSettings, err 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) { func (c *Client) doGet(url string) (*http.Response, error) {
request, err := http.NewRequestWithContext(c.ctx, "GET", url, nil) request, err := http.NewRequestWithContext(c.ctx, "GET", url, nil)
if err != nil { if err != nil {
@ -256,7 +256,7 @@ func (c *Client) doGet(url string) (*http.Response, error) {
return c.client.Do(request) 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 { func (c *Client) doPut(url string, body []byte) error {
request, err := http.NewRequestWithContext(c.ctx, "PUT", url, bytes.NewBuffer(body)) request, err := http.NewRequestWithContext(c.ctx, "PUT", url, bytes.NewBuffer(body))
if err != nil { if err != nil {
@ -273,7 +273,7 @@ func (c *Client) doPut(url string, body []byte) error {
return nil 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 { func (c *Client) doPost(url string, status *BuildStatus) error {
// write it to the body of the request. // write it to the body of the request.
var buf io.ReadWriter var buf io.ReadWriter
@ -296,7 +296,7 @@ func (c *Client) doPost(url string, status *BuildStatus) error {
return err return err
} }
//Helper function to get repos paginated // Helper function to get repos paginated
func (c *Client) paginatedRepos(start int) ([]*Repo, error) { func (c *Client) paginatedRepos(start int) ([]*Repo, error) {
limit := 1000 limit := 1000
requestURL := fmt.Sprintf(pathRepos, c.base, strconv.Itoa(start), strconv.Itoa(limit)) 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 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 { func arrayToHookSettings(hooks []string) HookSettings {
hookSettings := HookSettings{} hookSettings := HookSettings{}
for loc, value := range hooks { for loc, value := range hooks {
@ -378,7 +378,7 @@ func arrayToHookSettings(hooks []string) HookSettings {
case 19: case 19:
hookSettings.HookURL19 = value 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: default:
hookSettings.HookURL19 = value hookSettings.HookURL19 = value
} }

View File

@ -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. // Gitea SDK forces us to read repo list paginated.
var page = 1 page := 1
for { for {
all, _, err := client.ListMyRepos( all, _, err := client.ListMyRepos(
gitea.ListReposOptions{ gitea.ListReposOptions{

View File

@ -216,7 +216,7 @@ func Test_parse(t *testing.T) {
}) })
g.It("Should correct a malformed avatar url", func() { g.It("Should correct a malformed avatar url", func() {
var urls = []struct { urls := []struct {
Before string Before string
After string After string
}{ }{
@ -245,7 +245,7 @@ func Test_parse(t *testing.T) {
}) })
g.It("Should expand the avatar url", func() { g.It("Should expand the avatar url", func() {
var urls = []struct { urls := []struct {
Before string Before string
After 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 { for _, url := range urls {
got := expandAvatar(repo, url.Before) got := expandAvatar(repo, url.Before)
g.Assert(got).Equal(url.After) g.Assert(got).Equal(url.After)

View File

@ -29,8 +29,8 @@ import (
func (g *Gitlab) convertGitlabRepo(_repo *gitlab.Project) (*model.Repo, error) { func (g *Gitlab) convertGitlabRepo(_repo *gitlab.Project) (*model.Repo, error) {
parts := strings.Split(_repo.PathWithNamespace, "/") parts := strings.Split(_repo.PathWithNamespace, "/")
// TODO(648) save repo id (support nested repos) // TODO(648) save repo id (support nested repos)
var owner = strings.Join(parts[:len(parts)-1], "/") owner := strings.Join(parts[:len(parts)-1], "/")
var name = parts[len(parts)-1] name := parts[len(parts)-1]
repo := &model.Repo{ repo := &model.Repo{
Owner: owner, Owner: owner,
Name: name, Name: name,

View File

@ -90,7 +90,7 @@ func New(opts Opts) (remote.Remote, error) {
// Login authenticates the session and returns the // Login authenticates the session and returns the
// remote user details. // remote user details.
func (g *Gitlab) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) { 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, ClientID: g.ClientID,
ClientSecret: g.ClientSecret, ClientSecret: g.ClientSecret,
Scope: defaultScope, Scope: defaultScope,
@ -109,17 +109,17 @@ func (g *Gitlab) Login(ctx context.Context, res http.ResponseWriter, req *http.R
} }
// get the OAuth code // get the OAuth code
var code = req.FormValue("code") code := req.FormValue("code")
if len(code) == 0 { if len(code) == 0 {
http.Redirect(res, req, config.AuthCodeURL("drone"), http.StatusSeeOther) http.Redirect(res, req, config.AuthCodeURL("drone"), http.StatusSeeOther)
return nil, nil 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}, TLSClientConfig: &tls.Config{InsecureSkipVerify: g.SkipVerify},
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
}} }}
var token, err = trans.Exchange(code) token, err := trans.Exchange(code)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error exchanging token. %s", err) 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 }, 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) uri, err := url.Parse(link)
if err != nil { if err != nil {
return "", "", err return "", "", err

View File

@ -52,19 +52,19 @@ func load(config string) *Gitlab {
func Test_Gitlab(t *testing.T) { func Test_Gitlab(t *testing.T) {
// setup a dummy github server // setup a dummy github server
var server = testdata.NewServer(t) server := testdata.NewServer(t)
defer server.Close() defer server.Close()
env := server.URL + "?client_id=test&client_secret=test" env := server.URL + "?client_id=test&client_secret=test"
client := load(env) client := load(env)
var user = model.User{ user := model.User{
Login: "test_user", Login: "test_user",
Token: "e3b0c44298fc1c149afbf4c8996fb", Token: "e3b0c44298fc1c149afbf4c8996fb",
} }
var repo = model.Repo{ repo := model.Repo{
Name: "diaspora-client", Name: "diaspora-client",
Owner: "diaspora", Owner: "diaspora",
} }

View File

@ -39,8 +39,8 @@ func newClient(url, accessToken string, skipVerify bool) (*gitlab.Client, error)
// isRead is a helper function that returns true if the // isRead is a helper function that returns true if the
// user has Read-only access to the repository. // user has Read-only access to the repository.
func isRead(proj *gitlab.Project) bool { func isRead(proj *gitlab.Project) bool {
var user = proj.Permissions.ProjectAccess user := proj.Permissions.ProjectAccess
var group = proj.Permissions.GroupAccess group := proj.Permissions.GroupAccess
switch { switch {
case proj.Public: case proj.Public:
@ -57,8 +57,8 @@ func isRead(proj *gitlab.Project) bool {
// isWrite is a helper function that returns true if the // isWrite is a helper function that returns true if the
// user has Read-Write access to the repository. // user has Read-Write access to the repository.
func isWrite(proj *gitlab.Project) bool { func isWrite(proj *gitlab.Project) bool {
var user = proj.Permissions.ProjectAccess user := proj.Permissions.ProjectAccess
var group = proj.Permissions.GroupAccess group := proj.Permissions.GroupAccess
switch { switch {
case user != nil && user.AccessLevel >= 30: 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 // isAdmin is a helper function that returns true if the
// user has Admin access to the repository. // user has Admin access to the repository.
func isAdmin(proj *gitlab.Project) bool { func isAdmin(proj *gitlab.Project) bool {
var user = proj.Permissions.ProjectAccess user := proj.Permissions.ProjectAccess
var group = proj.Permissions.GroupAccess group := proj.Permissions.GroupAccess
switch { switch {
case user != nil && user.AccessLevel >= 40: case user != nil && user.AccessLevel >= 40:

View File

@ -188,7 +188,7 @@ func Test_parse(t *testing.T) {
}) })
g.It("Should correct a malformed avatar url", func() { g.It("Should correct a malformed avatar url", func() {
var urls = []struct { urls := []struct {
Before string Before string
After string After string
}{ }{
@ -217,7 +217,7 @@ func Test_parse(t *testing.T) {
}) })
g.It("Should expand the avatar url", func() { g.It("Should expand the avatar url", func() {
var urls = []struct { urls := []struct {
Before string Before string
After 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 { for _, url := range urls {
got := expandAvatar(repo, url.Before) got := expandAvatar(repo, url.Before)
g.Assert(got).Equal(url.After) g.Assert(got).Equal(url.After)

View File

@ -19,5 +19,4 @@ import (
) )
func TestSetPerm(t *testing.T) { func TestSetPerm(t *testing.T) {
} }

View File

@ -22,8 +22,7 @@ import (
"github.com/woodpecker-ci/woodpecker/server/model" "github.com/woodpecker-ci/woodpecker/server/model"
) )
type mockUpdateBuildStore struct { type mockUpdateBuildStore struct{}
}
func (m *mockUpdateBuildStore) UpdateBuild(build *model.Build) error { func (m *mockUpdateBuildStore) UpdateBuild(build *model.Build) error {
return nil return nil

View File

@ -49,7 +49,8 @@ pipeline:
image: scratch image: scratch
yyy: ${CI_COMMIT_MESSAGE} yyy: ${CI_COMMIT_MESSAGE}
`)}, `)},
}} },
}
if buildItems, err := b.Build(); err != nil { if buildItems, err := b.Build(); err != nil {
t.Fatal(err) t.Fatal(err)
@ -404,7 +405,8 @@ func TestTree(t *testing.T) {
Secs: []*model.Secret{}, Secs: []*model.Secret{},
Regs: []*model.Registry{}, Regs: []*model.Registry{},
Link: "", Link: "",
Yamls: []*remote.FileMeta{{Data: []byte(` Yamls: []*remote.FileMeta{
{Data: []byte(`
pipeline: pipeline:
build: build:
image: scratch image: scratch

View File

@ -22,8 +22,7 @@ import (
"github.com/woodpecker-ci/woodpecker/server/model" "github.com/woodpecker-ci/woodpecker/server/model"
) )
type mockUpdateProcStore struct { type mockUpdateProcStore struct{}
}
func (m *mockUpdateProcStore) ProcUpdate(build *model.Proc) error { func (m *mockUpdateProcStore) ProcUpdate(build *model.Proc) error {
return nil return nil

View File

@ -212,8 +212,10 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
return nil return nil
} }
var whitespaces = regexp.MustCompile(`\s+`) var (
var columnSeparator = regexp.MustCompile(`\s?,\s?`) whitespaces = regexp.MustCompile(`\s+`)
columnSeparator = regexp.MustCompile(`\s?,\s?`)
)
func removeColumnFromSQLITETableSchema(schema string, names ...string) string { func removeColumnFromSQLITETableSchema(schema string, names ...string) string {
if len(names) == 0 { if len(names) == 0 {

View File

@ -36,7 +36,7 @@ func createSQLiteDB(t *testing.T) string {
t.FailNow() t.FailNow()
} }
if !assert.NoError(t, ioutil.WriteFile(tmpF.Name(), dbF, 0644)) { if !assert.NoError(t, ioutil.WriteFile(tmpF.Name(), dbF, 0o644)) {
t.FailNow() t.FailNow()
} }
return tmpF.Name() return tmpF.Name()

View File

@ -54,7 +54,7 @@ func Config(c *gin.Context) {
} }
// default func map with json parser. // default func map with json parser.
var funcMap = template.FuncMap{ funcMap := template.FuncMap{
"json": func(v interface{}) string { "json": func(v interface{}) string {
a, _ := json.Marshal(v) a, _ := json.Marshal(v)
return string(a) return string(a)

View File

@ -88,7 +88,7 @@ func (f CacheFile) Token() (*Token, error) {
} }
func (f CacheFile) PutToken(tok *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 { if err != nil {
return OAuthError{"CacheFile.PutToken", err.Error()} return OAuthError{"CacheFile.PutToken", err.Error()}
} }

View File

@ -14,10 +14,8 @@
package version package version
var ( // Version of Woodpecker, set with ldflags, from Git tag
// Version of Woodpecker, set with ldflags, from Git tag var Version string
Version string
)
// String returns the Version set at build time or "dev" // String returns the Version set at build time or "dev"
func String() string { func String() string {

View File

@ -114,7 +114,7 @@ func (c *client) UserDel(login string) error {
} }
// Repo returns a repository by name. // 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) out := new(Repo)
uri := fmt.Sprintf(pathRepo, c.addr, owner, name) uri := fmt.Sprintf(pathRepo, c.addr, owner, name)
err := c.get(uri, out) err := c.get(uri, out)
@ -140,7 +140,7 @@ func (c *client) RepoListOpts(sync, all bool) ([]*Repo, error) {
} }
// RepoPost activates a repository. // 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) out := new(Repo)
uri := fmt.Sprintf(pathRepo, c.addr, owner, name) uri := fmt.Sprintf(pathRepo, c.addr, owner, name)
err := c.post(uri, nil, out) 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. // 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) out := new(Repo)
uri := fmt.Sprintf(pathChown, c.addr, owner, name) uri := fmt.Sprintf(pathChown, c.addr, owner, name)
err := c.post(uri, nil, out) 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. // 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) uri := fmt.Sprintf(pathRepair, c.addr, owner, name)
return c.post(uri, nil, nil) 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. // 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 var out []*Registry
uri := fmt.Sprintf(pathRepoRegistries, c.addr, owner, name) uri := fmt.Sprintf(pathRepoRegistries, c.addr, owner, name)
err := c.get(uri, &out) 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. // 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 var out []*Secret
uri := fmt.Sprintf(pathRepoSecrets, c.addr, owner, name) uri := fmt.Sprintf(pathRepoSecrets, c.addr, owner, name)
err := c.get(uri, &out) err := c.get(uri, &out)