Browse Source

Import topics during migration (#7851)

* add GetTopics interface

* CreateTopics

* remove un-needed comment
for-closed-social
Antoine GIRARD 5 years ago
committed by Lunny Xiao
parent
commit
46d6b92ad0
8 changed files with 34 additions and 0 deletions
  1. +1
    -0
      docs/content/doc/advanced/migrations.en-us.md
  2. +1
    -0
      modules/migrations/base/downloader.go
  3. +1
    -0
      modules/migrations/base/uploader.go
  4. +5
    -0
      modules/migrations/git.go
  5. +5
    -0
      modules/migrations/gitea.go
  6. +6
    -0
      modules/migrations/github.go
  7. +4
    -0
      modules/migrations/github_test.go
  8. +11
    -0
      modules/migrations/migrate.go

+ 1
- 0
docs/content/doc/advanced/migrations.en-us.md View File

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

+ 1
- 0
modules/migrations/base/downloader.go View File

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

+ 1
- 0
modules/migrations/base/uploader.go View File

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

+ 5
- 0
modules/migrations/git.go View File

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

+ 5
- 0
modules/migrations/gitea.go View File

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

+ 6
- 0
modules/migrations/github.go View File

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

+ 4
- 0
modules/migrations/github_test.go View File

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

+ 11
- 0
modules/migrations/migrate.go View File

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