From 51938cd1613c789c7176ca59592689c3bf055f45 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Tue, 5 Dec 2023 16:43:35 +0100 Subject: [PATCH] [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 --- services/migrations/forgejo_downloader.go | 20 ++++++++++++++++++ .../migrations/forgejo_downloader_test.go | 16 ++++++++++++++ services/migrations/migrate.go | 21 ++++++++++++------- 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 services/migrations/forgejo_downloader.go create mode 100644 services/migrations/forgejo_downloader_test.go diff --git a/services/migrations/forgejo_downloader.go b/services/migrations/forgejo_downloader.go new file mode 100644 index 0000000000..25dbb6ec51 --- /dev/null +++ b/services/migrations/forgejo_downloader.go @@ -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 +} diff --git a/services/migrations/forgejo_downloader_test.go b/services/migrations/forgejo_downloader_test.go new file mode 100644 index 0000000000..5bd37551cc --- /dev/null +++ b/services/migrations/forgejo_downloader_test.go @@ -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)) +} diff --git a/services/migrations/migrate.go b/services/migrations/migrate.go index 0b83f3b4a3..ae164a7add 100644 --- a/services/migrations/migrate.go +++ b/services/migrations/migrate.go @@ -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 } }