mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 07:43:18 -05:00
Import topics during migration (#7851)
* add GetTopics interface * CreateTopics * remove un-needed comment
This commit is contained in:
parent
99a004c343
commit
46d6b92ad0
8 changed files with 34 additions and 0 deletions
|
@ -34,6 +34,7 @@ create a Downloader.
|
||||||
```Go
|
```Go
|
||||||
type Downloader interface {
|
type Downloader interface {
|
||||||
GetRepoInfo() (*Repository, error)
|
GetRepoInfo() (*Repository, error)
|
||||||
|
GetTopics() ([]string, error)
|
||||||
GetMilestones() ([]*Milestone, error)
|
GetMilestones() ([]*Milestone, error)
|
||||||
GetReleases() ([]*Release, error)
|
GetReleases() ([]*Release, error)
|
||||||
GetLabels() ([]*Label, error)
|
GetLabels() ([]*Label, error)
|
||||||
|
|
|
@ -8,6 +8,7 @@ package base
|
||||||
// Downloader downloads the site repo informations
|
// Downloader downloads the site repo informations
|
||||||
type Downloader interface {
|
type Downloader interface {
|
||||||
GetRepoInfo() (*Repository, error)
|
GetRepoInfo() (*Repository, error)
|
||||||
|
GetTopics() ([]string, error)
|
||||||
GetMilestones() ([]*Milestone, error)
|
GetMilestones() ([]*Milestone, error)
|
||||||
GetReleases() ([]*Release, error)
|
GetReleases() ([]*Release, error)
|
||||||
GetLabels() ([]*Label, error)
|
GetLabels() ([]*Label, error)
|
||||||
|
|
|
@ -9,6 +9,7 @@ package base
|
||||||
type Uploader interface {
|
type Uploader interface {
|
||||||
MaxBatchInsertSize(tp string) int
|
MaxBatchInsertSize(tp string) int
|
||||||
CreateRepo(repo *Repository, opts MigrateOptions) error
|
CreateRepo(repo *Repository, opts MigrateOptions) error
|
||||||
|
CreateTopics(topic ...string) error
|
||||||
CreateMilestones(milestones ...*Milestone) error
|
CreateMilestones(milestones ...*Milestone) error
|
||||||
CreateReleases(releases ...*Release) error
|
CreateReleases(releases ...*Release) error
|
||||||
CreateLabels(labels ...*Label) error
|
CreateLabels(labels ...*Label) error
|
||||||
|
|
|
@ -38,6 +38,11 @@ func (g *PlainGitDownloader) GetRepoInfo() (*base.Repository, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetTopics returns empty list for plain git repo
|
||||||
|
func (g *PlainGitDownloader) GetTopics() ([]string, error) {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetMilestones returns milestones
|
// GetMilestones returns milestones
|
||||||
func (g *PlainGitDownloader) GetMilestones() ([]*base.Milestone, error) {
|
func (g *PlainGitDownloader) GetMilestones() ([]*base.Milestone, error) {
|
||||||
return nil, ErrNotSupported
|
return nil, ErrNotSupported
|
||||||
|
|
|
@ -97,6 +97,11 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateTopics creates topics
|
||||||
|
func (g *GiteaLocalUploader) CreateTopics(topics ...string) error {
|
||||||
|
return models.SaveTopics(g.repo.ID, topics...)
|
||||||
|
}
|
||||||
|
|
||||||
// CreateMilestones creates milestones
|
// CreateMilestones creates milestones
|
||||||
func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) error {
|
func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) error {
|
||||||
var mss = make([]*models.Milestone, 0, len(milestones))
|
var mss = make([]*models.Milestone, 0, len(milestones))
|
||||||
|
|
|
@ -118,6 +118,12 @@ func (g *GithubDownloaderV3) GetRepoInfo() (*base.Repository, error) {
|
||||||
}, nil
|
}, 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
|
// GetMilestones returns milestones
|
||||||
func (g *GithubDownloaderV3) GetMilestones() ([]*base.Milestone, error) {
|
func (g *GithubDownloaderV3) GetMilestones() ([]*base.Milestone, error) {
|
||||||
var perPage = 100
|
var perPage = 100
|
||||||
|
|
|
@ -71,6 +71,10 @@ func TestGitHubDownloadRepo(t *testing.T) {
|
||||||
OriginalURL: "https://github.com/go-gitea/gitea",
|
OriginalURL: "https://github.com/go-gitea/gitea",
|
||||||
}, repo)
|
}, repo)
|
||||||
|
|
||||||
|
topics, err := downloader.GetTopics()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Contains(t, topics, "gitea")
|
||||||
|
|
||||||
milestones, err := downloader.GetMilestones()
|
milestones, err := downloader.GetMilestones()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// before this tool release, we have 39 milestones on github.com/go-gitea/gitea
|
// 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
|
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 {
|
if opts.Milestones {
|
||||||
log.Trace("migrating milestones")
|
log.Trace("migrating milestones")
|
||||||
milestones, err := downloader.GetMilestones()
|
milestones, err := downloader.GetMilestones()
|
||||||
|
|
Loading…
Reference in a new issue