Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
refactor: add helper function to send "triggered" message
Lars Wirzenius committed 2 years ago
commit 32486e825442778f5fbbf0c9a9c3432c36eb6461
parent a0aee4d
2 files changed +11 -5
modified src/bin/radicle-native-ci.rs
@@ -26,7 +26,7 @@ use radicle_ci_broker::msg::{Id, Oid, Request, Response, RunId, RunResult};
use radicle_native_ci::{
    config::{Config, ConfigError},
    logfile::{LogError, LogFile},
-
    msg::{read_request, write_response, NativeMessageError},
+
    msg::{read_request, write_response, write_triggered, NativeMessageError},
    report,
    runcmd::{runcmd, RunCmdError},
    runinfo::{RunInfo, RunInfoBuilder, RunInfoError},
@@ -190,9 +190,7 @@ impl<'a> Runner<'a> {
        self.run_log(format!("* Repository id: `{}`\n", self.repo))?;
        self.run_log(format!("* Commit: `{}`\n\n", self.commit))?;

-
        write_response(&Response::triggered(RunId::from(
-
            self.run_id.to_string().as_str(),
-
        )))?;
+
        write_triggered(&self.run_id)?;

        let repo_path = self.storage.join(self.repo.canonical());
        debug!("repo path: {}", repo_path.display());
modified src/msg.rs
@@ -2,7 +2,7 @@ use std::path::PathBuf;

use log::{debug, error};

-
use radicle_ci_broker::msg::{MessageError, Request, Response};
+
use radicle_ci_broker::msg::{MessageError, Request, Response, RunId};

use crate::{
    config::ConfigError, logfile::LogError, report, runcmd::RunCmdError, runinfo::RunInfoError,
@@ -23,6 +23,14 @@ pub fn write_response(resp: &Response) -> Result<(), NativeMessageError> {
    Ok(())
}

+
/// Write a "triggered" response to stdout.
+
pub fn write_triggered(run_id: &RunId) -> Result<(), NativeMessageError> {
+
    write_response(&Response::triggered(RunId::from(
+
        run_id.to_string().as_str(),
+
    )))?;
+
    Ok(())
+
}
+

#[derive(Debug, thiserror::Error)]
pub enum NativeMessageError {
    #[error("failed to read request from stdin: {0:?}")]