1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
use crate as config;

use std::collections::BTreeMap;

/// A notification receive from a Forge, typically via a Webhook.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, derive_more::Constructor)]
pub struct ForgeNotification {
    forge_alias: config::ForgeAlias,
    repo_alias: config::RepoAlias,
    headers: BTreeMap<String, String>,
    body: Body,
}
impl ForgeNotification {
    pub const fn forge_alias(&self) -> &config::ForgeAlias {
        &self.forge_alias
    }
    pub const fn repo_alias(&self) -> &config::RepoAlias {
        &self.repo_alias
    }
    pub const fn body(&self) -> &Body {
        &self.body
    }
    pub fn header(&self, header: &str) -> Option<String> {
        self.headers.get(header).map(|value| value.to_string())
    }
}

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, derive_more::Constructor)]
pub struct Body(String);
impl Body {
    pub fn as_str(&self) -> &str {
        self.0.as_str()
    }

    pub fn as_bytes(&self) -> &[u8] {
        self.0.as_bytes()
    }
}