* On Migration respect old DefaultBranch * add DefaultBranch int test set Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
ff9d99f63d
commit
6305f07fdc
7 changed files with 56 additions and 41 deletions
|
@ -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
|
Name string
|
||||||
Owner string
|
Owner string
|
||||||
IsPrivate bool
|
IsPrivate bool
|
||||||
IsMirror bool
|
IsMirror bool
|
||||||
Description string
|
Description string
|
||||||
AuthUsername string
|
AuthUsername string
|
||||||
AuthPassword string
|
AuthPassword string
|
||||||
CloneURL string
|
CloneURL string
|
||||||
OriginalURL string
|
OriginalURL string
|
||||||
|
DefaultBranch string
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,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, structs.MigrateRepoOption{
|
r, err = repository.MigrateRepositoryGitData(g.doer, owner, r, structs.MigrateRepoOption{
|
||||||
RepoName: g.repoName,
|
RepoName: g.repoName,
|
||||||
|
|
|
@ -154,14 +154,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,
|
Owner: g.repoOwner,
|
||||||
Name: gr.GetName(),
|
Name: gr.GetName(),
|
||||||
IsPrivate: *gr.Private,
|
IsPrivate: *gr.Private,
|
||||||
Description: gr.GetDescription(),
|
Description: gr.GetDescription(),
|
||||||
OriginalURL: gr.GetHTMLURL(),
|
OriginalURL: gr.GetHTMLURL(),
|
||||||
CloneURL: gr.GetCloneURL(),
|
CloneURL: gr.GetCloneURL(),
|
||||||
|
DefaultBranch: defaultBranch,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,11 +71,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",
|
Name: "test_repo",
|
||||||
Owner: "go-gitea",
|
Owner: "go-gitea",
|
||||||
Description: "Test repository for testing migration from github to gitea",
|
Description: "Test repository for testing migration from github to gitea",
|
||||||
CloneURL: "https://github.com/go-gitea/test_repo.git",
|
CloneURL: "https://github.com/go-gitea/test_repo.git",
|
||||||
OriginalURL: "https://github.com/go-gitea/test_repo",
|
OriginalURL: "https://github.com/go-gitea/test_repo",
|
||||||
|
DefaultBranch: "master",
|
||||||
}, repo)
|
}, repo)
|
||||||
|
|
||||||
topics, err := downloader.GetTopics()
|
topics, err := downloader.GetTopics()
|
||||||
|
|
|
@ -157,12 +157,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,
|
Owner: owner,
|
||||||
Name: gr.Name,
|
Name: gr.Name,
|
||||||
IsPrivate: private,
|
IsPrivate: private,
|
||||||
Description: gr.Description,
|
Description: gr.Description,
|
||||||
OriginalURL: gr.WebURL,
|
OriginalURL: gr.WebURL,
|
||||||
CloneURL: gr.HTTPURLToRepo,
|
CloneURL: gr.HTTPURLToRepo,
|
||||||
|
DefaultBranch: gr.DefaultBranch,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,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",
|
Name: "test_repo",
|
||||||
Owner: "",
|
Owner: "",
|
||||||
Description: "Test repository for testing migration from gitlab to gitea",
|
Description: "Test repository for testing migration from gitlab to gitea",
|
||||||
CloneURL: "https://gitlab.com/gitea/test_repo.git",
|
CloneURL: "https://gitlab.com/gitea/test_repo.git",
|
||||||
OriginalURL: "https://gitlab.com/gitea/test_repo",
|
OriginalURL: "https://gitlab.com/gitea/test_repo",
|
||||||
|
DefaultBranch: "master",
|
||||||
}, repo)
|
}, repo)
|
||||||
|
|
||||||
topics, err := downloader.GetTopics()
|
topics, err := downloader.GetTopics()
|
||||||
|
|
|
@ -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 {
|
if !repo.IsEmpty {
|
||||||
// Try to get HEAD branch and set it as default branch.
|
if len(repo.DefaultBranch) == 0 {
|
||||||
headBranch, err := gitRepo.GetHEADBranch()
|
// Try to get HEAD branch and set it as default branch.
|
||||||
if err != nil {
|
headBranch, err := gitRepo.GetHEADBranch()
|
||||||
return repo, fmt.Errorf("GetHEADBranch: %v", err)
|
if err != nil {
|
||||||
}
|
return repo, fmt.Errorf("GetHEADBranch: %v", err)
|
||||||
if headBranch != nil {
|
}
|
||||||
repo.DefaultBranch = headBranch.Name
|
if headBranch != nil {
|
||||||
|
repo.DefaultBranch = headBranch.Name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = SyncReleasesWithTags(repo, gitRepo); err != nil {
|
if !opts.Releases {
|
||||||
log.Error("Failed to synchronize tags to releases for repository: %v", err)
|
if err = SyncReleasesWithTags(repo, gitRepo); err != nil {
|
||||||
|
log.Error("Failed to synchronize tags to releases for repository: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue