feat: add rust actions
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
49
crates/cuddle-please-actions/src/config.rs
Normal file
49
crates/cuddle-please-actions/src/config.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use std::ops::Deref;
|
||||
|
||||
use anyhow::Context;
|
||||
|
||||
pub enum ActionConfig {
|
||||
Actual { doc: yaml_rust2::Yaml },
|
||||
None,
|
||||
}
|
||||
|
||||
impl Deref for ActionConfig {
|
||||
type Target = yaml_rust2::Yaml;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
match &self {
|
||||
ActionConfig::Actual { doc } => doc,
|
||||
ActionConfig::None => &yaml_rust2::Yaml::BadValue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for ActionConfig {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
let mut cuddle = yaml_rust2::YamlLoader::load_from_str(value)?;
|
||||
|
||||
if cuddle.len() != 1 {
|
||||
anyhow::bail!("cuddle.yaml can only be 1 document wide");
|
||||
}
|
||||
|
||||
let doc = cuddle.pop().unwrap();
|
||||
let doc = doc["please"]["actions"].clone();
|
||||
|
||||
if doc.is_badvalue() {
|
||||
return Ok(Self::None);
|
||||
}
|
||||
|
||||
Ok(Self::Actual { doc })
|
||||
}
|
||||
}
|
||||
|
||||
impl ActionConfig {
|
||||
pub fn parse() -> anyhow::Result<Self> {
|
||||
let cuddle_yaml =
|
||||
std::fs::read_to_string("cuddle.yaml").context("failed to read cuddle.yaml")?;
|
||||
|
||||
Self::try_from(cuddle_yaml.as_str())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user