Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
feat: check that all adapters in triggers are defined
Lars Wirzenius committed 11 months ago
commit 5f203cd2d7435d975c594868bf73e788ddce61ff
parent b7dd71b
1 file changed +19 -1
modified src/config.rs
@@ -54,7 +54,21 @@ impl Config {
    pub fn load(filename: &Path) -> Result<Self, ConfigError> {
        let config =
            std::fs::read(filename).map_err(|e| ConfigError::ReadConfig(filename.into(), e))?;
-
        serde_yml::from_slice(&config).map_err(|e| ConfigError::ParseConfig(filename.into(), e))
+
        let config: Config = serde_yml::from_slice(&config)
+
            .map_err(|e| ConfigError::ParseConfig(filename.into(), e))?;
+
        config.check()?;
+
        Ok(config)
+
    }
+

+
    fn check(&self) -> Result<(), ConfigError> {
+
        if let Some(triggers) = &self.triggers {
+
            for trigger in triggers.iter() {
+
                if !self.adapters.contains_key(&trigger.adapter) {
+
                    return Err(ConfigError::UnknownAdapter(trigger.adapter.clone()));
+
                }
+
            }
+
        }
+
        Ok(())
    }

    pub fn report_dir(&self) -> Option<&Path> {
@@ -160,6 +174,10 @@ pub enum ConfigError {
    /// No default adapter.
    #[error("the default adapter is not defined in the configuration")]
    NoDefaultAdapter,
+

+
    /// Unknown adapter.
+
    #[error("'triggers' refers to adapter that hasn't been defined: {0}")]
+
    UnknownAdapter(String),
}

#[cfg(test)]