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
58 changed files with 126 additions and 129 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -26,7 +26,7 @@ import (
)
// 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
func PromHandler() gin.HandlerFunc {

View File

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

View File

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

View File

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

View File

@@ -140,7 +140,7 @@ func GetPipeline(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
if pl.Workflows, err = _store.WorkflowGetTree(pl); err != nil {
@@ -158,7 +158,7 @@ func GetPipelineLast(c *gin.Context) {
pl, err := _store.GetPipelineLast(repo, branch)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
@@ -194,7 +194,7 @@ func GetStepLogs(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
@@ -206,19 +206,19 @@ func GetStepLogs(c *gin.Context) {
step, err := _store.StepLoad(stepID)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
if step.PipelineID != pl.ID {
// make sure we can not read arbitrary logs by id
// make sure we cannot read arbitrary logs by id
_ = c.AbortWithError(http.StatusBadRequest, fmt.Errorf("step with id %d is not part of repo %s", stepID, repo.FullName))
return
}
logs, err := _store.LogFind(step)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
@@ -246,7 +246,7 @@ func GetPipelineConfig(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
@@ -277,7 +277,7 @@ func CancelPipeline(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
@@ -308,7 +308,7 @@ func PostApproval(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
@@ -340,7 +340,7 @@ func PostDecline(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
@@ -394,13 +394,13 @@ func PostPipeline(c *gin.Context) {
user, err := _store.GetUser(repo.UserID)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
pl, err := _store.GetPipelineNumber(repo, num)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
@@ -467,7 +467,7 @@ func DeletePipelineLogs(c *gin.Context) {
pl, err := _store.GetPipelineNumber(repo, num)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}

View File

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

View File

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

View File

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

View File

@@ -179,7 +179,7 @@ func LogStreamSSE(c *gin.Context) {
}
if step.PipelineID != pl.ID {
// make sure we can not read arbitrary logs by id
// make sure we cannot read arbitrary logs by id
err = fmt.Errorf("step with id %d is not part of repo %s", stepID, repo.FullName)
log.Debug().Err(err).Msg("event error")
logWriteStringErr(io.WriteString(rw, "event: error\ndata: "+err.Error()+"\n\n"))

View File

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