Skip to main content

Module webhooks

Module webhooks 

Source
Expand description

Outgoing event webhooks: administration and the events.

Administrators register webhooks (URL, events, optional project group). The services call emit inside the transaction of the event, which writes one delivery per matching active webhook into the outbox webhook_deliveries; crate::webhooks sends them. A rolled back event leaves no delivery behind.

Every payload has the same envelope – event, id (one per event, the same for every webhook), occurred_at, actor.username, instance – plus the objects of the event (revision, change, change_request, …) with their identifiers, web_url and api_url. File contents and secrets are never part of a payload.

EventEmitted byObjects
revision.releasedthe last approval of a change, per revisionrevision, change
revision.obsoletedmarking a released revision obsoleterevision
change.submittedsubmitting a change for reviewchange, revisions
change.approvedevery approval of a reviewerchange, review, revisions
change.rejecteda reviewer’s rejection (rejects the change)change, review, revisions
change.releasedthe last approvalchange, revisions
change_request.createdraising a change requestchange_request, items
change_request.decidedaccepting, rejecting or deferring a requestchange_request, decision
simulation.result_addedadding or importing simulation result valuesrevision, result or import

Structs§

Delivery
One entry of the outbox.
Webhook
A webhook as shown to administrators – without its secret.
WebhookInput
What an administrator enters.

Constants§

MAX_WEBHOOKS
Most webhooks of one instance.
SECRET_PREFIX
Prefix of generated webhook secrets.

Functions§

change_object
A change in a payload. status is the status after the event.
create
Registers a webhook. Returns it and its secret – the only time the secret leaves the server.
delete
Deletes a webhook together with its deliveries.
deliveries
The latest deliveries of a webhook, newest first.
emit
Queues an event for every active webhook that subscribed to it and whose project group (if any) is one of projects. Call it inside the event’s transaction. Returns the number of deliveries queued.
get
get_delivery
list
payload
Builds the payload of an event: the envelope plus objects (a JSON object whose keys are added at the top level).
request_object
A change request in a payload (with its current status).
retry
Schedules a failed (or waiting) delivery again, now, with a fresh set of attempts. The delivery id stays the same, so receivers can deduplicate.
revision_object
A revision in a payload. state is the state after the event.
rotate_secret
Replaces the secret. Returns the webhook and the new secret (shown once). Deliveries that are still pending are signed with the new secret.
send_test
Queues a ping delivery to an active webhook; returns its id (the caller may send it at once with Dispatcher::deliver_now).
update
Changes name, URL, events, project group and the active flag. Pending deliveries of a webhook that is switched off are given up.