Skip to content

Commit

Permalink
Fix bug conflict between SyncReleasesWithTags and InsertReleases (#7337)
Browse files Browse the repository at this point in the history
* fix bug conflict between SyncReleasesWithTags and InsertReleases

* fix tests

* fix fmt
  • Loading branch information
lunny authored and zeripath committed Jul 1, 2019
1 parent 9fdd199 commit e728b55
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
13 changes: 7 additions & 6 deletions models/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ func TestRelease_MirrorDelete(t *testing.T) {
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
repoPath := RepoPath(user.Name, repo.Name)
migrationOptions := MigrateRepoOptions{
Name: "test_mirror",
Description: "Test mirror",
IsPrivate: false,
IsMirror: true,
RemoteAddr: repoPath,
Wiki: true,
Name: "test_mirror",
Description: "Test mirror",
IsPrivate: false,
IsMirror: true,
RemoteAddr: repoPath,
Wiki: true,
SyncReleasesWithTags: true,
}
mirror, err := MigrateRepository(user, user, migrationOptions)
assert.NoError(t, err)
Expand Down
15 changes: 8 additions & 7 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,12 +845,13 @@ func (repo *Repository) CloneLink() (cl *CloneLink) {

// MigrateRepoOptions contains the repository migrate options
type MigrateRepoOptions struct {
Name string
Description string
IsPrivate bool
IsMirror bool
RemoteAddr string
Wiki bool // include wiki repository
Name string
Description string
IsPrivate bool
IsMirror bool
RemoteAddr string
Wiki bool // include wiki repository
SyncReleasesWithTags bool // sync releases from tags
}

/*
Expand Down Expand Up @@ -942,7 +943,7 @@ func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, 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.
headBranch, err := gitRepo.GetHEADBranch()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion modules/migrations/base/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package base

// Uploader uploads all the informations of one repository
type Uploader interface {
CreateRepo(repo *Repository, includeWiki bool) error
CreateRepo(repo *Repository, opts MigrateOptions) error
CreateMilestones(milestones ...*Milestone) error
CreateReleases(releases ...*Release) error
CreateLabels(labels ...*Label) error
Expand Down
22 changes: 14 additions & 8 deletions modules/migrations/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,20 @@ func NewGiteaLocalUploader(doer *models.User, repoOwner, repoName string) *Gitea
}

// 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)
if err != nil {
return err
}

r, err := models.MigrateRepository(g.doer, owner, models.MigrateRepoOptions{
Name: g.repoName,
Description: repo.Description,
IsMirror: repo.IsMirror,
RemoteAddr: repo.CloneURL,
IsPrivate: repo.IsPrivate,
Wiki: includeWiki,
Name: g.repoName,
Description: repo.Description,
IsMirror: repo.IsMirror,
RemoteAddr: repo.CloneURL,
IsPrivate: repo.IsPrivate,
Wiki: opts.Wiki,
SyncReleasesWithTags: !opts.Releases, // if didn't get releases, then sync them from tags
})
g.repo = r
if err != nil {
Expand Down Expand Up @@ -198,7 +199,12 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {

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
Expand Down
2 changes: 1 addition & 1 deletion modules/migrations/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
repo.Description = opts.Description
}
log.Trace("migrating git data")
if err := uploader.CreateRepo(repo, opts.Wiki); err != nil {
if err := uploader.CreateRepo(repo, opts); err != nil {
return err
}

Expand Down

0 comments on commit e728b55

Please sign in to comment.