[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:
Earl Warren 2023-12-05 16:43:35 +01:00
parent 9bdeee3081
commit 51938cd161
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 50 additions and 7 deletions

View 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
}

View 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))
}

View file

@ -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,19 +140,25 @@ 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
} }
} }