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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Client configuration
use std::path::PathBuf;

use tini::Ini;

#[derive(Clone, Serialize, Deserialize)]
pub struct Author {
    pub name: String,
    pub email: Option<String>,
}

use std::fmt::Display;
impl Display for Author {
    fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
        write!(fmt, "{}", self.name)?;
        match self.email {
            Some(ref email) => write!(fmt, " <{}>", email),
            None => Ok(())
        }
    }
}

impl Author {
    pub fn from_gitconfig(path: PathBuf) -> Option<Author> {
        let gitconfig = Ini::from_file(&path).ok()?;
        let name = gitconfig.get("user", "name")?;
        let email = Some(gitconfig.get("user", "email")?);
        Some(Author {
            name,
            email
        })
    }
}

use std::collections::HashMap;
#[derive(Default, Serialize, Deserialize)]
pub struct JMESPathConfig {
    #[serde(default)]
    pub filters: HashMap<String, String>,
    #[serde(default)]
    pub queries: HashMap<String, String>,
}

#[derive(Default, Serialize, Deserialize)]
pub struct Signing {
    #[serde(default)]
    pub enabled: bool,
    #[serde(default)]
    pub key: Option<String>,
    #[serde(default)]
    pub gnupg: Option<String>,
}

#[derive(Serialize, Deserialize)]
pub struct Configuration {
    pub author: Option<Author>,
    #[serde(default)]
    pub issues: JMESPathConfig,
    #[serde(default)]
    pub records: JMESPathConfig,
    #[serde(default)]
    pub signing: Signing,
}