mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-16 23:12:43 +00:00
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:
parent
f8e93ce423
commit
0f4e1b9ac6
37 changed files with 444 additions and 362 deletions
|
@ -13,7 +13,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/json"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/services/convert"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
webhook_service "code.gitea.io/gitea/services/webhook"
|
||||
)
|
||||
|
||||
|
@ -98,7 +98,7 @@ func AddRepoHook(ctx *context.APIContext, form *api.CreateHookOption) {
|
|||
// toAPIHook converts the hook to its API representation.
|
||||
// If there is an error, write to `ctx` accordingly. Return (hook, ok)
|
||||
func toAPIHook(ctx *context.APIContext, repoLink string, hook *webhook.Webhook) (*api.Hook, bool) {
|
||||
apiHook, err := convert.ToHook(repoLink, hook)
|
||||
apiHook, err := webhook_service.ToHook(repoLink, hook)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ToHook", err)
|
||||
return nil, false
|
||||
|
@ -127,9 +127,9 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID
|
|||
ContentType: webhook.ToHookContentType(form.Config["content_type"]),
|
||||
Secret: form.Config["secret"],
|
||||
HTTPMethod: "POST",
|
||||
HookEvent: &webhook.HookEvent{
|
||||
HookEvent: &webhook_module.HookEvent{
|
||||
ChooseEvents: true,
|
||||
HookEvents: webhook.HookEvents{
|
||||
HookEvents: webhook_module.HookEvents{
|
||||
Create: util.IsStringInSlice(string(webhook.HookEventCreate), form.Events, true),
|
||||
Delete: util.IsStringInSlice(string(webhook.HookEventDelete), form.Events, true),
|
||||
Fork: util.IsStringInSlice(string(webhook.HookEventFork), form.Events, true),
|
||||
|
@ -160,7 +160,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID
|
|||
ctx.Error(http.StatusInternalServerError, "SetHeaderAuthorization", err)
|
||||
return nil, false
|
||||
}
|
||||
if w.Type == webhook.SLACK {
|
||||
if w.Type == webhook_module.SLACK {
|
||||
channel, ok := form.Config["channel"]
|
||||
if !ok {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", "Missing config option: channel")
|
||||
|
@ -253,7 +253,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
|
|||
w.ContentType = webhook.ToHookContentType(ct)
|
||||
}
|
||||
|
||||
if w.Type == webhook.SLACK {
|
||||
if w.Type == webhook_module.SLACK {
|
||||
if channel, ok := form.Config["channel"]; ok {
|
||||
meta, err := json.Marshal(&webhook_service.SlackMeta{
|
||||
Channel: channel,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue