Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of migration errors #12928

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions modules/auth/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions routers/repo/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,19 @@ 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
}
ctx.Data["ContextUser"] = ctxUser

if ctx.HasError() {
ctx.HTML(200, tplMigrate)
ctx.HTML(200, tpl)
return
}

Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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)
}
10 changes: 7 additions & 3 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -13658,9 +13664,7 @@
"x-go-name": "RepoName"
},
"service": {
"type": "integer",
"format": "int64",
"x-go-name": "Service"
"$ref": "#/definitions/GitServiceType"
},
"uid": {
"type": "integer",
Expand Down