Skip to content

Commit 40aca73

Browse files
authored
Fix migration context data (#14910)
* Unified context data. * Changed method name.
1 parent 9b261f5 commit 40aca73

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

routers/repo/migrate.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ func Migrate(ctx *context.Context) {
3232
return
3333
}
3434

35-
ctx.Data["Services"] = append([]structs.GitServiceType{structs.PlainGitService}, structs.SupportedFullGitService...)
36-
serviceType := ctx.QueryInt("service_type")
35+
serviceType := structs.GitServiceType(ctx.QueryInt("service_type"))
36+
37+
setMigrationContextData(ctx, serviceType)
38+
3739
if serviceType == 0 {
3840
ctx.Data["Org"] = ctx.Query("org")
3941
ctx.Data["Mirror"] = ctx.Query("mirror")
@@ -42,28 +44,22 @@ func Migrate(ctx *context.Context) {
4244
return
4345
}
4446

45-
ctx.Data["Title"] = ctx.Tr("new_migrate")
4647
ctx.Data["private"] = getRepoPrivate(ctx)
47-
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
48-
ctx.Data["DisableMirrors"] = setting.Repository.DisableMirrors
4948
ctx.Data["mirror"] = ctx.Query("mirror") == "1"
5049
ctx.Data["wiki"] = ctx.Query("wiki") == "1"
5150
ctx.Data["milestones"] = ctx.Query("milestones") == "1"
5251
ctx.Data["labels"] = ctx.Query("labels") == "1"
5352
ctx.Data["issues"] = ctx.Query("issues") == "1"
5453
ctx.Data["pull_requests"] = ctx.Query("pull_requests") == "1"
5554
ctx.Data["releases"] = ctx.Query("releases") == "1"
56-
ctx.Data["LFSActive"] = setting.LFS.StartServer
57-
// Plain git should be first
58-
ctx.Data["service"] = structs.GitServiceType(serviceType)
5955

6056
ctxUser := checkContextUser(ctx, ctx.QueryInt64("org"))
6157
if ctx.Written() {
6258
return
6359
}
6460
ctx.Data["ContextUser"] = ctxUser
6561

66-
ctx.HTML(200, base.TplName("repo/migrate/"+structs.GitServiceType(serviceType).Name()))
62+
ctx.HTML(200, base.TplName("repo/migrate/"+serviceType.Name()))
6763
}
6864

6965
func handleMigrateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form *auth.MigrateRepoForm) {
@@ -125,19 +121,18 @@ func MigratePost(ctx *context.Context) {
125121
return
126122
}
127123

128-
ctx.Data["Title"] = ctx.Tr("new_migrate")
129-
// Plain git should be first
130-
ctx.Data["service"] = structs.GitServiceType(form.Service)
131-
ctx.Data["Services"] = append([]structs.GitServiceType{structs.PlainGitService}, structs.SupportedFullGitService...)
124+
serviceType := structs.GitServiceType(form.Service)
132125

133-
tpl := base.TplName("repo/migrate/" + structs.GitServiceType(form.Service).Name())
126+
setMigrationContextData(ctx, serviceType)
134127

135128
ctxUser := checkContextUser(ctx, form.UID)
136129
if ctx.Written() {
137130
return
138131
}
139132
ctx.Data["ContextUser"] = ctxUser
140133

134+
tpl := base.TplName("repo/migrate/" + serviceType.Name())
135+
141136
if ctx.HasError() {
142137
ctx.HTML(200, tpl)
143138
return
@@ -166,7 +161,7 @@ func MigratePost(ctx *context.Context) {
166161

167162
var opts = migrations.MigrateOptions{
168163
OriginalURL: form.CloneAddr,
169-
GitServiceType: structs.GitServiceType(form.Service),
164+
GitServiceType: serviceType,
170165
CloneAddr: remoteAddr,
171166
RepoName: form.RepoName,
172167
Description: form.Description,
@@ -206,3 +201,15 @@ func MigratePost(ctx *context.Context) {
206201

207202
handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, form)
208203
}
204+
205+
func setMigrationContextData(ctx *context.Context, serviceType structs.GitServiceType) {
206+
ctx.Data["Title"] = ctx.Tr("new_migrate")
207+
208+
ctx.Data["LFSActive"] = setting.LFS.StartServer
209+
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
210+
ctx.Data["DisableMirrors"] = setting.Repository.DisableMirrors
211+
212+
// Plain git should be first
213+
ctx.Data["Services"] = append([]structs.GitServiceType{structs.PlainGitService}, structs.SupportedFullGitService...)
214+
ctx.Data["service"] = serviceType
215+
}

0 commit comments

Comments
 (0)