agent_hub_runtime/core/platforms/
mod.rs1pub mod accounts;
3pub(crate) mod cli;
4pub mod contracts;
5#[cfg(feature = "github")]
6pub(crate) mod github;
7#[cfg(feature = "gitlab")]
8pub(crate) mod gitlab;
9pub(crate) mod hosts;
10pub mod schedules;
11use crate::core::task_browser::{Provider, TaskFailure};
12impl Provider {
13 pub fn enabled(self) -> bool {
15 match self {
16 Self::Github => cfg!(feature = "github"),
17 Self::Gitlab => cfg!(feature = "gitlab"),
18 }
19 }
20 pub(crate) fn require(self) -> Result<(), TaskFailure> {
21 if self.enabled() {
22 Ok(())
23 } else {
24 Err(TaskFailure::new(
25 "feature_unavailable",
26 "This build does not include the selected hosting platform",
27 ))
28 }
29 }
30 pub(crate) fn cli(self) -> Result<&'static str, TaskFailure> {
31 self.require()?;
32 match self {
33 #[cfg(feature = "github")]
34 Self::Github => Ok(github::CLI),
35 #[cfg(feature = "gitlab")]
36 Self::Gitlab => Ok(gitlab::CLI),
37 #[cfg(not(feature = "github"))]
38 Self::Github => unreachable!(),
39 #[cfg(not(feature = "gitlab"))]
40 Self::Gitlab => unreachable!(),
41 }
42 }
43 pub(crate) fn login_name(self, user: &serde_json::Value) -> Option<&str> {
44 let _ = user;
45 match self {
46 #[cfg(feature = "github")]
47 Self::Github => github::login_name(user),
48 #[cfg(feature = "gitlab")]
49 Self::Gitlab => gitlab::login_name(user),
50 #[cfg(not(feature = "github"))]
51 Self::Github => None,
52 #[cfg(not(feature = "gitlab"))]
53 Self::Gitlab => None,
54 }
55 }
56}
57
58impl Provider {
59 pub(crate) fn account_adapter(self) -> Result<accounts::AccountAdapter, TaskFailure> {
60 self.require()?;
61 match self {
62 #[cfg(feature = "github")]
63 Self::Github => Ok(github::accounts::ADAPTER),
64 #[cfg(feature = "gitlab")]
65 Self::Gitlab => Ok(gitlab::accounts::ADAPTER),
66 #[cfg(not(feature = "github"))]
67 Self::Github => unreachable!(),
68 #[cfg(not(feature = "gitlab"))]
69 Self::Gitlab => unreachable!(),
70 }
71 }
72}