use super::types::CiEnvironment;
pub fn map_ci_environment(detected_name: &Option<String>) -> CiEnvironment {
match detected_name.as_deref() {
Some("GitHub Actions") => CiEnvironment::GitHubActions,
Some("GitLab CI") => CiEnvironment::GitLabCi,
Some(name) => CiEnvironment::Custom {
name: name.to_string(),
},
None => CiEnvironment::Unknown,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn detects_github_actions() {
let env = map_ci_environment(&Some("GitHub Actions".into()));
assert!(matches!(env, CiEnvironment::GitHubActions));
}
#[test]
fn detects_gitlab_ci() {
let env = map_ci_environment(&Some("GitLab CI".into()));
assert!(matches!(env, CiEnvironment::GitLabCi));
}
#[test]
fn detects_custom_ci() {
let env = map_ci_environment(&Some("Buildkite".into()));
assert!(matches!(env, CiEnvironment::Custom { name } if name == "Buildkite"));
}
#[test]
fn returns_unknown_for_none() {
let env = map_ci_environment(&None);
assert!(matches!(env, CiEnvironment::Unknown));
}
}