Merge pull request '[FEAT] add Forgero Git Service (squash) register a Forgejo factory' (#1883) from earl-warren/forgejo:wip-forgejo-migration into forgejo-dependency
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1883
This commit is contained in:
commit
eb44e6a1ab
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2023 The Forgejo Authors
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterDownloaderFactory(&ForgejoDownloaderFactory{})
|
||||
}
|
||||
|
||||
type ForgejoDownloaderFactory struct {
|
||||
GiteaDownloaderFactory
|
||||
}
|
||||
|
||||
func (f *ForgejoDownloaderFactory) GitServiceType() structs.GitServiceType {
|
||||
return structs.ForgejoService
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2023 The Forgejo Authors
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestForgejoDownload(t *testing.T) {
|
||||
require.NotNil(t, getFactoryFromServiceType(structs.ForgejoService))
|
||||
}
|
|
@ -20,6 +20,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/log"
|
||||
base "code.gitea.io/gitea/modules/migration"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
|
@ -139,20 +140,26 @@ func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName str
|
|||
return uploader.repo, nil
|
||||
}
|
||||
|
||||
func getFactoryFromServiceType(serviceType structs.GitServiceType) base.DownloaderFactory {
|
||||
for _, factory := range factories {
|
||||
if factory.GitServiceType() == serviceType {
|
||||
return factory
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func newDownloader(ctx context.Context, ownerName string, opts base.MigrateOptions) (base.Downloader, error) {
|
||||
var (
|
||||
downloader base.Downloader
|
||||
err error
|
||||
)
|
||||
|
||||
for _, factory := range factories {
|
||||
if factory.GitServiceType() == opts.GitServiceType {
|
||||
if factory := getFactoryFromServiceType(opts.GitServiceType); factory != nil {
|
||||
downloader, err = factory.New(ctx, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if downloader == nil {
|
||||
|
|
Loading…
Reference in New Issue