From 95f8671b139150f9958ad34a0306440dc6333df5 Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 20 Apr 2022 19:41:42 +0200 Subject: [PATCH 1/3] Mark TemplateLoading error as "UnprocessableEntity" (#19445) - Backport #19445 - Don't return Internal Server error if the user provide incorrect label template, instead return UnprocessableEntity. - Resolves #19399 --- routers/api/v1/repo/repo.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index af8b06ed2a4a4..39eb314025713 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -21,6 +21,7 @@ import ( "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" + repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" @@ -160,7 +161,7 @@ func Search(ctx *context.APIContext) { opts.Collaborate = util.OptionalBoolFalse } - var mode = ctx.FormString("mode") + mode := ctx.FormString("mode") switch mode { case "source": opts.Fork = util.OptionalBoolFalse @@ -186,9 +187,9 @@ func Search(ctx *context.APIContext) { opts.IsPrivate = util.OptionalBoolOf(ctx.FormBool("is_private")) } - var sortMode = ctx.FormString("sort") + sortMode := ctx.FormString("sort") if len(sortMode) > 0 { - var sortOrder = ctx.FormString("order") + sortOrder := ctx.FormString("order") if len(sortOrder) == 0 { sortOrder = "asc" } @@ -264,7 +265,8 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre if repo_model.IsErrRepoAlreadyExist(err) { ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.") } else if db.IsErrNameReserved(err) || - db.IsErrNamePatternNotAllowed(err) { + db.IsErrNamePatternNotAllowed(err) || + repo_module.IsErrIssueLabelTemplateLoad(err) { ctx.Error(http.StatusUnprocessableEntity, "", err) } else { ctx.Error(http.StatusInternalServerError, "CreateRepository", err) From 8a79da24b80e53b815ea89a014cc97be8c4817f7 Mon Sep 17 00:00:00 2001 From: Gusted Date: Thu, 21 Apr 2022 11:35:15 +0200 Subject: [PATCH 2/3] Fix package import --- routers/api/v1/repo/repo.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 39eb314025713..851505fe4a964 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -21,7 +21,6 @@ import ( "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" @@ -266,7 +265,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.") } else if db.IsErrNameReserved(err) || db.IsErrNamePatternNotAllowed(err) || - repo_module.IsErrIssueLabelTemplateLoad(err) { + models.IsErrIssueLabelTemplateLoad(err) { ctx.Error(http.StatusUnprocessableEntity, "", err) } else { ctx.Error(http.StatusInternalServerError, "CreateRepository", err) From faa9831e8d95f09d14747973d21eac8c565c0bc0 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 22 Apr 2022 20:20:34 +0200 Subject: [PATCH 3/3] dep: upgrade: github.com/gogs/chardet --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 92e4b20ca074b..e34a3e740c07c 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( github.com/go-swagger/go-swagger v0.27.0 github.com/go-testfixtures/testfixtures/v3 v3.6.1 github.com/gobwas/glob v0.2.3 - github.com/gogs/chardet v0.0.0-20191104214054-4b6791f73a28 + github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14 github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85 github.com/golang-jwt/jwt/v4 v4.3.0 diff --git a/go.sum b/go.sum index 2f6f544b6784a..f6aeda9638557 100644 --- a/go.sum +++ b/go.sum @@ -649,8 +649,8 @@ github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/gogs/chardet v0.0.0-20191104214054-4b6791f73a28 h1:gBeyun7mySAKWg7Fb0GOcv0upX9bdaZScs8QcRo8mEY= -github.com/gogs/chardet v0.0.0-20191104214054-4b6791f73a28/go.mod h1:Pcatq5tYkCW2Q6yrR2VRHlbHpZ/R4/7qyL1TCF7vl14= +github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f h1:3BSP1Tbs2djlpprl7wCLuiqMaUh5SJkkzI2gDs+FgLs= +github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f/go.mod h1:Pcatq5tYkCW2Q6yrR2VRHlbHpZ/R4/7qyL1TCF7vl14= github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14 h1:yXtpJr/LV6PFu4nTLgfjQdcMdzjbqqXMEnHfq0Or6p8= github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14/go.mod h1:jPoNZLWDAqA5N3G5amEoiNbhVrmM+ZQEcnQvNQ2KaZk= github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85 h1:UjoPNDAQ5JPCjlxoJd6K8ALZqSDDhk2ymieAZOVaDg0=