You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitea/services
oliverpool 26653b196b
Store webhook event in database (#29145)
Refactor the webhook logic, to have the type-dependent processing happen
only in one place.

---

## Current webhook flow

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.

## Consequences of the refactor

- 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)
1 year ago
..
actions Add ac claim for old docker/build-push-action@v3 / current buildx gha cache (#29584) 1 year ago
agit A small refactor for agit implementation (#29614) 1 year ago
asymkey Move some asymkey functions to service layer (#28894) 1 year ago
attachment Add support for API blob upload of release attachments (#29507) 1 year ago
auth Move some asymkey functions to service layer (#28894) 1 year ago
automerge Simplify how git repositories are opened (#28937) 1 year ago
context Use strict protocol check when redirect (#29642) 1 year ago
contexttest Make "/user/login" page redirect if the current user has signed in (#29583) 1 year ago
convert Enable/disable owner and repo projects independently (#28805) 1 year ago
cron Move some asymkey functions to service layer (#28894) 1 year ago
doctor Move some asymkey functions to service layer (#28894) 1 year ago
externalaccount Revert "Support SAML authentication (#25165)" (#29358) 1 year ago
feed More `db.DefaultContext` refactor (#27265) 2 years ago
forms Make wiki default branch name changable (#29603) 1 year ago
gitdiff Fix incorrect diff expander for deletion of last lines in a file (#29501) 1 year ago
indexer Fix missing issue search index update when changing status (#28325) 1 year ago
issue Add missing database transaction for new issue (#29490) 1 year ago
lfs Move context from modules to services (#29440) 1 year ago
mailer Move context from modules to services (#29440) 1 year ago
markup Move context from modules to services (#29440) 1 year ago
migrations remove util.OptionalBool and related functions (#29513) 1 year ago
mirror Simplify how git repositories are opened (#28937) 1 year ago
notify Update status and code index after changing the default branch (#27018) 2 years ago
org Delete repos of org when purge delete user (#27273) 1 year ago
packages remove util.OptionalBool and related functions (#29513) 1 year ago
pull Add user blocking (#29028) 1 year ago
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) 1 year ago
repository Add download URL for executable files (#28260) 1 year ago
secrets Refactor deletion (#28610) 1 year ago
task Fix incorrect ctx usage in defer function (#27740) 1 year ago
uinotification Penultimate round of `db.DefaultContext` refactor (#27414) 1 year ago
user Skip email domain check when admins edit user emails (#29609) 1 year ago
webhook Store webhook event in database (#29145) 1 year ago
wiki Make wiki default branch name changable (#29603) 1 year ago