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
65
#[cfg(test)]
#[path = "./ci_test.rs"]
mod ci_test;
use crate::config;
use crate::types::{CiInfo, EnvValue, Vendor};
use envmnt;
fn validate(env_info: &EnvValue) -> bool {
match env_info {
EnvValue::Exists(ref key) => envmnt::exists(key),
EnvValue::AllExists(ref keys) => envmnt::is_all_exists(keys),
EnvValue::AnyExists(ref keys) => envmnt::is_any_exists(keys),
EnvValue::Value(ref key, ref value) => envmnt::is_equal(key, value),
EnvValue::NotEqual(ref key, ref value) => !envmnt::is_equal(key, value),
EnvValue::Contains(ref key, ref value) => envmnt::contains_ignore_case(key, value),
}
}
pub(crate) fn get() -> CiInfo {
let mut info = CiInfo::new();
let vendor_config_list = config::create();
for vendor_config in vendor_config_list.iter() {
let found = validate(&vendor_config.ci_env);
if found {
info.ci = true;
info.vendor = match vendor_config.vendor {
Vendor::Unknown => None,
_ => Some(vendor_config.vendor),
};
info.name = match vendor_config.vendor {
Vendor::Unknown => None,
_ => Some(vendor_config.name.clone()),
};
info.pr = match vendor_config.pr_env {
Some(ref env_value) => {
let is_pr = validate(env_value);
Some(is_pr)
}
None => None,
};
break;
}
}
info
}
pub(crate) fn is_ci() -> bool {
let info = get();
info.ci
}