use self::commands::locate_failure_log;
use super::*;
pub mod github;
pub mod gitlab;
pub mod util;
#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumString, Display, ValueEnum)]
pub enum CIProvider {
#[value(name = "GitHub", alias = "github")]
GitHub,
#[value(name = "GitLab", alias = "gitlab")]
GitLab,
}
impl CIProvider {
fn env_is_github() -> bool {
env::var("GITHUB_ENV").is_ok()
}
fn env_is_gitlab() -> bool {
env::var("GITLAB_CI").is_ok()
}
pub fn from_enviroment() -> Result<Self> {
if Self::env_is_gitlab() {
Ok(Self::GitLab)
} else if Self::env_is_github() {
Ok(Self::GitHub)
} else {
bail!("Could not determine CI provider from environment")
}
}
pub async fn handle(&self, command: &commands::Command) -> Result<()> {
use commands::Command;
match command {
Command::LocateFailureLog { kind, input_file } => {
locate_failure_log::locate_failure_log(*kind, input_file.as_ref())
}
Command::CreateIssueFromRun {
repo,
run_id,
label,
kind,
title,
no_duplicate,
} => match self {
Self::GitHub => {
github::GitHub::get()
.create_issue_from_run(repo, run_id, label, kind, *no_duplicate, title)
.await
}
Self::GitLab => gitlab::GitLab::get().handle(command),
},
}
}
}