ci_manager/
ci_provider.rs1use self::commands::locate_failure_log;
2
3use super::*;
4
5pub mod github;
6pub mod gitlab;
7pub mod util;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumString, Display, ValueEnum)]
11pub enum CIProvider {
12 #[value(name = "GitHub", alias = "github")]
13 GitHub,
14 #[value(name = "GitLab", alias = "gitlab")]
15 GitLab,
16}
17
18impl CIProvider {
19 fn env_is_github() -> bool {
20 env::var("GITHUB_ENV").is_ok()
25 }
26 fn env_is_gitlab() -> bool {
27 env::var("GITLAB_CI").is_ok()
28 }
29
30 pub fn from_enviroment() -> Result<Self> {
31 if Self::env_is_gitlab() {
32 Ok(Self::GitLab)
33 } else if Self::env_is_github() {
34 Ok(Self::GitHub)
35 } else {
36 bail!("Could not determine CI provider from environment")
37 }
38 }
39
40 pub async fn handle(&self, command: &commands::Command) -> Result<()> {
41 use commands::Command;
42 match command {
43 Command::LocateFailureLog { kind, input_file } => {
45 locate_failure_log::locate_failure_log(*kind, input_file.as_ref())
46 }
47 Command::CreateIssueFromRun {
48 repo,
49 run_id,
50 label,
51 kind,
52 title,
53 no_duplicate,
54 } => match self {
55 Self::GitHub => {
56 github::GitHub::get()
57 .create_issue_from_run(repo, run_id, label, kind, *no_duplicate, title)
58 .await
59 }
60 Self::GitLab => gitlab::GitLab::get().handle(command),
61 },
62 }
63 }
64}