From e79dae29cc2fcabc639ff27f28a9adf1fa07b28c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 22 Feb 2021 11:57:41 +0800 Subject: [PATCH] Fix repo-restore bug with poster not replaced (#14759) * Fix restore bug * Fix restore bug Co-authored-by: Lauris BH Co-authored-by: John Olheiser Co-authored-by: 6543 <6543@obermui.de> --- modules/migrations/dump.go | 27 ++++++++++++++++++--------- modules/migrations/restore.go | 12 ++++++++++-- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/modules/migrations/dump.go b/modules/migrations/dump.go index 3c3b9a175..297095883 100644 --- a/modules/migrations/dump.go +++ b/modules/migrations/dump.go @@ -12,6 +12,7 @@ import ( "net/url" "os" "path/filepath" + "strconv" "time" "code.gitea.io/gitea/models" @@ -19,6 +20,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/migrations/base" "code.gitea.io/gitea/modules/repository" + "code.gitea.io/gitea/modules/structs" "gopkg.in/yaml.v2" ) @@ -572,20 +574,27 @@ func RestoreRepository(ctx context.Context, baseDir string, ownerName, repoName if err != nil { return err } + opts, err := downloader.getRepoOptions() + if err != nil { + return err + } + tp, _ := strconv.Atoi(opts["service_type"]) + if err = migrateRepository(downloader, uploader, base.MigrateOptions{ - Wiki: true, - Issues: true, - Milestones: true, - Labels: true, - Releases: true, - Comments: true, - PullRequests: true, - ReleaseAssets: true, + Wiki: true, + Issues: true, + Milestones: true, + Labels: true, + Releases: true, + Comments: true, + PullRequests: true, + ReleaseAssets: true, + GitServiceType: structs.GitServiceType(tp), }); err != nil { if err1 := uploader.Rollback(); err1 != nil { log.Error("rollback failed: %v", err1) } return err } - return nil + return updateMigrationPosterIDByGitService(ctx, structs.GitServiceType(tp)) } diff --git a/modules/migrations/restore.go b/modules/migrations/restore.go index e1ab408e4..4e63df142 100644 --- a/modules/migrations/restore.go +++ b/modules/migrations/restore.go @@ -53,8 +53,7 @@ func (r *RepositoryRestorer) SetContext(ctx context.Context) { r.ctx = ctx } -// GetRepoInfo returns a repository information -func (r *RepositoryRestorer) GetRepoInfo() (*base.Repository, error) { +func (r *RepositoryRestorer) getRepoOptions() (map[string]string, error) { p := filepath.Join(r.baseDir, "repo.yml") bs, err := ioutil.ReadFile(p) if err != nil { @@ -66,6 +65,15 @@ func (r *RepositoryRestorer) GetRepoInfo() (*base.Repository, error) { if err != nil { return nil, err } + return opts, nil +} + +// GetRepoInfo returns a repository information +func (r *RepositoryRestorer) GetRepoInfo() (*base.Repository, error) { + opts, err := r.getRepoOptions() + if err != nil { + return nil, err + } isPrivate, _ := strconv.ParseBool(opts["is_private"])