forgejo/services
oliverpool 53f6f62ad4
Store webhook event in database (#29145)
Refactor the webhook logic, to have the type-dependent processing happen
only in one place.

---

1. An event happens
2. It is pre-processed (depending on the webhook type) and its body is
added to a task queue
3. When the task is processed, some more logic (depending on the webhook
type as well) is applied to make an HTTP request

This means that webhook-type dependant logic is needed in step 2 and 3.
This is cumbersome and brittle to maintain.

Updated webhook flow with this PR:
1. An event happens
2. It is stored as-is and added to a task queue
3. When the task is processed, the event is processed (depending on the
webhook type) to make an HTTP request

So the only webhook-type dependent logic happens in one place (step 3)
which should be much more robust.

- the raw event must be stored in the hooktask (until now, the
pre-processed body was stored)
- to ensure that previous hooktasks are correctly sent, a
`payload_version` is added (version 1: the body has already been
pre-process / version 2: the body is the raw event)

So future webhook additions will only have to deal with creating an
http.Request based on the raw event (no need to adjust the code in
multiple places, like currently).

Moreover since this processing happens when fetching from the task
queue, it ensures that the queuing of new events (upon a `git push` for
instance) does not get slowed down by a slow webhook.

As a concrete example, the PR #19307 for custom webhooks, should be
substantially smaller:
- no need to change `services/webhook/deliver.go`
- minimal change in `services/webhook/webhook.go` (add the new webhook
to the map)
- no need to change all the individual webhook files (since with this
refactor the `*webhook_model.Webhook` is provided as argument)

(cherry picked from commit 26653b196bd1d15c532af41f60351596dd4330bd)

Conflicts:
	services/webhook/deliver_test.go
	trivial context conflict
2024-03-11 23:36:59 +07:00
..
actions Add ac claim for old docker/build-push-action@v3 / current buildx gha cache (#29584) 2024-03-11 23:36:58 +07:00
agit Use the database object format name but not read from git repoisitory everytime and fix possible migration wrong objectformat when migrating a sha256 repository (#29294) 2024-02-26 22:30:26 +01:00
asymkey Simplify how git repositories are opened (#28937) 2024-01-27 21:09:51 +01:00
attachment Add support for API blob upload of release attachments (#29507) 2024-03-06 12:10:46 +08:00
auth remove util.OptionalBool and related functions (#29513) 2024-03-06 12:10:46 +08:00
automerge Simplify how git repositories are opened (#28937) 2024-01-27 21:09:51 +01:00
context Use strict protocol check when redirect (#29642) 2024-03-11 23:36:59 +07:00
contexttest Make "/user/login" page redirect if the current user has signed in (#29583) 2024-03-11 23:36:58 +07:00
convert Fix incorrect relative/absolute URL usages (#29531) 2024-03-06 12:10:46 +08:00
cron Refactor locale&string&template related code (#29165) 2024-02-16 15:20:52 +01:00
doctor [GITEA] new doctor check: fix-push-mirrors-without-git-remote (#1853) 2024-02-05 16:09:41 +01:00
externalaccount Final round of db.DefaultContext refactor (#27587) 2023-10-14 08:37:24 +00:00
feed More db.DefaultContext refactor (#27265) 2023-09-29 12:12:54 +00:00
forgejo [UPGRADE] run sanity checks before the database is upgraded 2024-02-05 14:44:33 +01:00
forms Add option to set language in admin user view (#28449) 2024-03-06 12:10:46 +08:00
gitdiff Fix incorrect diff expander for deletion of last lines in a file (#29501) 2024-03-06 12:10:45 +08:00
indexer Fix missing issue search index update when changing status (#28325) 2023-12-03 12:22:44 +01:00
issue Allow non-admin users to delete review requests (#29057) 2024-02-26 22:30:27 +01:00
lfs Move context from modules to services (#29440) 2024-03-06 12:10:43 +08:00
mailer Rename Str2html to SanitizeHTML and clarify its behavior (followup) 2024-03-06 12:10:45 +08:00
markup Move context from modules to services (#29440) 2024-03-06 12:10:43 +08:00
migrations remove util.OptionalBool and related functions (#29513) 2024-03-06 12:10:46 +08:00
mirror Simplify how git repositories are opened (#28937) 2024-01-27 21:09:51 +01:00
notify [GITEA] notifies admins on new user registration 2024-02-05 16:09:28 +01:00
org Delete repos of org when purge delete user (#27273) 2023-10-19 13:16:11 +00:00
packages remove util.OptionalBool and related functions (#29513) 2024-03-06 12:10:46 +08:00
pull remove util.OptionalBool and related functions (#29513) 2024-03-06 12:10:46 +08:00
release Use the database object format name but not read from git repoisitory everytime and fix possible migration wrong objectformat when migrating a sha256 repository (#29294) 2024-02-26 22:30:26 +01:00
repository Cache repository default branch commit status to reduce query on commit status table (#29444) 2024-03-11 23:36:58 +07:00
secrets Refactor deletion (#28610) 2023-12-25 21:25:29 +01:00
task Fix incorrect ctx usage in defer function (#27740) 2023-10-22 14:12:27 +00:00
uinotification Penultimate round of db.DefaultContext refactor (#27414) 2023-10-11 04:24:07 +00:00
user Skip email domain check when admins edit user emails (#29609) 2024-03-11 23:36:58 +07:00
webhook Store webhook event in database (#29145) 2024-03-11 23:36:59 +07:00
wiki [GITEA] Allow changing the repo Wiki branch to main 2024-02-05 16:57:47 +01:00