Restructure webhook module (#22256)

Previously, there was an `import services/webhooks` inside
`modules/notification/webhook`.
This import was removed (after fighting against many import cycles).
Additionally, `modules/notification/webhook` was moved to
`modules/webhook`,
and a few structs/constants were extracted from `models/webhooks` to
`modules/webhook`.

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
delvh 2023-01-01 16:23:15 +01:00 committed by GitHub
parent f8e93ce423
commit 0f4e1b9ac6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 444 additions and 362 deletions

View file

@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/json"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
webhook_module "code.gitea.io/gitea/modules/webhook"
"github.com/stretchr/testify/assert"
)
@ -46,11 +47,11 @@ func TestWebhook_History(t *testing.T) {
func TestWebhook_UpdateEvent(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
webhook := unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 1})
hookEvent := &HookEvent{
hookEvent := &webhook_module.HookEvent{
PushOnly: true,
SendEverything: false,
ChooseEvents: false,
HookEvents: HookEvents{
HookEvents: webhook_module.HookEvents{
Create: false,
Push: true,
PullRequest: false,
@ -59,7 +60,7 @@ func TestWebhook_UpdateEvent(t *testing.T) {
webhook.HookEvent = hookEvent
assert.NoError(t, webhook.UpdateEvent())
assert.NotEmpty(t, webhook.Events)
actualHookEvent := &HookEvent{}
actualHookEvent := &webhook_module.HookEvent{}
assert.NoError(t, json.Unmarshal([]byte(webhook.Events), actualHookEvent))
assert.Equal(t, *hookEvent, *actualHookEvent)
}
@ -74,13 +75,13 @@ func TestWebhook_EventsArray(t *testing.T) {
"package",
},
(&Webhook{
HookEvent: &HookEvent{SendEverything: true},
HookEvent: &webhook_module.HookEvent{SendEverything: true},
}).EventsArray(),
)
assert.Equal(t, []string{"push"},
(&Webhook{
HookEvent: &HookEvent{PushOnly: true},
HookEvent: &webhook_module.HookEvent{PushOnly: true},
}).EventsArray(),
)
}