Skip to content

Commit 3f522cd

Browse files
Fix handling of migration errors (#12928)
* 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 <[email protected]> * make gen-swagger Co-authored-by: techknowlogick <[email protected]>
1 parent f215e01 commit 3f522cd

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

modules/auth/repo_form.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"code.gitea.io/gitea/models"
1313
"code.gitea.io/gitea/modules/setting"
14+
"code.gitea.io/gitea/modules/structs"
1415
"code.gitea.io/gitea/routers/utils"
1516

1617
"gitea.com/macaron/binding"
@@ -57,11 +58,11 @@ func (f *CreateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) bin
5758
// this is used to interact with web ui
5859
type MigrateRepoForm struct {
5960
// required: true
60-
CloneAddr string `json:"clone_addr" binding:"Required"`
61-
Service int `json:"service"`
62-
AuthUsername string `json:"auth_username"`
63-
AuthPassword string `json:"auth_password"`
64-
AuthToken string `json:"auth_token"`
61+
CloneAddr string `json:"clone_addr" binding:"Required"`
62+
Service structs.GitServiceType `json:"service"`
63+
AuthUsername string `json:"auth_username"`
64+
AuthPassword string `json:"auth_password"`
65+
AuthToken string `json:"auth_token"`
6566
// required: true
6667
UID int64 `json:"uid" binding:"Required"`
6768
// required: true

routers/repo/migrate.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,19 @@ func handleMigrateError(ctx *context.Context, owner *models.User, err error, nam
9494
func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
9595
ctx.Data["Title"] = ctx.Tr("new_migrate")
9696
// Plain git should be first
97-
ctx.Data["service"] = form.Service
97+
ctx.Data["service"] = structs.GitServiceType(form.Service)
9898
ctx.Data["Services"] = append([]structs.GitServiceType{structs.PlainGitService}, structs.SupportedFullGitService...)
9999

100+
tpl := base.TplName("repo/migrate/" + structs.GitServiceType(form.Service).Name())
101+
100102
ctxUser := checkContextUser(ctx, form.UID)
101103
if ctx.Written() {
102104
return
103105
}
104106
ctx.Data["ContextUser"] = ctxUser
105107

106108
if ctx.HasError() {
107-
ctx.HTML(200, tplMigrate)
109+
ctx.HTML(200, tpl)
108110
return
109111
}
110112

@@ -115,11 +117,11 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
115117
addrErr := err.(models.ErrInvalidCloneAddr)
116118
switch {
117119
case addrErr.IsURLError:
118-
ctx.RenderWithErr(ctx.Tr("form.url_error"), tplMigrate, &form)
120+
ctx.RenderWithErr(ctx.Tr("form.url_error"), tpl, &form)
119121
case addrErr.IsPermissionDenied:
120-
ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), tplMigrate, &form)
122+
ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), tpl, &form)
121123
case addrErr.IsInvalidPath:
122-
ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), tplMigrate, &form)
124+
ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), tpl, &form)
123125
default:
124126
ctx.ServerError("Unknown error", err)
125127
}
@@ -159,7 +161,7 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
159161

160162
err = models.CheckCreateRepository(ctx.User, ctxUser, opts.RepoName)
161163
if err != nil {
162-
handleMigrateError(ctx, ctxUser, err, "MigratePost", tplMigrate, &form)
164+
handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, &form)
163165
return
164166
}
165167

@@ -169,5 +171,5 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
169171
return
170172
}
171173

172-
handleMigrateError(ctx, ctxUser, err, "MigratePost", tplMigrate, &form)
174+
handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, &form)
173175
}

templates/swagger/v1_json.tmpl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13231,6 +13231,12 @@
1323113231
},
1323213232
"x-go-package": "code.gitea.io/gitea/modules/structs"
1323313233
},
13234+
"GitServiceType": {
13235+
"description": "GitServiceType represents a git service",
13236+
"type": "integer",
13237+
"format": "int64",
13238+
"x-go-package": "code.gitea.io/gitea/modules/structs"
13239+
},
1323413240
"GitTreeResponse": {
1323513241
"description": "GitTreeResponse returns a git tree",
1323613242
"type": "object",
@@ -13658,9 +13664,7 @@
1365813664
"x-go-name": "RepoName"
1365913665
},
1366013666
"service": {
13661-
"type": "integer",
13662-
"format": "int64",
13663-
"x-go-name": "Service"
13667+
"$ref": "#/definitions/GitServiceType"
1366413668
},
1366513669
"uid": {
1366613670
"type": "integer",

0 commit comments

Comments
 (0)