Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
fix: make enums non-exhaustive, add an error result
Lars Wirzenius committed 2 years ago
commit e2f352d68e54495077658a0dd610845e2e28c381
parent 53281dee849dbc3ad610ac6a648a3cdb3746bfba
2 files changed +17 -4
modified src/bin/ci-broker.rs
@@ -44,9 +44,10 @@ fn main() -> anyhow::Result<()> {
                BrokerEvent::RefChanged { rid, name: _, oid } => {
                    counter += 1;
                    let ret = match run(&bin, rid, oid)? {
-
                        None => "unknown",
-
                        Some(RunResult::Failure) => "FAILED",
-
                        Some(RunResult::Success) => "OK",
+
                        None => "unknown".into(),
+
                        Some(RunResult::Error(e)) => format!("ERROR: {}", e),
+
                        Some(RunResult::Failure) => "FAILED".into(),
+
                        Some(RunResult::Success) => "OK".into(),
                    };
                    println!("Run CI run #{}: {}, {} -> {}", counter, rid, oid, ret,);
                }
modified src/msg.rs
@@ -43,6 +43,7 @@ impl fmt::Display for RunId {
/// The result of a CI run.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
+
#[non_exhaustive]
pub enum RunResult {
    /// CI run was successful.
    #[serde(rename = "success")]
@@ -51,6 +52,10 @@ pub enum RunResult {
    /// CI run failed.
    #[serde(rename = "failure")]
    Failure,
+

+
    /// CI run has failed in a way external to the software under test.
+
    #[serde(rename = "error")]
+
    Error(String),
}

impl fmt::Display for RunResult {
@@ -58,6 +63,7 @@ impl fmt::Display for RunResult {
        match self {
            Self::Failure => write!(f, "failure"),
            Self::Success => write!(f, "success"),
+
            Self::Error(expl) => write!(f, "error: {}", expl),
        }
    }
}
@@ -65,6 +71,7 @@ impl fmt::Display for RunResult {
/// A request message sent by the broker to its adapter child process.
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "request")]
+
#[non_exhaustive]
pub enum Request {
    /// Trigger a run.
    #[serde(rename = "trigger")]
@@ -109,7 +116,7 @@ pub enum Response {
    #[serde(rename = "triggered")]
    Triggered { run_id: RunId },

-
    /// A Ci run has finished.
+
    /// A CI run has finished.
    #[serde(rename = "finished")]
    Finished { result: RunResult },
}
@@ -125,6 +132,11 @@ impl Response {
        Self::Finished { result }
    }

+
    /// Create a `Response::Error` message.
+
    pub fn error(explanation: &str) -> Self {
+
        Self::finished(RunResult::Error(explanation.into()))
+
    }
+

    /// Does the message indicate a result for the CI run?
    pub fn result(&self) -> Option<&RunResult> {
        if let Self::Finished { result } = self {