ephemeris_forge_forgejo/config/webhooks.rs
1use std::collections::BTreeMap;
2
3use ephemeris_forge::{Mode, WebhookContentType};
4use facet::Facet;
5
6ephemeris_forge::string_enum! {
7 /// The kind of a webhook, as the spec's `CreateHookOption` lists it.
8 pub enum HookType("hook type") {
9 /// A Forgejo hook.
10 Forgejo = "forgejo",
11 /// A dingtalk hook.
12 Dingtalk = "dingtalk",
13 /// A Discord hook.
14 Discord = "discord",
15 /// A Gitea hook.
16 Gitea = "gitea",
17 /// A Gogs hook.
18 Gogs = "gogs",
19 /// A Microsoft Teams hook.
20 Msteams = "msteams",
21 /// A Slack hook.
22 Slack = "slack",
23 /// A Telegram hook.
24 Telegram = "telegram",
25 /// A Feishu hook.
26 Feishu = "feishu",
27 /// A wechatwork hook.
28 Wechatwork = "wechatwork",
29 /// A Packagist hook.
30 Packagist = "packagist",
31 }
32}
33
34/// Desired settings of one webhook. The delivery URL is its key.
35///
36/// The secret and the authorization header are never managed.
37#[derive(Clone, Debug, Eq, Facet, PartialEq)]
38#[facet(deny_unknown_fields)]
39pub struct Webhook {
40 /// The kind of hook. Forgejo cannot change it, so a change recreates the
41 /// hook.
42 #[facet(rename = "type")]
43 pub kind: HookType,
44 /// The body format of a delivery.
45 pub content_type: WebhookContentType,
46 /// The events that trigger a delivery.
47 pub events: Vec<String>,
48 /// Whether Forgejo delivers events.
49 pub active: bool,
50 /// The glob of branches that trigger push events.
51 pub branch_filter: String,
52}
53
54/// Desired webhooks of a repository.
55#[derive(Clone, Debug, Eq, Facet, PartialEq)]
56#[facet(deny_unknown_fields)]
57pub struct Webhooks {
58 /// Whether webhooks that are not declared are deleted.
59 pub mode: Mode,
60 /// The webhooks keyed by delivery URL.
61 pub webhooks: BTreeMap<String, Webhook>,
62}