Browse Source

On Migration respect old DefaultBranch (#12843)

* On Migration respect old DefaultBranch

* add DefaultBranch int test set

Co-authored-by: zeripath <art27@cantab.net>
for-closed-social
6543 4 years ago
committed by GitHub
parent
commit
6c61f498ea
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 41 deletions
  1. +10
    -9
      modules/migrations/base/repo.go
  2. +1
    -0
      modules/migrations/gitea.go
  3. +12
    -6
      modules/migrations/github.go
  4. +6
    -5
      modules/migrations/github_test.go
  5. +7
    -6
      modules/migrations/gitlab.go
  6. +6
    -5
      modules/migrations/gitlab_test.go
  7. +14
    -10
      modules/repository/repo.go

+ 10
- 9
modules/migrations/base/repo.go View File

@ -7,13 +7,14 @@ package base
// Repository defines a standard repository information // Repository defines a standard repository information
type Repository struct { type Repository struct {
Name string
Owner string
IsPrivate bool
IsMirror bool
Description string
AuthUsername string
AuthPassword string
CloneURL string
OriginalURL string
Name string
Owner string
IsPrivate bool
IsMirror bool
Description string
AuthUsername string
AuthPassword string
CloneURL string
OriginalURL string
DefaultBranch string
} }

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

@ -122,6 +122,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
if err != nil { if err != nil {
return err return err
} }
r.DefaultBranch = repo.DefaultBranch
r, err = repository.MigrateRepositoryGitData(g.doer, owner, r, base.MigrateOptions{ r, err = repository.MigrateRepositoryGitData(g.doer, owner, r, base.MigrateOptions{
RepoName: g.repoName, RepoName: g.repoName,

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

@ -143,14 +143,20 @@ func (g *GithubDownloaderV3) GetRepoInfo() (*base.Repository, error) {
} }
g.rate = &resp.Rate g.rate = &resp.Rate
defaultBranch := ""
if gr.DefaultBranch != nil {
defaultBranch = *gr.DefaultBranch
}
// convert github repo to stand Repo // convert github repo to stand Repo
return &base.Repository{ return &base.Repository{
Owner: g.repoOwner,
Name: gr.GetName(),
IsPrivate: *gr.Private,
Description: gr.GetDescription(),
OriginalURL: gr.GetHTMLURL(),
CloneURL: gr.GetCloneURL(),
Owner: g.repoOwner,
Name: gr.GetName(),
IsPrivate: *gr.Private,
Description: gr.GetDescription(),
OriginalURL: gr.GetHTMLURL(),
CloneURL: gr.GetCloneURL(),
DefaultBranch: defaultBranch,
}, nil }, nil
} }

+ 6
- 5
modules/migrations/github_test.go View File

@ -72,11 +72,12 @@ func TestGitHubDownloadRepo(t *testing.T) {
repo, err := downloader.GetRepoInfo() repo, err := downloader.GetRepoInfo()
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, &base.Repository{ assert.EqualValues(t, &base.Repository{
Name: "test_repo",
Owner: "go-gitea",
Description: "Test repository for testing migration from github to gitea",
CloneURL: "https://github.com/go-gitea/test_repo.git",
OriginalURL: "https://github.com/go-gitea/test_repo",
Name: "test_repo",
Owner: "go-gitea",
Description: "Test repository for testing migration from github to gitea",
CloneURL: "https://github.com/go-gitea/test_repo.git",
OriginalURL: "https://github.com/go-gitea/test_repo",
DefaultBranch: "master",
}, repo) }, repo)
topics, err := downloader.GetTopics() topics, err := downloader.GetTopics()

+ 7
- 6
modules/migrations/gitlab.go View File

@ -139,12 +139,13 @@ func (g *GitlabDownloader) GetRepoInfo() (*base.Repository, error) {
// convert gitlab repo to stand Repo // convert gitlab repo to stand Repo
return &base.Repository{ return &base.Repository{
Owner: owner,
Name: gr.Name,
IsPrivate: private,
Description: gr.Description,
OriginalURL: gr.WebURL,
CloneURL: gr.HTTPURLToRepo,
Owner: owner,
Name: gr.Name,
IsPrivate: private,
Description: gr.Description,
OriginalURL: gr.WebURL,
CloneURL: gr.HTTPURLToRepo,
DefaultBranch: gr.DefaultBranch,
}, nil }, nil
} }

+ 6
- 5
modules/migrations/gitlab_test.go View File

@ -37,11 +37,12 @@ func TestGitlabDownloadRepo(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
// Repo Owner is blank in Gitlab Group repos // Repo Owner is blank in Gitlab Group repos
assert.EqualValues(t, &base.Repository{ assert.EqualValues(t, &base.Repository{
Name: "test_repo",
Owner: "",
Description: "Test repository for testing migration from gitlab to gitea",
CloneURL: "https://gitlab.com/gitea/test_repo.git",
OriginalURL: "https://gitlab.com/gitea/test_repo",
Name: "test_repo",
Owner: "",
Description: "Test repository for testing migration from gitlab to gitea",
CloneURL: "https://gitlab.com/gitea/test_repo.git",
OriginalURL: "https://gitlab.com/gitea/test_repo",
DefaultBranch: "master",
}, repo) }, repo)
topics, err := downloader.GetTopics() topics, err := downloader.GetTopics()

+ 14
- 10
modules/repository/repo.go View File

@ -102,18 +102,22 @@ func MigrateRepositoryGitData(doer, u *models.User, repo *models.Repository, opt
return repo, fmt.Errorf("git.IsEmpty: %v", err) return repo, fmt.Errorf("git.IsEmpty: %v", err)
} }
if !opts.Releases && !repo.IsEmpty {
// Try to get HEAD branch and set it as default branch.
headBranch, err := gitRepo.GetHEADBranch()
if err != nil {
return repo, fmt.Errorf("GetHEADBranch: %v", err)
}
if headBranch != nil {
repo.DefaultBranch = headBranch.Name
if !repo.IsEmpty {
if len(repo.DefaultBranch) == 0 {
// Try to get HEAD branch and set it as default branch.
headBranch, err := gitRepo.GetHEADBranch()
if err != nil {
return repo, fmt.Errorf("GetHEADBranch: %v", err)
}
if headBranch != nil {
repo.DefaultBranch = headBranch.Name
}
} }
if err = SyncReleasesWithTags(repo, gitRepo); err != nil {
log.Error("Failed to synchronize tags to releases for repository: %v", err)
if !opts.Releases {
if err = SyncReleasesWithTags(repo, gitRepo); err != nil {
log.Error("Failed to synchronize tags to releases for repository: %v", err)
}
} }
} }

Loading…
Cancel
Save