Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
feat: add --show-config to write out configuration as JSON
Lars Wirzenius committed 1 year ago
commit 63fb66f46869303c1fce3483b2339e7c7499071a
parent 17acd1c
3 files changed +16 -0
modified src/bin/radicle-native-ci.rs
@@ -54,6 +54,10 @@ fn fallible_main() -> Result<bool, EngineError> {
        for arg in args.iter() {
            match arg.as_str() {
                "--version" => println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")),
+
                "--show-config" => {
+
                    let engine = Engine::new()?;
+
                    println!("{}", engine.config().as_json());
+
                }
                _ => {
                    eprintln!("unknown argument {arg}");
                    return Ok(false);
modified src/config.rs
@@ -50,6 +50,13 @@ impl Config {
    pub fn timeout(&self) -> usize {
        self.timeout.unwrap_or(DEFAULT_TIMEOUT)
    }
+

+
    /// Return configuration serialized to JSON.
+
    pub fn as_json(&self) -> String {
+
        // We don't check the result: we know a configuration can
+
        // always be serialized to JSON.
+
        serde_json::to_string_pretty(self).unwrap()
+
    }
}

#[derive(Debug, thiserror::Error)]
modified src/engine.rs
@@ -48,6 +48,11 @@ impl Engine {
        })
    }

+
    /// Return config that has been loaded for the engine.
+
    pub fn config(&self) -> &Config {
+
        &self.config
+
    }
+

    /// Set up and run CI on a project once: read the trigger request
    /// from stdin, write responses to stdout. Update node admin log
    /// with any problems that aren't inherent in the git repository