Import topics during migration (#7851)

* add GetTopics interface

* CreateTopics

* remove un-needed comment
tokarchuk/v1.17
Antoine GIRARD 5 years ago committed by Lunny Xiao
parent 99a004c343
commit 46d6b92ad0
  1. 1
      docs/content/doc/advanced/migrations.en-us.md
  2. 1
      modules/migrations/base/downloader.go
  3. 1
      modules/migrations/base/uploader.go
  4. 5
      modules/migrations/git.go
  5. 5
      modules/migrations/gitea.go
  6. 6
      modules/migrations/github.go
  7. 4
      modules/migrations/github_test.go
  8. 11
      modules/migrations/migrate.go

@ -34,6 +34,7 @@ create a Downloader.
```Go
type Downloader interface {
GetRepoInfo() (*Repository, error)
GetTopics() ([]string, error)
GetMilestones() ([]*Milestone, error)
GetReleases() ([]*Release, error)
GetLabels() ([]*Label, error)

@ -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)

@ -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

@ -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

@ -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))

@ -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

@ -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

@ -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()

Loading…
Cancel
Save