mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-18 06:58:19 +00:00
[FEAT] add Forgejo Git Service (squash) register a Forgejo factory
If the Forgejo factory for the Forgejo service is not registered, newDownloader will fallback to a git service and not migrate issues etc. Refs: https://codeberg.org/forgejo/forgejo/issues/1678
This commit is contained in:
parent
9bdeee3081
commit
51938cd161
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"
|
||||
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,19 +140,25 @@ 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 {
|
||||
downloader, err = factory.New(ctx, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
break
|
||||
if factory := getFactoryFromServiceType(opts.GitServiceType); factory != nil {
|
||||
downloader, err = factory.New(ctx, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue