Enable golangci linter stylecheck (#3167)

This PR only fixes error string formatting, log message strings are
still mixed upper/lowercase (see
https://github.com/woodpecker-ci/woodpecker/pull/3161#issuecomment-1885140649)
and I'm not aware of a linter to enforce it.
This commit is contained in:
Robert Kaussow 2024-01-10 22:56:42 +01:00 committed by GitHub
parent 00df53e941
commit 7756c60a33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
58 changed files with 126 additions and 129 deletions

View file

@ -163,6 +163,7 @@ linters:
- whitespace - whitespace
- gocritic - gocritic
- nolintlint - nolintlint
- stylecheck
run: run:
timeout: 15m timeout: 15m

View file

@ -64,7 +64,6 @@ func FormatFlag(tmpl string, hidden ...bool) *cli.StringFlag {
} }
} }
// specify repository
var RepoFlag = &cli.StringFlag{ var RepoFlag = &cli.StringFlag{
Name: "repository", Name: "repository",
Aliases: []string{"repo"}, Aliases: []string{"repo"},

View file

@ -97,7 +97,7 @@ func deploy(c *cli.Context) error {
} }
} }
if number == 0 { if number == 0 {
return fmt.Errorf("Cannot deploy failure pipeline") return fmt.Errorf("cannot deploy failure pipeline")
} }
} else { } else {
number, err = strconv.ParseInt(pipelineArg, 10, 64) number, err = strconv.ParseInt(pipelineArg, 10, 64)
@ -108,7 +108,7 @@ func deploy(c *cli.Context) error {
env := c.Args().Get(2) env := c.Args().Get(2)
if env == "" { if env == "" {
return fmt.Errorf("Please specify the target environment (ie production)") return fmt.Errorf("please specify the target environment (i.e. production)")
} }
params := internal.ParseKeyPair(c.StringSlice("param")) params := internal.ParseKeyPair(c.StringSlice("param"))

View file

@ -41,7 +41,7 @@ func userInfo(c *cli.Context) error {
login := c.Args().First() login := c.Args().First()
if len(login) == 0 { if len(login) == 0 {
return fmt.Errorf("Missing or invalid user login") return fmt.Errorf("missing or invalid user login")
} }
user, err := client.User(login) user, err := client.User(login)

View file

@ -255,7 +255,7 @@ func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string)
} }
if isImagePullBackOffState(pod) { if isImagePullBackOffState(pod) {
return nil, fmt.Errorf("Could not pull image for pod %s", pod.Name) return nil, fmt.Errorf("could not pull image for pod %s", pod.Name)
} }
bs := &types.State{ bs := &types.State{

View file

@ -261,7 +261,7 @@ func (c *List) UnmarshalYAML(value *yaml.Node) error {
if err1 != nil && err2 != nil { if err1 != nil && err2 != nil {
y, _ := yaml.Marshal(value) y, _ := yaml.Marshal(value)
return fmt.Errorf("Could not parse condition: %s: %w", y, multierr.Append(err1, err2)) return fmt.Errorf("could not parse condition: %s: %w", y, multierr.Append(err1, err2))
} }
return nil return nil
@ -342,7 +342,7 @@ func (c *Path) UnmarshalYAML(value *yaml.Node) error {
if err1 != nil && err2 != nil { if err1 != nil && err2 != nil {
y, _ := yaml.Marshal(value) y, _ := yaml.Marshal(value)
return fmt.Errorf("Could not parse condition: %s", y) return fmt.Errorf("could not parse condition: %s", y)
} }
return nil return nil

View file

@ -36,29 +36,29 @@ func Lint(r io.Reader) ([]gojsonschema.ResultError, error) {
// read yaml config // read yaml config
rBytes, err := io.ReadAll(r) rBytes, err := io.ReadAll(r)
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed to load yml file %w", err) return nil, fmt.Errorf("failed to load yml file %w", err)
} }
// resolve sequence merges // resolve sequence merges
yamlDoc := new(yaml.Node) yamlDoc := new(yaml.Node)
if err := xyaml.Unmarshal(rBytes, yamlDoc); err != nil { if err := xyaml.Unmarshal(rBytes, yamlDoc); err != nil {
return nil, fmt.Errorf("Failed to parse yml file %w", err) return nil, fmt.Errorf("failed to parse yml file %w", err)
} }
// convert to json // convert to json
jsonDoc, err := yaml2json.ConvertNode(yamlDoc) jsonDoc, err := yaml2json.ConvertNode(yamlDoc)
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed to convert yaml %w", err) return nil, fmt.Errorf("failed to convert yaml %w", err)
} }
documentLoader := gojsonschema.NewBytesLoader(jsonDoc) documentLoader := gojsonschema.NewBytesLoader(jsonDoc)
result, err := gojsonschema.Validate(schemaLoader, documentLoader) result, err := gojsonschema.Validate(schemaLoader, documentLoader)
if err != nil { if err != nil {
return nil, fmt.Errorf("Validation failed %w", err) return nil, fmt.Errorf("validation failed %w", err)
} }
if !result.Valid() { if !result.Valid() {
return result.Errors(), fmt.Errorf("Config not valid") return result.Errors(), fmt.Errorf("config not valid")
} }
return nil, nil return nil, nil

View file

@ -104,7 +104,7 @@ bars: []
func TestUnmarshalSliceOrMap(t *testing.T) { func TestUnmarshalSliceOrMap(t *testing.T) {
s := StructSliceorMap{} s := StructSliceorMap{}
err := yaml.Unmarshal([]byte(sampleStructSliceorMap), &s) err := yaml.Unmarshal([]byte(sampleStructSliceorMap), &s)
assert.Equal(t, fmt.Errorf("Cannot unmarshal 'true' of type bool into a string value"), err) assert.Equal(t, fmt.Errorf("cannot unmarshal 'true' of type bool into a string value"), err)
} }
func TestStr2SliceOrMapPtrMap(t *testing.T) { func TestStr2SliceOrMapPtrMap(t *testing.T) {

View file

@ -42,7 +42,7 @@ func (s *StringOrInt) UnmarshalYAML(unmarshal func(any) error) error {
return nil return nil
} }
return errors.New("Failed to unmarshal StringOrInt") return errors.New("failed to unmarshal StringOrInt")
} }
// MemStringOrInt represents a string or an integer // MemStringOrInt represents a string or an integer
@ -67,5 +67,5 @@ func (s *MemStringOrInt) UnmarshalYAML(unmarshal func(any) error) error {
return nil return nil
} }
return errors.New("Failed to unmarshal MemStringOrInt") return errors.New("failed to unmarshal MemStringOrInt")
} }

