summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorAntoine GIRARD <sapk@users.noreply.github.com>2019-08-14 08:16:12 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2019-08-14 14:16:12 +0800
commit46d6b92ad04df87560ee12dfee58a5e8222e52ff (patch)
tree55d7a5ebf3292b79af4eca564f4bdc3f353f58e8 /modules
parent99a004c343ff0770af4e209ca4634b83f153a23c (diff)
downloadgitea-46d6b92ad04df87560ee12dfee58a5e8222e52ff.tar.gz
gitea-46d6b92ad04df87560ee12dfee58a5e8222e52ff.zip
Import topics during migration (#7851)
* add GetTopics interface * CreateTopics * remove un-needed comment
Diffstat (limited to 'modules')
-rw-r--r--modules/migrations/base/downloader.go1
-rw-r--r--modules/migrations/base/uploader.go1
-rw-r--r--modules/migrations/git.go5
-rw-r--r--modules/migrations/gitea.go5
-rw-r--r--modules/migrations/github.go6
-rw-r--r--modules/migrations/github_test.go4
-rw-r--r--modules/migrations/migrate.go11
7 files changed, 33 insertions, 0 deletions
diff --git a/modules/migrations/base/downloader.go b/modules/migrations/base/downloader.go
index f28d0b61e7..ab5ca6dec8 100644
--- a/modules/migrations/base/downloader.go
+++ b/modules/migrations/base/downloader.go
@@ -8,6 +8,7 @@ package base
// Downloader downloads the site repo informations
type Downloader interface {
GetRepoInfo() (*Repository, error)
+ GetTopics() ([]string, error)
GetMilestones() ([]*Milestone, error)
GetReleases() ([]*Release, error)
GetLabels() ([]*Label, error)
diff --git a/modules/migrations/base/uploader.go b/modules/migrations/base/uploader.go
index 8c1d649229..a3a9c9fac6 100644
--- a/modules/migrations/base/uploader.go
+++ b/modules/migrations/base/uploader.go
@@ -9,6 +9,7 @@ package base
type Uploader interface {
MaxBatchInsertSize(tp string) int
CreateRepo(repo *Repository, opts MigrateOptions) error
+ CreateTopics(topic ...string) error
CreateMilestones(milestones ...*Milestone) error
CreateReleases(releases ...*Release) error
CreateLabels(labels ...*Label) error
diff --git a/modules/migrations/git.go b/modules/migrations/git.go
index 335d44ec9b..75d05976cd 100644
--- a/modules/migrations/git.go
+++ b/modules/migrations/git.go
@@ -38,6 +38,11 @@ func (g *PlainGitDownloader) GetRepoInfo() (*base.Repository, error) {
}, nil
}
+// GetTopics returns empty list for plain git repo
+func (g *PlainGitDownloader) GetTopics() ([]string, error) {
+ return []string{}, nil
+}
+
// GetMilestones returns milestones
func (g *PlainGitDownloader) GetMilestones() ([]*base.Milestone, error) {
return nil, ErrNotSupported
diff --git a/modules/migrations/gitea.go b/modules/migrations/gitea.go
index 45f324516e..08244e5ab2 100644
--- a/modules/migrations/gitea.go
+++ b/modules/migrations/gitea.go
@@ -97,6 +97,11 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
return err
}
+// CreateTopics creates topics
+func (g *GiteaLocalUploader) CreateTopics(topics ...string) error {
+ return models.SaveTopics(g.repo.ID, topics...)
+}
+
// CreateMilestones creates milestones
func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) error {
var mss = make([]*models.Milestone, 0, len(milestones))
diff --git a/modules/migrations/github.go b/modules/migrations/github.go
index 93ba108548..c5f29cabb7 100644
--- a/modules/migrations/github.go
+++ b/modules/migrations/github.go
@@ -118,6 +118,12 @@ func (g *GithubDownloaderV3) GetRepoInfo() (*base.Repository, error) {
}, nil
}
+// GetTopics return github topics
+func (g *GithubDownloaderV3) GetTopics() ([]string, error) {
+ r, _, err := g.client.Repositories.Get(g.ctx, g.repoOwner, g.repoName)
+ return r.Topics, err
+}
+
// GetMilestones returns milestones
func (g *GithubDownloaderV3) GetMilestones() ([]*base.Milestone, error) {
var perPage = 100
diff --git a/modules/migrations/github_test.go b/modules/migrations/github_test.go
index 54845ab426..62fce6bbcc 100644
--- a/modules/migrations/github_test.go
+++ b/modules/migrations/github_test.go
@@ -71,6 +71,10 @@ func TestGitHubDownloadRepo(t *testing.T) {
OriginalURL: "https://github.com/go-gitea/gitea",
}, repo)
+ topics, err := downloader.GetTopics()
+ assert.NoError(t, err)
+ assert.Contains(t, topics, "gitea")
+
milestones, err := downloader.GetMilestones()
assert.NoError(t, err)
// before this tool release, we have 39 milestones on github.com/go-gitea/gitea
diff --git a/modules/migrations/migrate.go b/modules/migrations/migrate.go
index a86614c317..27782cb940 100644
--- a/modules/migrations/migrate.go
+++ b/modules/migrations/migrate.go
@@ -82,6 +82,17 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
return err
}
+ log.Trace("migrating topics")
+ topics, err := downloader.GetTopics()
+ if err != nil {
+ return err
+ }
+ if len(topics) > 0 {
+ if err := uploader.CreateTopics(topics...); err != nil {
+ return err
+ }
+ }
+
if opts.Milestones {
log.Trace("migrating milestones")
milestones, err := downloader.GetMilestones()