ephemeris_forge_forgejo/api/request/
webhooks.rs1use std::collections::BTreeMap;
2
3use facet::Facet;
4
5use crate::config::{HookType, Webhook};
6
7#[derive(Clone, Debug, Eq, Facet, PartialEq)]
10pub struct CreateHookOption {
11 #[facet(rename = "type")]
13 pub kind: HookType,
14 pub config: BTreeMap<String, String>,
16 pub events: Vec<String>,
18 pub active: bool,
20 pub branch_filter: String,
22}
23
24#[derive(Clone, Debug, Default, Eq, Facet, PartialEq)]
30#[facet(skip_all_unless_truthy)]
31pub struct EditHookOption {
32 pub config: Option<BTreeMap<String, String>>,
34 pub events: Option<Vec<String>>,
36 pub active: Option<bool>,
38 pub branch_filter: Option<String>,
40 pub authorization_header: Option<String>,
42}
43
44impl EditHookOption {
45 #[must_use]
47 pub fn is_empty(&self) -> bool {
48 *self == Self::default()
49 }
50}
51
52impl CreateHookOption {
53 #[must_use]
55 pub fn new(url: &str, hook: &Webhook) -> Self {
56 Self {
57 kind: hook.kind,
58 config: BTreeMap::from([
59 ("url".to_owned(), url.to_owned()),
60 (
61 "content_type".to_owned(),
62 hook.content_type.as_str().to_owned(),
63 ),
64 ]),
65 events: hook.events.clone(),
66 active: hook.active,
67 branch_filter: hook.branch_filter.clone(),
68 }
69 }
70}