Add Gitea2Gitea Migration Support (#454)

Add Gitea2Gitea Migration Support

Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/454
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: John Olheiser <john.olheiser@gmail.com>
Co-Authored-By: 6543 <6543@obermui.de>
Co-Committed-By: 6543 <6543@obermui.de>
This commit is contained in:
6543 2020-11-13 05:16:11 +08:00
parent 9c81fa936f
commit b00ea89ffe

View file

@ -20,10 +20,10 @@ const (
GitServiceGithub GitServiceType = "github"
// GitServiceGitlab represents a gitlab service
GitServiceGitlab GitServiceType = "gitlab"
// GitServiceGitea represents a gitea service
GitServiceGitea GitServiceType = "gitea"
// Not supported jet
// // GitServiceGitea represents a gitea service
// GitServiceGitea GitServiceType = "gitea"
// // GitServiceGogs represents a gogs service
// GitServiceGogs GitServiceType = "gogs"
)
@ -51,7 +51,7 @@ type MigrateRepoOption struct {
}
// Validate the MigrateRepoOption struct
func (opt *MigrateRepoOption) Validate() error {
func (opt *MigrateRepoOption) Validate(c *Client) error {
// check user options
if len(opt.CloneAddr) == 0 {
return fmt.Errorf("CloneAddr required")
@ -69,6 +69,15 @@ func (opt *MigrateRepoOption) Validate() error {
if len(opt.AuthToken) == 0 {
return fmt.Errorf("github require token authentication")
}
case GitServiceGitlab, GitServiceGitea:
if len(opt.AuthToken) == 0 {
return fmt.Errorf("%s require token authentication", opt.Service)
}
// Gitlab is supported since 1.12.0 but api cant handle it until 1.13.0
// https://github.com/go-gitea/gitea/pull/12672
if c.checkServerVersionGreaterThanOrEqual(version1_13_0) != nil {
return fmt.Errorf("migrate from service %s need gitea >= 1.13.0", opt.Service)
}
}
return nil
}
@ -78,7 +87,7 @@ func (opt *MigrateRepoOption) Validate() error {
// To migrate a repository for a organization, the authenticated user must be a
// owner of the specified organization.
func (c *Client) MigrateRepo(opt MigrateRepoOption) (*Repository, *Response, error) {
if err := opt.Validate(); err != nil {
if err := opt.Validate(c); err != nil {
return nil, nil, err
}