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
3 changed files with 50 additions and 7 deletions
20
services/migrations/forgejo_downloader.go
Normal file
20
services/migrations/forgejo_downloader.go
Normal file
|
@ -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
|
||||||
|
}
|
16
services/migrations/forgejo_downloader_test.go
Normal file
16
services/migrations/forgejo_downloader_test.go
Normal file
|
@ -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"
|
"code.gitea.io/gitea/modules/log"
|
||||||
base "code.gitea.io/gitea/modules/migration"
|
base "code.gitea.io/gitea/modules/migration"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"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
|
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) {
|
func newDownloader(ctx context.Context, ownerName string, opts base.MigrateOptions) (base.Downloader, error) {
|
||||||
var (
|
var (
|
||||||
downloader base.Downloader
|
downloader base.Downloader
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, factory := range factories {
|
if factory := getFactoryFromServiceType(opts.GitServiceType); factory != nil {
|
||||||
if factory.GitServiceType() == opts.GitServiceType {
|
|
||||||
downloader, err = factory.New(ctx, opts)
|
downloader, err = factory.New(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if downloader == nil {
|
if downloader == nil {
|
||||||
|
|
Loading…
Reference in a new issue