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
64
use std::collections::HashMap;
use std::fs;
use std::path::Path;
use serde::Deserialize;
use serde::Serialize;
use crate::types::ResultDynError;
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PhabConfig {
pub host: String,
pub api_token: String,
pub pkcs12_path: String,
pub pkcs12_password: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GhubConfig {
pub api_token: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DeploymentSchemeConfig {
pub name: String,
pub default_pull_request_title: String,
pub merge_from_branch: String,
pub merge_into_branch: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct RepositoryConfig {
pub key: String,
pub path: String,
pub github_path: String,
pub deployment_scheme_by_key: HashMap<String, DeploymentSchemeConfig>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DeploymentConfig {
pub repositories: Vec<RepositoryConfig>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BitlyConfig {
pub api_token: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Config {
pub phab: PhabConfig,
pub ghub: GhubConfig,
pub bitly: Option<BitlyConfig>,
pub deployment: DeploymentConfig,
}
impl Config {
pub fn new(setting_path: impl AsRef<Path>) -> ResultDynError<Config> {
let config_str = fs::read_to_string(setting_path)?;
let config: Config = serde_yaml::from_str(&config_str)?;
return Ok(config);
}
}