View file

@ -40,7 +40,7 @@ func (s *SliceOrMap) UnmarshalYAML(unmarshal func(any) error) error {
} }
parts[key] = val parts[key] = val
} else { } else {
return fmt.Errorf("Cannot unmarshal '%v' of type %T into a string value", s, s) return fmt.Errorf("cannot unmarshal '%v' of type %T into a string value", s, s)
} }
} }
*s = parts *s = parts
@ -55,15 +55,15 @@ func (s *SliceOrMap) UnmarshalYAML(unmarshal func(any) error) error {
if sv, ok := v.(string); ok { if sv, ok := v.(string); ok {
parts[sk] = sv parts[sk] = sv
} else { } else {
return fmt.Errorf("Cannot unmarshal '%v' of type %T into a string value", v, v) return fmt.Errorf("cannot unmarshal '%v' of type %T into a string value", v, v)
} }
} else { } else {
return fmt.Errorf("Cannot unmarshal '%v' of type %T into a string value", k, k) return fmt.Errorf("cannot unmarshal '%v' of type %T into a string value", k, k)
} }
} }
*s = parts *s = parts
return nil return nil
} }
return errors.New("Failed to unmarshal SliceOrMap") return errors.New("failed to unmarshal SliceOrMap")
} }

View file

@ -41,7 +41,7 @@ func (s *StringOrSlice) UnmarshalYAML(unmarshal func(any) error) error {
return nil return nil
} }
return errors.New("Failed to unmarshal StringOrSlice") return errors.New("failed to unmarshal StringOrSlice")
} }
func toStrings(s []any) ([]string, error) { func toStrings(s []any) ([]string, error) {
@ -53,7 +53,7 @@ func toStrings(s []any) ([]string, error) {
if sv, ok := v.(string); ok { if sv, ok := v.(string); ok {
r[k] = sv r[k] = sv
} else { } else {
return nil, fmt.Errorf("Cannot unmarshal '%v' of type %T into a string value", v, v) return nil, fmt.Errorf("cannot unmarshal '%v' of type %T into a string value", v, v)
} }
} }
return r, nil return r, nil

View file

@ -50,7 +50,7 @@ func (n *Networks) UnmarshalYAML(unmarshal func(any) error) error {
for _, network := range sliceType { for _, network := range sliceType {
name, ok := network.(string) name, ok := network.(string)
if !ok { if !ok {
return fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", name, name) return fmt.Errorf("cannot unmarshal '%v' to type %T into a string value", name, name)
} }
n.Networks = append(n.Networks, &Network{ n.Networks = append(n.Networks, &Network{
Name: name, Name: name,
@ -65,7 +65,7 @@ func (n *Networks) UnmarshalYAML(unmarshal func(any) error) error {
for mapKey, mapValue := range mapType { for mapKey, mapValue := range mapType {
name, ok := mapKey.(string) name, ok := mapKey.(string)
if !ok { if !ok {
return fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", name, name) return fmt.Errorf("cannot unmarshal '%v' to type %T into a string value", name, name)
} }
network, err := handleNetwork(name, mapValue) network, err := handleNetwork(name, mapValue)
if err != nil { if err != nil {
@ -76,7 +76,7 @@ func (n *Networks) UnmarshalYAML(unmarshal func(any) error) error {
return nil return nil
} }
return errors.New("Failed to unmarshal Networks") return errors.New("failed to unmarshal Networks")
} }
func handleNetwork(name string, value any) (*Network, error) { func handleNetwork(name string, value any) (*Network, error) {
@ -95,7 +95,7 @@ func handleNetwork(name string, value any) (*Network, error) {
case "aliases": case "aliases":
aliases, ok := mapValue.([]any) aliases, ok := mapValue.([]any)
if !ok { if !ok {
return &Network{}, fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", aliases, aliases) return &Network{}, fmt.Errorf("cannot unmarshal '%v' to type %T into a string value", aliases, aliases)
} }
network.Aliases = []string{} network.Aliases = []string{}
for _, alias := range aliases { for _, alias := range aliases {
@ -112,6 +112,6 @@ func handleNetwork(name string, value any) (*Network, error) {
} }
return network, nil return network, nil
default: default:
return &Network{}, fmt.Errorf("Failed to unmarshal Network: %#v", value) return &Network{}, fmt.Errorf("failed to unmarshal Network: %#v", value)
} }
} }

View file

@ -64,7 +64,7 @@ func (v *Volumes) UnmarshalYAML(unmarshal func(any) error) error {
for _, volume := range sliceType { for _, volume := range sliceType {
name, ok := volume.(string) name, ok := volume.(string)
if !ok { if !ok {
return fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", name, name) return fmt.Errorf("cannot unmarshal '%v' to type %T into a string value", name, name)
} }
elts := strings.SplitN(name, ":", 3) elts := strings.SplitN(name, ":", 3)
var vol *Volume var vol *Volume
@ -93,5 +93,5 @@ func (v *Volumes) UnmarshalYAML(unmarshal func(any) error) error {
return nil return nil
} }
return errors.New("Failed to unmarshal Volumes") return errors.New("failed to unmarshal Volumes")
} }

View file

@ -65,7 +65,7 @@ func GetAgent(c *gin.Context) {
agent, err := store.FromContext(c).AgentFind(agentID) agent, err := store.FromContext(c).AgentFind(agentID)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
c.JSON(http.StatusOK, agent) c.JSON(http.StatusOK, agent)
@ -89,7 +89,7 @@ func GetAgentTasks(c *gin.Context) {
agent, err := store.FromContext(c).AgentFind(agentID) agent, err := store.FromContext(c).AgentFind(agentID)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -132,7 +132,7 @@ func PatchAgent(c *gin.Context) {
agent, err := _store.AgentFind(agentID) agent, err := _store.AgentFind(agentID)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
agent.Name = in.Name agent.Name = in.Name
@ -201,7 +201,7 @@ func DeleteAgent(c *gin.Context) {
agent, err := _store.AgentFind(agentID) agent, err := _store.AgentFind(agentID)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
if err = _store.AgentDelete(agent); err != nil { if err = _store.AgentDelete(agent); err != nil {

View file

@ -62,7 +62,7 @@ func GetBadge(c *gin.Context) {
} }
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -116,7 +116,7 @@ func GetCC(c *gin.Context) {
} }
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }

View file

@ -49,7 +49,7 @@ func GetCron(c *gin.Context) {
cron, err := store.FromContext(c).CronFind(repo, id) cron, err := store.FromContext(c).CronFind(repo, id)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
c.JSON(http.StatusOK, cron) c.JSON(http.StatusOK, cron)
@ -76,7 +76,7 @@ func RunCron(c *gin.Context) {
cron, err := _store.CronFind(repo, id) cron, err := _store.CronFind(repo, id)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -183,7 +183,7 @@ func PatchCron(c *gin.Context) {
cron, err := _store.CronFind(repo, id) cron, err := _store.CronFind(repo, id)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
if in.Branch != "" { if in.Branch != "" {
@ -259,7 +259,7 @@ func DeleteCron(c *gin.Context) {
return return
} }
if err := store.FromContext(c).CronDelete(repo, id); err != nil { if err := store.FromContext(c).CronDelete(repo, id); err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
c.Status(http.StatusNoContent) c.Status(http.StatusNoContent)

View file

@ -62,7 +62,7 @@ func GetGlobalSecret(c *gin.Context) {
name := c.Param("secret") name := c.Param("secret")
secret, err := server.Config.Services.Secrets.GlobalSecretFind(name) secret, err := server.Config.Services.Secrets.GlobalSecretFind(name)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
c.JSON(http.StatusOK, secret.Copy()) c.JSON(http.StatusOK, secret.Copy())
@ -122,7 +122,7 @@ func PatchGlobalSecret(c *gin.Context) {
secret, err := server.Config.Services.Secrets.GlobalSecretFind(name) secret, err := server.Config.Services.Secrets.GlobalSecretFind(name)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
if in.Value != "" { if in.Value != "" {
@ -158,7 +158,7 @@ func PatchGlobalSecret(c *gin.Context) {
func DeleteGlobalSecret(c *gin.Context) { func DeleteGlobalSecret(c *gin.Context) {
name := c.Param("secret") name := c.Param("secret")
if err := server.Config.Services.Secrets.GlobalSecretDelete(name); err != nil { if err := server.Config.Services.Secrets.GlobalSecretDelete(name); err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
c.Status(http.StatusNoContent) c.Status(http.StatusNoContent)

View file

@ -43,7 +43,7 @@ func handlePipelineErr(c *gin.Context, err error) {
} }
} }
func handleDbError(c *gin.Context, err error) { func handleDBError(c *gin.Context, err error) {
if errors.Is(err, types.RecordNotExist) { if errors.Is(err, types.RecordNotExist) {
c.AbortWithStatus(http.StatusNotFound) c.AbortWithStatus(http.StatusNotFound)
return return

View file

@ -144,7 +144,7 @@ func PostHook(c *gin.Context) {
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeRemoteID, tmpRepo.FullName) repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeRemoteID, tmpRepo.FullName)
if err != nil { if err != nil {
log.Error().Err(err).Msgf("failure to get repo %s from store", tmpRepo.FullName) log.Error().Err(err).Msgf("failure to get repo %s from store", tmpRepo.FullName)
handleDbError(c, err) handleDBError(c, err)
return return
} }
if !repo.IsActive { if !repo.IsActive {

View file

@ -208,7 +208,7 @@ func GetLoginToken(c *gin.Context) {
user, err := _store.GetUserLogin(login) user, err := _store.GetUserLogin(login)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }

View file

@ -26,7 +26,7 @@ import (
) )
// 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") var 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

@ -49,7 +49,7 @@ func GetOrg(c *gin.Context) {
org, err := _store.OrgGet(orgID) org, err := _store.OrgGet(orgID)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -122,7 +122,7 @@ func LookupOrg(c *gin.Context) {
org, err := _store.OrgFindByName(orgFullName) org, err := _store.OrgFindByName(orgFullName)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }

View file

@ -47,7 +47,7 @@ func GetOrgSecret(c *gin.Context) {
secret, err := server.Config.Services.Secrets.OrgSecretFind(orgID, name) secret, err := server.Config.Services.Secrets.OrgSecretFind(orgID, name)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
c.JSON(http.StatusOK, secret.Copy()) c.JSON(http.StatusOK, secret.Copy())
@ -152,7 +152,7 @@ func PatchOrgSecret(c *gin.Context) {
secret, err := server.Config.Services.Secrets.OrgSecretFind(orgID, name) secret, err := server.Config.Services.Secrets.OrgSecretFind(orgID, name)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
if in.Value != "" { if in.Value != "" {
@ -195,7 +195,7 @@ func DeleteOrgSecret(c *gin.Context) {
} }
if err := server.Config.Services.Secrets.OrgSecretDelete(orgID, name); err != nil { if err := server.Config.Services.Secrets.OrgSecretDelete(orgID, name); err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
c.Status(http.StatusNoContent) c.Status(http.StatusNoContent)

View file

@ -65,7 +65,7 @@ func DeleteOrg(c *gin.Context) {
err = _store.OrgDelete(orgID) err = _store.OrgDelete(orgID)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }

View file

@ -140,7 +140,7 @@ func GetPipeline(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num) pl, err := _store.GetPipelineNumber(repo, num)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
if pl.Workflows, err = _store.WorkflowGetTree(pl); err != nil { if pl.Workflows, err = _store.WorkflowGetTree(pl); err != nil {
@ -158,7 +158,7 @@ func GetPipelineLast(c *gin.Context) {
pl, err := _store.GetPipelineLast(repo, branch) pl, err := _store.GetPipelineLast(repo, branch)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -194,7 +194,7 @@ func GetStepLogs(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num) pl, err := _store.GetPipelineNumber(repo, num)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -206,7 +206,7 @@ func GetStepLogs(c *gin.Context) {
step, err := _store.StepLoad(stepID) step, err := _store.StepLoad(stepID)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -218,7 +218,7 @@ func GetStepLogs(c *gin.Context) {
logs, err := _store.LogFind(step) logs, err := _store.LogFind(step)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -246,7 +246,7 @@ func GetPipelineConfig(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num) pl, err := _store.GetPipelineNumber(repo, num)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -277,7 +277,7 @@ func CancelPipeline(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num) pl, err := _store.GetPipelineNumber(repo, num)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -308,7 +308,7 @@ func PostApproval(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num) pl, err := _store.GetPipelineNumber(repo, num)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -340,7 +340,7 @@ func PostDecline(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num) pl, err := _store.GetPipelineNumber(repo, num)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -394,13 +394,13 @@ func PostPipeline(c *gin.Context) {
user, err := _store.GetUser(repo.UserID) user, err := _store.GetUser(repo.UserID)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
pl, err := _store.GetPipelineNumber(repo, num) pl, err := _store.GetPipelineNumber(repo, num)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -467,7 +467,7 @@ func DeletePipelineLogs(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num) pl, err := _store.GetPipelineNumber(repo, num)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }

View file

@ -41,7 +41,7 @@ func GetRegistry(c *gin.Context) {
) )
registry, err := server.Config.Services.Registries.RegistryFind(repo, name) registry, err := server.Config.Services.Registries.RegistryFind(repo, name)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
c.JSON(200, registry.Copy()) c.JSON(200, registry.Copy())
@ -110,7 +110,7 @@ func PatchRegistry(c *gin.Context) {
registry, err := server.Config.Services.Registries.RegistryFind(repo, name) registry, err := server.Config.Services.Registries.RegistryFind(repo, name)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
if in.Username != "" { if in.Username != "" {
@ -180,7 +180,7 @@ func DeleteRegistry(c *gin.Context) {
) )
err := server.Config.Services.Registries.RegistryDelete(repo, name) err := server.Config.Services.Registries.RegistryDelete(repo, name)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
c.Status(http.StatusNoContent) c.Status(http.StatusNoContent)

View file

@ -400,7 +400,7 @@ func DeleteRepo(c *gin.Context) {
if remove { if remove {
if err := _store.DeleteRepo(repo); err != nil { if err := _store.DeleteRepo(repo); err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
} }

View file

@ -42,7 +42,7 @@ func GetSecret(c *gin.Context) {
) )
secret, err := server.Config.Services.Secrets.SecretFind(repo, name) secret, err := server.Config.Services.Secrets.SecretFind(repo, name)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
c.JSON(http.StatusOK, secret.Copy()) c.JSON(http.StatusOK, secret.Copy())
@ -110,7 +110,7 @@ func PatchSecret(c *gin.Context) {
secret, err := server.Config.Services.Secrets.SecretFind(repo, name) secret, err := server.Config.Services.Secrets.SecretFind(repo, name)
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
if in.Value != "" { if in.Value != "" {
@ -176,7 +176,7 @@ func DeleteSecret(c *gin.Context) {
name = c.Param("secret") name = c.Param("secret")
) )
if err := server.Config.Services.Secrets.SecretDelete(repo, name); err != nil { if err := server.Config.Services.Secrets.SecretDelete(repo, name); err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
c.Status(http.StatusNoContent) c.Status(http.StatusNoContent)

View file

@ -59,7 +59,7 @@ func GetUsers(c *gin.Context) {
func GetUser(c *gin.Context) { func GetUser(c *gin.Context) {
user, err := store.FromContext(c).GetUserLogin(c.Param("login")) user, err := store.FromContext(c).GetUserLogin(c.Param("login"))
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
c.JSON(http.StatusOK, user) c.JSON(http.StatusOK, user)
@ -89,7 +89,7 @@ func PatchUser(c *gin.Context) {
user, err := _store.GetUserLogin(c.Param("login")) user, err := _store.GetUserLogin(c.Param("login"))
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
@ -159,11 +159,11 @@ func DeleteUser(c *gin.Context) {
user, err := _store.GetUserLogin(c.Param("login")) user, err := _store.GetUserLogin(c.Param("login"))
if err != nil { if err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
if err = _store.DeleteUser(user); err != nil { if err = _store.DeleteUser(user); err != nil {
handleDbError(c, err) handleDBError(c, err)
return return
} }
c.Status(http.StatusNoContent) c.Status(http.StatusNoContent)

View file

@ -125,7 +125,7 @@ func (cf *configFetcher) fetch(c context.Context, timeout time.Duration, config
case <-ctx.Done(): case <-ctx.Done():
return nil, ctx.Err() return nil, ctx.Err()
default: default:
return []*types.FileMeta{}, fmt.Errorf("ConfigFetcher: Fallback did not find config: %w", err) return []*types.FileMeta{}, fmt.Errorf("configFetcher: fallback did not find config: %w", err)
} }
} }

View file

@ -310,8 +310,8 @@ func TestFetch(t *testing.T) {
} }
// if the previous mocks do not match return not found errors // if the previous mocks do not match return not found errors
f.On("File", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("File not found")) f.On("File", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("file not found"))
f.On("Dir", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("Directory not found")) f.On("Dir", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("directory not found"))
configFetcher := forge.NewConfigFetcher( configFetcher := forge.NewConfigFetcher(
f, f,
@ -516,8 +516,8 @@ func TestFetchFromConfigService(t *testing.T) {
} }
// if the previous mocks do not match return not found errors // if the previous mocks do not match return not found errors
f.On("File", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("File not found")) f.On("File", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("file not found"))
f.On("Dir", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("Directory not found")) f.On("Dir", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("directory not found"))
f.On("Netrc", mock.Anything, mock.Anything).Return(&model.Netrc{Machine: "mock", Login: "mock", Password: "mock"}, nil) f.On("Netrc", mock.Anything, mock.Anything).Return(&model.Netrc{Machine: "mock", Login: "mock", Password: "mock"}, nil)

View file

@ -39,7 +39,6 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/server" "go.woodpecker-ci.org/woodpecker/v2/server"
"go.woodpecker-ci.org/woodpecker/v2/server/forge" "go.woodpecker-ci.org/woodpecker/v2/server/forge"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/common" "go.woodpecker-ci.org/woodpecker/v2/server/forge/common"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/types"
forge_types "go.woodpecker-ci.org/woodpecker/v2/server/forge/types" forge_types "go.woodpecker-ci.org/woodpecker/v2/server/forge/types"
"go.woodpecker-ci.org/woodpecker/v2/server/model" "go.woodpecker-ci.org/woodpecker/v2/server/model"
"go.woodpecker-ci.org/woodpecker/v2/server/store" "go.woodpecker-ci.org/woodpecker/v2/server/store"
@ -292,7 +291,7 @@ func (c *Gitea) File(ctx context.Context, u *model.User, r *model.Repo, b *model
cfg, resp, err := client.GetFile(r.Owner, r.Name, b.Commit, f) cfg, resp, err := client.GetFile(r.Owner, r.Name, b.Commit, f)
if err != nil && resp != nil && resp.StatusCode == http.StatusNotFound { if err != nil && resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, errors.Join(err, &types.ErrConfigNotFound{Configs: []string{f}}) return nil, errors.Join(err, &forge_types.ErrConfigNotFound{Configs: []string{f}})
} }
return cfg, err return cfg, err
} }
@ -318,7 +317,7 @@ func (c *Gitea) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.
if m, _ := filepath.Match(f, e.Path); m && e.Type == "blob" { if m, _ := filepath.Match(f, e.Path); m && e.Type == "blob" {
data, err := c.File(ctx, u, r, b, e.Path) data, err := c.File(ctx, u, r, b, e.Path)
if err != nil { if err != nil {
if errors.Is(err, &types.ErrConfigNotFound{}) { if errors.Is(err, &forge_types.ErrConfigNotFound{}) {
return nil, fmt.Errorf("git tree reported existence of file but we got: %s", err.Error()) return nil, fmt.Errorf("git tree reported existence of file but we got: %s", err.Error())
} }
return nil, fmt.Errorf("multi-pipeline cannot get %s: %w", e.Path, err) return nil, fmt.Errorf("multi-pipeline cannot get %s: %w", e.Path, err)
@ -402,10 +401,10 @@ func (c *Gitea) Activate(ctx context.Context, u *model.User, r *model.Repo, link
if err != nil { if err != nil {
if response != nil { if response != nil {
if response.StatusCode == 404 { if response.StatusCode == 404 {
return fmt.Errorf("Could not find repository") return fmt.Errorf("could not find repository")
} }
if response.StatusCode == 200 { if response.StatusCode == 200 {
return fmt.Errorf("Could not find repository, repository was probably renamed") return fmt.Errorf("could not find repository, repository was probably renamed")
} }
} }
return err return err

View file

@ -33,7 +33,6 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/server" "go.woodpecker-ci.org/woodpecker/v2/server"
"go.woodpecker-ci.org/woodpecker/v2/server/forge" "go.woodpecker-ci.org/woodpecker/v2/server/forge"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/common" "go.woodpecker-ci.org/woodpecker/v2/server/forge/common"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/types"
forge_types "go.woodpecker-ci.org/woodpecker/v2/server/forge/types" forge_types "go.woodpecker-ci.org/woodpecker/v2/server/forge/types"
"go.woodpecker-ci.org/woodpecker/v2/server/model" "go.woodpecker-ci.org/woodpecker/v2/server/model"
"go.woodpecker-ci.org/woodpecker/v2/server/store" "go.woodpecker-ci.org/woodpecker/v2/server/store"
@ -132,7 +131,7 @@ func (c *client) Login(ctx context.Context, res http.ResponseWriter, req *http.R
} }
email := matchingEmail(emails, c.API) email := matchingEmail(emails, c.API)
if email == nil { if email == nil {
return nil, fmt.Errorf("No verified Email address for GitHub account") return nil, fmt.Errorf("no verified Email address for GitHub account")
} }
return &model.User{ return &model.User{
@ -230,7 +229,7 @@ func (c *client) File(ctx context.Context, u *model.User, r *model.Repo, b *mode
opts.Ref = b.Commit opts.Ref = b.Commit
content, _, resp, err := client.Repositories.GetContents(ctx, r.Owner, r.Name, f, opts) content, _, resp, err := client.Repositories.GetContents(ctx, r.Owner, r.Name, f, opts)
if resp != nil && resp.StatusCode == http.StatusNotFound { if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, errors.Join(err, &types.ErrConfigNotFound{Configs: []string{f}}) return nil, errors.Join(err, &forge_types.ErrConfigNotFound{Configs: []string{f}})
} }
if err != nil { if err != nil {
return nil, err return nil, err
@ -249,7 +248,7 @@ func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model
opts.Ref = b.Commit opts.Ref = b.Commit
_, data, resp, err := client.Repositories.GetContents(ctx, r.Owner, r.Name, f, opts) _, data, resp, err := client.Repositories.GetContents(ctx, r.Owner, r.Name, f, opts)
if resp != nil && resp.StatusCode == http.StatusNotFound { if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, errors.Join(err, &types.ErrConfigNotFound{Configs: []string{f}}) return nil, errors.Join(err, &forge_types.ErrConfigNotFound{Configs: []string{f}})
} }
if err != nil { if err != nil {
return nil, err return nil, err
@ -262,7 +261,7 @@ func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model
go func(path string) { go func(path string) {
content, err := c.File(ctx, u, r, b, path) content, err := c.File(ctx, u, r, b, path)
if err != nil { if err != nil {
if errors.Is(err, &types.ErrConfigNotFound{}) { if errors.Is(err, &forge_types.ErrConfigNotFound{}) {
err = fmt.Errorf("git tree reported existence of file but we got: %s", err.Error()) err = fmt.Errorf("git tree reported existence of file but we got: %s", err.Error())
} }
errc <- err errc <- err

View file

@ -256,7 +256,7 @@ func getUserAvatar(email string) string {
func extractFromPath(str string) (string, string, error) { func extractFromPath(str string) (string, string, error) {
s := strings.Split(str, "/") s := strings.Split(str, "/")
if len(s) < 2 { if len(s) < 2 {
return "", "", fmt.Errorf("Minimum match not found") return "", "", fmt.Errorf("minimum match not found")
} }
return s[0], s[1], nil return s[0], s[1], nil
} }

View file

@ -34,7 +34,6 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/server" "go.woodpecker-ci.org/woodpecker/v2/server"
"go.woodpecker-ci.org/woodpecker/v2/server/forge" "go.woodpecker-ci.org/woodpecker/v2/server/forge"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/common" "go.woodpecker-ci.org/woodpecker/v2/server/forge/common"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/types"
forge_types "go.woodpecker-ci.org/woodpecker/v2/server/forge/types" forge_types "go.woodpecker-ci.org/woodpecker/v2/server/forge/types"
"go.woodpecker-ci.org/woodpecker/v2/server/model" "go.woodpecker-ci.org/woodpecker/v2/server/model"
"go.woodpecker-ci.org/woodpecker/v2/server/store" "go.woodpecker-ci.org/woodpecker/v2/server/store"
@ -127,7 +126,7 @@ func (g *GitLab) Login(ctx context.Context, res http.ResponseWriter, req *http.R
token, err := config.Exchange(oauth2Ctx, code) token, err := config.Exchange(oauth2Ctx, code)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error exchanging token. %w", err) return nil, fmt.Errorf("error exchanging token: %w", err)
} }
client, err := newClient(g.url, token.AccessToken, g.SkipVerify) client, err := newClient(g.url, token.AccessToken, g.SkipVerify)
@ -345,7 +344,7 @@ func (g *GitLab) File(ctx context.Context, user *model.User, repo *model.Repo, p
} }
file, resp, err := client.RepositoryFiles.GetRawFile(_repo.ID, fileName, &gitlab.GetRawFileOptions{Ref: &pipeline.Commit}, gitlab.WithContext(ctx)) file, resp, err := client.RepositoryFiles.GetRawFile(_repo.ID, fileName, &gitlab.GetRawFileOptions{Ref: &pipeline.Commit}, gitlab.WithContext(ctx))
if resp != nil && resp.StatusCode == http.StatusNotFound { if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, errors.Join(err, &types.ErrConfigNotFound{Configs: []string{fileName}}) return nil, errors.Join(err, &forge_types.ErrConfigNotFound{Configs: []string{fileName}})
} }
return file, err return file, err
} }
@ -383,7 +382,7 @@ func (g *GitLab) Dir(ctx context.Context, user *model.User, repo *model.Repo, pi
} }
data, err := g.File(ctx, user, repo, pipeline, batch[i].Path) data, err := g.File(ctx, user, repo, pipeline, batch[i].Path)
if err != nil { if err != nil {
if errors.Is(err, &types.ErrConfigNotFound{}) { if errors.Is(err, &forge_types.ErrConfigNotFound{}) {
return nil, fmt.Errorf("git tree reported existence of file but we got: %s", err.Error()) return nil, fmt.Errorf("git tree reported existence of file but we got: %s", err.Error())
} }
return nil, err return nil, err

View file

@ -41,7 +41,7 @@ func NewWoodpeckerAuthServer(jwtManager *JWTManager, agentMasterToken string, st
func (s *WoodpeckerAuthServer) Auth(_ context.Context, req *proto.AuthRequest) (*proto.AuthResponse, error) { func (s *WoodpeckerAuthServer) Auth(_ context.Context, req *proto.AuthRequest) (*proto.AuthResponse, error) {
agent, err := s.getAgent(req.AgentId, req.AgentToken) agent, err := s.getAgent(req.AgentId, req.AgentToken)
if err != nil { if err != nil {
return nil, fmt.Errorf("Agent could not auth: %w", err) return nil, fmt.Errorf("agent could not auth: %w", err)
} }
accessToken, err := s.jwtManager.Generate(agent.ID) accessToken, err := s.jwtManager.Generate(agent.ID)

View file

@ -269,7 +269,7 @@ func (s *RPC) Done(c context.Context, id string, state rpc.State) error {
var queueErr error var queueErr error
if workflow.Failing() { if workflow.Failing() {
queueErr = s.queue.Error(c, id, fmt.Errorf("Step finished with exit code %d, %s", state.ExitCode, state.Error)) queueErr = s.queue.Error(c, id, fmt.Errorf("step finished with exit code %d, %s", state.ExitCode, state.Error))
} else { } else {
queueErr = s.queue.Done(c, id, workflow.State) queueErr = s.queue.Done(c, id, workflow.State)
} }
@ -388,6 +388,7 @@ func (s *RPC) ReportHealth(ctx context.Context, status string) error {
} }
if status != "I am alive!" { if status != "I am alive!" {
//nolint:stylecheck
return errors.New("Are you alive?") return errors.New("Are you alive?")
} }

View file

@ -21,9 +21,9 @@ import (
) )
var ( var (
errRegistryAddressInvalid = errors.New("Invalid Registry Address") errRegistryAddressInvalid = errors.New("invalid registry address")
errRegistryUsernameInvalid = errors.New("Invalid Registry Username") errRegistryUsernameInvalid = errors.New("invalid registry username")
errRegistryPasswordInvalid = errors.New("Invalid Registry Password") errRegistryPasswordInvalid = errors.New("invalid registry password")
) )
// RegistryService defines a service for managing registries. // RegistryService defines a service for managing registries.

View file

@ -23,10 +23,10 @@ import (
) )
var ( var (
ErrSecretNameInvalid = errors.New("Invalid Secret Name") ErrSecretNameInvalid = errors.New("invalid secret name")
ErrSecretImageInvalid = errors.New("Invalid Secret Image") ErrSecretImageInvalid = errors.New("invalid secret image")
ErrSecretValueInvalid = errors.New("Invalid Secret Value") ErrSecretValueInvalid = errors.New("invalid secret value")
ErrSecretEventInvalid = errors.New("Invalid Secret Event") ErrSecretEventInvalid = errors.New("invalid secret event")
) )
// SecretService defines a service for managing secrets. // SecretService defines a service for managing secrets.

View file

@ -25,7 +25,6 @@ import (
"go.uber.org/multierr" "go.uber.org/multierr"
backend_types "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types" backend_types "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/errors"
pipeline_errors "go.woodpecker-ci.org/woodpecker/v2/pipeline/errors" pipeline_errors "go.woodpecker-ci.org/woodpecker/v2/pipeline/errors"
yaml_types "go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml/types" yaml_types "go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml/types"
forge_types "go.woodpecker-ci.org/woodpecker/v2/server/forge/types" forge_types "go.woodpecker-ci.org/woodpecker/v2/server/forge/types"
@ -137,7 +136,7 @@ func (b *StepBuilder) genItemForWorkflow(workflow *model.Workflow, axis matrix.A
// parse yaml pipeline // parse yaml pipeline
parsed, err := yaml.ParseString(substituted) parsed, err := yaml.ParseString(substituted)
if err != nil { if err != nil {
return nil, &errors.PipelineError{Message: err.Error(), Type: errors.PipelineErrorTypeCompiler} return nil, &pipeline_errors.PipelineError{Message: err.Error(), Type: pipeline_errors.PipelineErrorTypeCompiler}
} }
// lint pipeline // lint pipeline

View file

@ -66,7 +66,7 @@ func (cp *http) FetchConfig(ctx context.Context, repo *model.Repo, pipeline *mod
status, err := utils.Send(ctx, "POST", cp.endpoint, cp.privateKey, body, response) status, err := utils.Send(ctx, "POST", cp.endpoint, cp.privateKey, body, response)
if err != nil && status != 204 { if err != nil && status != 204 {
return nil, false, fmt.Errorf("Failed to fetch config via http (%d) %w", status, err) return nil, false, fmt.Errorf("failed to fetch config via http (%d) %w", status, err)
} }
var newFileMeta []*forge_types.FileMeta var newFileMeta []*forge_types.FileMeta

View file

@ -111,11 +111,11 @@ func decodeAuth(authStr string) (string, string, error) {
return "", "", err return "", "", err
} }
if n > decLen { if n > decLen {
return "", "", fmt.Errorf("Something went wrong decoding auth config") return "", "", fmt.Errorf("something went wrong decoding auth config")
} }
arr := strings.SplitN(string(decoded), ":", 2) arr := strings.SplitN(string(decoded), ":", 2)
if len(arr) != 2 { if len(arr) != 2 {
return "", "", fmt.Errorf("Invalid auth configuration file") return "", "", fmt.Errorf("invalid auth configuration file")
} }
password := strings.Trim(arr[1], "\x00") password := strings.Trim(arr[1], "\x00")
return arr[0], password, nil return arr[0], password, nil

View file

@ -71,7 +71,7 @@ func Send(ctx context.Context, method, path string, privateKey crypto.PrivateKey
return resp.StatusCode, err return resp.StatusCode, err
} }
return resp.StatusCode, fmt.Errorf("Response: %s", string(body)) return resp.StatusCode, fmt.Errorf("response: %s", string(body))
} }
// if no other errors parse and return the json response. // if no other errors parse and return the json response.

View file

@ -20,7 +20,7 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/server/model" "go.woodpecker-ci.org/woodpecker/v2/server/model"
) )
var ErrNoTokenProvided = errors.New("Please provide a token") var ErrNoTokenProvided = errors.New("please provide a token")
func (s storage) AgentList(p *model.ListOptions) ([]*model.Agent, error) { func (s storage) AgentList(p *model.ListOptions) ([]*model.Agent, error) {
var agents []*model.Agent var agents []*model.Agent

View file

@ -113,7 +113,7 @@ func Migrate(e *xorm.Engine, allowLong bool) error {
func syncAll(sess *xorm.Engine) error { func syncAll(sess *xorm.Engine) error {
for _, bean := range allBeans { for _, bean := range allBeans {
if err := sess.Sync(bean); err != nil { if err := sess.Sync(bean); err != nil {
return fmt.Errorf("Sync error '%s': %w", reflect.TypeOf(bean), err) return fmt.Errorf("sync error '%s': %w", reflect.TypeOf(bean), err)
} }
} }
return nil return nil