mirror of
https://github.com/go-gitea/gitea
synced 2025-08-09 19:18:20 +00:00
Move webhook to a standalone package under modules (#8747)
* Move webhook to a standalone package under modules * fix test * fix comments
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/webhook"
|
||||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
@@ -122,7 +123,7 @@ func TestHook(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := models.PrepareWebhook(hook, ctx.Repo.Repository, models.HookEventPush, &api.PushPayload{
|
||||
if err := webhook.PrepareWebhook(hook, ctx.Repo.Repository, models.HookEventPush, &api.PushPayload{
|
||||
Ref: git.BranchPrefix + ctx.Repo.Repository.DefaultBranch,
|
||||
Before: ctx.Repo.Commit.ID.String(),
|
||||
After: ctx.Repo.Commit.ID.String(),
|
||||
@@ -136,7 +137,7 @@ func TestHook(ctx *context.APIContext) {
|
||||
ctx.Error(500, "PrepareWebhook: ", err)
|
||||
return
|
||||
}
|
||||
go models.HookQueue.Add(ctx.Repo.Repository.ID)
|
||||
go webhook.HookQueue.Add(ctx.Repo.Repository.ID)
|
||||
ctx.Status(204)
|
||||
}
|
||||
|
||||
|
@@ -22,6 +22,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/ssh"
|
||||
"code.gitea.io/gitea/modules/task"
|
||||
"code.gitea.io/gitea/modules/webhook"
|
||||
"code.gitea.io/gitea/services/mailer"
|
||||
mirror_service "code.gitea.io/gitea/services/mirror"
|
||||
|
||||
@@ -101,7 +102,7 @@ func GlobalInit() {
|
||||
issue_indexer.InitIssueIndexer(false)
|
||||
models.InitRepoIndexer()
|
||||
mirror_service.InitSyncMirrors()
|
||||
models.InitDeliverHooks()
|
||||
webhook.InitDeliverHooks()
|
||||
models.InitTestPullRequests()
|
||||
if err := task.Init(); err != nil {
|
||||
log.Fatal("Failed to initialize task scheduler: %v", err)
|
||||
|
@@ -23,6 +23,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/webhook"
|
||||
"code.gitea.io/gitea/services/gitdiff"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
@@ -823,7 +824,7 @@ func TriggerTask(ctx *context.Context) {
|
||||
|
||||
log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
|
||||
|
||||
go models.HookQueue.Add(repo.ID)
|
||||
go webhook.HookQueue.Add(repo.ID)
|
||||
go pull_service.AddTestPullRequestTask(pusher, repo.ID, branch, true)
|
||||
ctx.Status(202)
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/webhook"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
)
|
||||
@@ -864,11 +865,11 @@ func TestWebhook(ctx *context.Context) {
|
||||
Pusher: apiUser,
|
||||
Sender: apiUser,
|
||||
}
|
||||
if err := models.PrepareWebhook(w, ctx.Repo.Repository, models.HookEventPush, p); err != nil {
|
||||
if err := webhook.PrepareWebhook(w, ctx.Repo.Repository, models.HookEventPush, p); err != nil {
|
||||
ctx.Flash.Error("PrepareWebhook: " + err.Error())
|
||||
ctx.Status(500)
|
||||
} else {
|
||||
go models.HookQueue.Add(ctx.Repo.Repository.ID)
|
||||
go webhook.HookQueue.Add(ctx.Repo.Repository.ID)
|
||||
ctx.Flash.Info(ctx.Tr("repo.settings.webhook.test_delivery_success"))
|
||||
ctx.Status(200)
|
||||
}
|
||||
|
Reference in New Issue
Block a user