Fix bug conflict between SyncReleasesWithTags and InsertReleases (#7337)
* fix bug conflict between SyncReleasesWithTags and InsertReleases * fix tests * fix fmtrelease/v1.15
parent
9fdd199cca
commit
e728b55812
|
@ -102,12 +102,13 @@ func TestRelease_MirrorDelete(t *testing.T) {
|
||||||
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
||||||
repoPath := RepoPath(user.Name, repo.Name)
|
repoPath := RepoPath(user.Name, repo.Name)
|
||||||
migrationOptions := MigrateRepoOptions{
|
migrationOptions := MigrateRepoOptions{
|
||||||
Name: "test_mirror",
|
Name: "test_mirror",
|
||||||
Description: "Test mirror",
|
Description: "Test mirror",
|
||||||
IsPrivate: false,
|
IsPrivate: false,
|
||||||
IsMirror: true,
|
IsMirror: true,
|
||||||
RemoteAddr: repoPath,
|
RemoteAddr: repoPath,
|
||||||
Wiki: true,
|
Wiki: true,
|
||||||
|
SyncReleasesWithTags: true,
|
||||||
}
|
}
|
||||||
mirror, err := MigrateRepository(user, user, migrationOptions)
|
mirror, err := MigrateRepository(user, user, migrationOptions)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -845,12 +845,13 @@ func (repo *Repository) CloneLink() (cl *CloneLink) {
|
||||||
|
|
||||||
// MigrateRepoOptions contains the repository migrate options
|
// MigrateRepoOptions contains the repository migrate options
|
||||||
type MigrateRepoOptions struct {
|
type MigrateRepoOptions struct {
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
IsPrivate bool
|
IsPrivate bool
|
||||||
IsMirror bool
|
IsMirror bool
|
||||||
RemoteAddr string
|
RemoteAddr string
|
||||||
Wiki bool // include wiki repository
|
Wiki bool // include wiki repository
|
||||||
|
SyncReleasesWithTags bool // sync releases from tags
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -942,7 +943,7 @@ func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, err
|
||||||
return repo, fmt.Errorf("git.IsEmpty: %v", err)
|
return repo, fmt.Errorf("git.IsEmpty: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !repo.IsEmpty {
|
if opts.SyncReleasesWithTags && !repo.IsEmpty {
|
||||||
// Try to get HEAD branch and set it as default branch.
|
// Try to get HEAD branch and set it as default branch.
|
||||||
headBranch, err := gitRepo.GetHEADBranch()
|
headBranch, err := gitRepo.GetHEADBranch()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -7,7 +7,7 @@ package base
|
||||||
|
|
||||||
// Uploader uploads all the informations of one repository
|
// Uploader uploads all the informations of one repository
|
||||||
type Uploader interface {
|
type Uploader interface {
|
||||||
CreateRepo(repo *Repository, includeWiki bool) error
|
CreateRepo(repo *Repository, opts MigrateOptions) 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
|
||||||
|
|
|
@ -54,19 +54,20 @@ func NewGiteaLocalUploader(doer *models.User, repoOwner, repoName string) *Gitea
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateRepo creates a repository
|
// CreateRepo creates a repository
|
||||||
func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, includeWiki bool) error {
|
func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.MigrateOptions) error {
|
||||||
owner, err := models.GetUserByName(g.repoOwner)
|
owner, err := models.GetUserByName(g.repoOwner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := models.MigrateRepository(g.doer, owner, models.MigrateRepoOptions{
|
r, err := models.MigrateRepository(g.doer, owner, models.MigrateRepoOptions{
|
||||||
Name: g.repoName,
|
Name: g.repoName,
|
||||||
Description: repo.Description,
|
Description: repo.Description,
|
||||||
IsMirror: repo.IsMirror,
|
IsMirror: repo.IsMirror,
|
||||||
RemoteAddr: repo.CloneURL,
|
RemoteAddr: repo.CloneURL,
|
||||||
IsPrivate: repo.IsPrivate,
|
IsPrivate: repo.IsPrivate,
|
||||||
Wiki: includeWiki,
|
Wiki: opts.Wiki,
|
||||||
|
SyncReleasesWithTags: !opts.Releases, // if didn't get releases, then sync them from tags
|
||||||
})
|
})
|
||||||
g.repo = r
|
g.repo = r
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -198,7 +199,12 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
|
||||||
|
|
||||||
rels = append(rels, &rel)
|
rels = append(rels, &rel)
|
||||||
}
|
}
|
||||||
return models.InsertReleases(rels...)
|
if err := models.InsertReleases(rels...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// sync tags to releases in database
|
||||||
|
return models.SyncReleasesWithTags(g.repo, g.gitRepo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateIssues creates issues
|
// CreateIssues creates issues
|
||||||
|
|
|
@ -80,7 +80,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
|
||||||
repo.Description = opts.Description
|
repo.Description = opts.Description
|
||||||
}
|
}
|
||||||
log.Trace("migrating git data")
|
log.Trace("migrating git data")
|
||||||
if err := uploader.CreateRepo(repo, opts.Wiki); err != nil {
|
if err := uploader.CreateRepo(repo, opts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue