From c8adb2478b45f865861bdbe8b56adbc7ca4a0399 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Wed, 23 Sep 2020 19:35:37 +0100 Subject: [PATCH 1/2] Fix handling of migration errors The migration type selection screen PR did not correctly handle errors and any user input error on the migration page would simply redirect back to the selection page. This meant that the error would simply be lost and the user would be none the wiser as to what happened. Signed-off-by: Andrew Thornton --- modules/auth/repo_form.go | 11 ++++++----- routers/repo/migrate.go | 16 +++++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index f1130f372b794..e8809136c9d3c 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/routers/utils" "gitea.com/macaron/binding" @@ -57,11 +58,11 @@ func (f *CreateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) bin // this is used to interact with web ui type MigrateRepoForm struct { // required: true - CloneAddr string `json:"clone_addr" binding:"Required"` - Service int `json:"service"` - AuthUsername string `json:"auth_username"` - AuthPassword string `json:"auth_password"` - AuthToken string `json:"auth_token"` + CloneAddr string `json:"clone_addr" binding:"Required"` + Service structs.GitServiceType `json:"service"` + AuthUsername string `json:"auth_username"` + AuthPassword string `json:"auth_password"` + AuthToken string `json:"auth_token"` // required: true UID int64 `json:"uid" binding:"Required"` // required: true diff --git a/routers/repo/migrate.go b/routers/repo/migrate.go index 34060aabde5ab..19dbfbab405ed 100644 --- a/routers/repo/migrate.go +++ b/routers/repo/migrate.go @@ -94,9 +94,11 @@ func handleMigrateError(ctx *context.Context, owner *models.User, err error, nam func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) { ctx.Data["Title"] = ctx.Tr("new_migrate") // Plain git should be first - ctx.Data["service"] = form.Service + ctx.Data["service"] = structs.GitServiceType(form.Service) ctx.Data["Services"] = append([]structs.GitServiceType{structs.PlainGitService}, structs.SupportedFullGitService...) + tpl := base.TplName("repo/migrate/" + structs.GitServiceType(form.Service).Name()) + ctxUser := checkContextUser(ctx, form.UID) if ctx.Written() { return @@ -104,7 +106,7 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) { ctx.Data["ContextUser"] = ctxUser if ctx.HasError() { - ctx.HTML(200, tplMigrate) + ctx.HTML(200, tpl) return } @@ -115,11 +117,11 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) { addrErr := err.(models.ErrInvalidCloneAddr) switch { case addrErr.IsURLError: - ctx.RenderWithErr(ctx.Tr("form.url_error"), tplMigrate, &form) + ctx.RenderWithErr(ctx.Tr("form.url_error"), tpl, &form) case addrErr.IsPermissionDenied: - ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), tplMigrate, &form) + ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), tpl, &form) case addrErr.IsInvalidPath: - ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), tplMigrate, &form) + ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), tpl, &form) default: ctx.ServerError("Unknown error", err) } @@ -159,7 +161,7 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) { err = models.CheckCreateRepository(ctx.User, ctxUser, opts.RepoName) if err != nil { - handleMigrateError(ctx, ctxUser, err, "MigratePost", tplMigrate, &form) + handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, &form) return } @@ -169,5 +171,5 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) { return } - handleMigrateError(ctx, ctxUser, err, "MigratePost", tplMigrate, &form) + handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, &form) } From 4817655b74a6a5bd0c77818623f5c3c5484fc2c0 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Wed, 23 Sep 2020 15:49:18 -0400 Subject: [PATCH 2/2] make gen-swagger --- templates/swagger/v1_json.tmpl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 6792f7444b062..6c0d8c1b329f2 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -13231,6 +13231,12 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "GitServiceType": { + "description": "GitServiceType represents a git service", + "type": "integer", + "format": "int64", + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "GitTreeResponse": { "description": "GitTreeResponse returns a git tree", "type": "object", @@ -13658,9 +13664,7 @@ "x-go-name": "RepoName" }, "service": { - "type": "integer", - "format": "int64", - "x-go-name": "Service" + "$ref": "#/definitions/GitServiceType" }, "uid": { "type": "integer",