From 382936a668c48b3c83fe80cdf138f76fb74a5f8f Mon Sep 17 00:00:00 2001 From: John Olheiser <42128690+jolheiser@users.noreply.github.com> Date: Wed, 11 Dec 2019 18:20:11 -0600 Subject: [PATCH] Add SyncTags to uploader interface (#9326) * Add sync tags to interface Signed-off-by: jolheiser * Fix revive Signed-off-by: jolheiser --- modules/migrations/base/uploader.go | 3 ++- modules/migrations/gitea.go | 15 ++++++--------- modules/migrations/migrate.go | 15 ++++++++------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/modules/migrations/base/uploader.go b/modules/migrations/base/uploader.go index 7d35d136a..257c7a290 100644 --- a/modules/migrations/base/uploader.go +++ b/modules/migrations/base/uploader.go @@ -11,7 +11,8 @@ type Uploader interface { CreateRepo(repo *Repository, opts MigrateOptions) error CreateTopics(topic ...string) error CreateMilestones(milestones ...*Milestone) error - CreateReleases(syncTags bool, releases ...*Release) error + CreateReleases(releases ...*Release) error + SyncTags() error CreateLabels(labels ...*Label) error CreateIssues(issues ...*Issue) error CreateComments(comments ...*Comment) error diff --git a/modules/migrations/gitea.go b/modules/migrations/gitea.go index 617561194..18f4da758 100644 --- a/modules/migrations/gitea.go +++ b/modules/migrations/gitea.go @@ -201,7 +201,7 @@ func (g *GiteaLocalUploader) CreateLabels(labels ...*base.Label) error { } // CreateReleases creates releases -func (g *GiteaLocalUploader) CreateReleases(syncTags bool, releases ...*base.Release) error { +func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error { var rels = make([]*models.Release, 0, len(releases)) for _, release := range releases { var rel = models.Release{ @@ -288,16 +288,13 @@ func (g *GiteaLocalUploader) CreateReleases(syncTags bool, releases ...*base.Rel rels = append(rels, &rel) } - if err := models.InsertReleases(rels...); err != nil { - return err - } - if syncTags { - // sync tags to releases in database - return models.SyncReleasesWithTags(g.repo, g.gitRepo) - } + return models.InsertReleases(rels...) +} - return nil +// SyncTags syncs releases with tags in the database +func (g *GiteaLocalUploader) SyncTags() error { + return models.SyncReleasesWithTags(g.repo, g.gitRepo) } // CreateIssues creates issues diff --git a/modules/migrations/migrate.go b/modules/migrations/migrate.go index 124ef4413..957d4c85d 100644 --- a/modules/migrations/migrate.go +++ b/modules/migrations/migrate.go @@ -161,20 +161,21 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts } relBatchSize := uploader.MaxBatchInsertSize("release") - syncTags := false for len(releases) > 0 { - if len(releases) <= relBatchSize { - if len(releases) < relBatchSize { - relBatchSize = len(releases) - } - syncTags = true + if len(releases) < relBatchSize { + relBatchSize = len(releases) } - if err := uploader.CreateReleases(syncTags, releases[:relBatchSize]...); err != nil { + if err := uploader.CreateReleases(releases[:relBatchSize]...); err != nil { return err } releases = releases[relBatchSize:] } + + // Once all releases (if any) are inserted, sync any remaining non-release tags + if err := uploader.SyncTags(); err != nil { + return err + } } var commentBatchSize = uploader.MaxBatchInsertSize("comment")