From 130c414b49aa9446b66f97045b6dad9e094966ea Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Sep 2023 12:13:47 +0800 Subject: [PATCH 1/3] Move feed notification service layer --- modules/notification/notification.go | 2 -- routers/init.go | 2 ++ {modules/notification/action => services/feed}/action.go | 9 ++++++++- .../notification/action => services/feed}/action_test.go | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) rename {modules/notification/action => services/feed}/action.go (99%) rename {modules/notification/action => services/feed}/action_test.go (98%) diff --git a/modules/notification/notification.go b/modules/notification/notification.go index 50b2694d9c413..f0bdf1c9be27c 100644 --- a/modules/notification/notification.go +++ b/modules/notification/notification.go @@ -12,7 +12,6 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification/action" "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/notification/indexer" "code.gitea.io/gitea/modules/notification/mail" @@ -36,7 +35,6 @@ func NewContext() { RegisterNotifier(mail.NewNotifier()) } RegisterNotifier(indexer.NewNotifier()) - RegisterNotifier(action.NewNotifier()) } // NotifyNewWikiPage notifies creating new wiki pages to notifiers diff --git a/routers/init.go b/routers/init.go index 020fff31c0e38..164cb4f99ea22 100644 --- a/routers/init.go +++ b/routers/init.go @@ -41,6 +41,7 @@ import ( "code.gitea.io/gitea/services/auth/source/oauth2" "code.gitea.io/gitea/services/automerge" "code.gitea.io/gitea/services/cron" + feed_service "code.gitea.io/gitea/services/feed" "code.gitea.io/gitea/services/mailer" mailer_incoming "code.gitea.io/gitea/services/mailer/incoming" markup_service "code.gitea.io/gitea/services/markup" @@ -121,6 +122,7 @@ func InitWebInstalled(ctx context.Context) { mailer.NewContext(ctx) mustInit(cache.NewContext) notification.NewContext() + mustInit(feed_service.Init) mustInit(archiver.Init) highlight.NewContext() diff --git a/modules/notification/action/action.go b/services/feed/action.go similarity index 99% rename from modules/notification/action/action.go rename to services/feed/action.go index 1d759e4923678..3516e79feade7 100644 --- a/modules/notification/action/action.go +++ b/services/feed/action.go @@ -1,7 +1,7 @@ // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package action +package feed import ( "context" @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/util" @@ -27,6 +28,12 @@ type actionNotifier struct { var _ base.Notifier = &actionNotifier{} +func Init() error { + notification.RegisterNotifier(NewNotifier()) + + return nil +} + // NewNotifier create a new actionNotifier notifier func NewNotifier() base.Notifier { return &actionNotifier{} diff --git a/modules/notification/action/action_test.go b/services/feed/action_test.go similarity index 98% rename from modules/notification/action/action_test.go rename to services/feed/action_test.go index 05ce70f38877d..69e070a3f6147 100644 --- a/modules/notification/action/action_test.go +++ b/services/feed/action_test.go @@ -1,7 +1,7 @@ // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package action +package feed import ( "path/filepath" From 339c86801370211daedc6de88c5e58a46f03c4a0 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Sep 2023 16:08:57 +0800 Subject: [PATCH 2/3] Fix test --- services/repository/transfer_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/repository/transfer_test.go b/services/repository/transfer_test.go index 1299e66be2781..53ba3c2441d4d 100644 --- a/services/repository/transfer_test.go +++ b/services/repository/transfer_test.go @@ -15,8 +15,8 @@ import ( "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/notification" - "code.gitea.io/gitea/modules/notification/action" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/services/feed" "github.com/stretchr/testify/assert" ) @@ -25,7 +25,7 @@ var notifySync sync.Once func registerNotifier() { notifySync.Do(func() { - notification.RegisterNotifier(action.NewNotifier()) + notification.RegisterNotifier(feed.NewNotifier()) }) } From d342f85b6f89444e177839078310aa22a9613bcb Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Sep 2023 16:36:44 +0800 Subject: [PATCH 3/3] Fix test --- services/feed/action_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/feed/action_test.go b/services/feed/action_test.go index 69e070a3f6147..1037ba768e229 100644 --- a/services/feed/action_test.go +++ b/services/feed/action_test.go @@ -19,7 +19,7 @@ import ( func TestMain(m *testing.M) { unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), + GiteaRootPath: filepath.Join("..", ".."), }) }