diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-05-11 16:25:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-11 08:25:46 +0000 |
commit | f6e029e6c7849d4361abf7f1d749b5d528364ac4 (patch) | |
tree | af285dd000dc48e4e94e717cf61a8b2437e99beb /routers | |
parent | 58dfaf3a75a097088376a9c221784b3675ac9c48 (diff) | |
download | gitea-f6e029e6c7849d4361abf7f1d749b5d528364ac4.tar.gz gitea-f6e029e6c7849d4361abf7f1d749b5d528364ac4.zip |
Make repo migration cancelable and fix various bugs (#24605)
Replace #12917
Close #24601
Close #12845
![image](https://github.com/go-gitea/gitea/assets/2114189/39378118-064d-40fb-8396-4579ebf33917)
![image](https://github.com/go-gitea/gitea/assets/2114189/faf37418-191c-46a6-90a8-353141e00e2d)
![image](https://github.com/go-gitea/gitea/assets/2114189/fdc8ee4d-125f-4737-9990-89bcdf9eb388)
![image](https://github.com/go-gitea/gitea/assets/2114189/9a3bd2c2-fe20-4011-81f0-990ed869d139)
---------
Co-authored-by: Yarden Shoham <git@yardenshoham.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/repo/migrate.go | 18 | ||||
-rw-r--r-- | routers/web/web.go | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/routers/web/repo/migrate.go b/routers/web/repo/migrate.go index bbc349a0a5..b918650d1d 100644 --- a/routers/web/repo/migrate.go +++ b/routers/web/repo/migrate.go @@ -10,6 +10,7 @@ import ( "strings" "code.gitea.io/gitea/models" + admin_model "code.gitea.io/gitea/models/admin" "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" @@ -257,3 +258,20 @@ func setMigrationContextData(ctx *context.Context, serviceType structs.GitServic ctx.Data["Services"] = append([]structs.GitServiceType{structs.PlainGitService}, structs.SupportedFullGitService...) ctx.Data["service"] = serviceType } + +func MigrateCancelPost(ctx *context.Context) { + migratingTask, err := admin_model.GetMigratingTask(ctx.Repo.Repository.ID) + if err != nil { + log.Error("GetMigratingTask: %v", err) + ctx.Redirect(ctx.Repo.Repository.Link()) + return + } + if migratingTask.Status == structs.TaskStatusRunning { + taskUpdate := &admin_model.Task{ID: migratingTask.ID, Status: structs.TaskStatusFailed, Message: "canceled"} + if err = taskUpdate.UpdateCols("status", "message"); err != nil { + ctx.ServerError("task.UpdateCols", err) + return + } + } + ctx.Redirect(ctx.Repo.Repository.Link()) +} diff --git a/routers/web/web.go b/routers/web/web.go index d0deb845fc..8784b7c5f7 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -939,6 +939,7 @@ func registerRoutes(m *web.Route) { addSettingsRunnersRoutes() addSettingsSecretsRoutes() }, actions.MustEnableActions) + m.Post("/migrate/cancel", repo.MigrateCancelPost) // this handler must be under "settings", otherwise this incomplete repo can't be accessed }, ctxDataSet("PageIsRepoSettings", true, "LFSStartServer", setting.LFS.StartServer)) }, reqSignIn, context.RepoAssignment, context.UnitTypes(), reqRepoAdmin, context.RepoRef()) |