From ab1e46471f6081829de52c355f2b44792f84f2e0 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 10 Nov 2020 21:13:31 +0100 Subject: [PATCH 1/3] Add Gitea2Gitea Migration Support --- gitea/repo_migrate.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gitea/repo_migrate.go b/gitea/repo_migrate.go index 583d800..c114f28 100644 --- a/gitea/repo_migrate.go +++ b/gitea/repo_migrate.go @@ -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 err := c.CheckServerVersionConstraint(">=1.13.0"); err != 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 } -- 2.40.1 From 71a561720b8f1bac959338c22202f2cf327cefb1 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 9 Nov 2020 22:17:06 +0100 Subject: [PATCH 2/3] Update TestData --- gitea/repo_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitea/repo_test.go b/gitea/repo_test.go index 0131505..3e19a6a 100644 --- a/gitea/repo_test.go +++ b/gitea/repo_test.go @@ -66,7 +66,7 @@ func TestRepoMigrateAndLanguages(t *testing.T) { assert.NoError(t, err) assert.Len(t, lang, 2) assert.True(t, 217441 < lang["Go"]) - assert.EqualValues(t, 3614, lang["Makefile"]) + assert.True(t, 3614 < lang["Makefile"] && 6000 > lang["Makefile"]) } func TestSearchRepo(t *testing.T) { -- 2.40.1 From 5b3385e3f52428a63b33a71b8a2fb09b7297c677 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 12 Nov 2020 22:04:17 +0100 Subject: [PATCH 3/3] adopt #442 --- gitea/repo_migrate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitea/repo_migrate.go b/gitea/repo_migrate.go index e89537e..518c6ae 100644 --- a/gitea/repo_migrate.go +++ b/gitea/repo_migrate.go @@ -75,7 +75,7 @@ func (opt *MigrateRepoOption) Validate(c *Client) error { } // 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 err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil { + if c.checkServerVersionGreaterThanOrEqual(version1_13_0) != nil { return fmt.Errorf("migrate from service %s need gitea >= 1.13.0", opt.Service) } } -- 2.40.1