Skip to main content

ephemeris_forge_github/api/model/
webhooks.rs

1use facet::Facet;
2use facet_value::Value;
3
4/// A repository webhook as GitHub reports it.
5#[derive(Clone, Debug, Eq, Facet, PartialEq)]
6pub struct Webhook {
7    /// The id GitHub gave the webhook.
8    pub id: u64,
9    /// The hook type. Only `web` hooks are managed.
10    pub name: String,
11    /// Whether GitHub delivers events.
12    pub active: bool,
13    /// The events that trigger a delivery.
14    pub events: Vec<String>,
15    /// The delivery settings.
16    pub config: WebhookConfig,
17}
18
19/// The delivery settings of a webhook.
20#[derive(Clone, Debug, Eq, Facet, PartialEq)]
21pub struct WebhookConfig {
22    /// The delivery URL.
23    pub url: Option<String>,
24    /// The body format, `json` or `form`.
25    pub content_type: Option<String>,
26    /// GitHub reports this as the string "0" or "1", and sometimes as a number.
27    pub insecure_ssl: Option<Value>,
28    /// GitHub reports a set secret as a masked string and omits it otherwise.
29    pub secret: Option<String>,
30}
31
32impl WebhookConfig {
33    /// Whether TLS certificate checks are off.
34    #[must_use]
35    pub fn insecure(&self) -> bool {
36        self.insecure_ssl.as_ref().is_some_and(|value| {
37            value.as_string().map_or_else(
38                || {
39                    value
40                        .as_number()
41                        .and_then(facet_value::VNumber::to_i64)
42                        .is_some_and(|number| number == 1)
43                },
44                |text| text.as_str() == "1",
45            )
46        })
47    }
48}