Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
refactor: use the message helper from radicle-ci-broker
Lars Wirzenius committed 1 year ago
commit 495ddf151837cde0a96131bc9afa23c0298704fe
parent 3ebc354
3 files changed +59 -60
modified src/engine.rs
@@ -4,6 +4,7 @@ use uuid::Uuid;

use radicle::prelude::Profile;
use radicle_ci_broker::msg::{
+
    helper::{read_request, write_failed, write_succeeded, write_triggered, NativeMessageError},
    EventCommonFields, Oid, Patch, PatchEvent, PushEvent, RepoId, Repository, Request, RunId,
    RunResult,
};
@@ -11,7 +12,6 @@ use radicle_ci_broker::msg::{
use crate::{
    config::{Config, ConfigError},
    logfile::{AdminLog, LogError},
-
    msg::{read_request, write_failed, write_succeeded, write_triggered, NativeMessageError},
    run::{Run, RunError},
    runlog::RunLogError,
    runspec::RunSpecError,
modified src/msg.rs
@@ -1,72 +1,72 @@
-
use std::path::PathBuf;
+
// use std::path::PathBuf;

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

-
use crate::{config::ConfigError, logfile::LogError, runspec::RunSpecError};
+
// use crate::{config::ConfigError, logfile::LogError, runspec::RunSpecError};

-
/// Read a request from stdin.
-
pub fn read_request() -> Result<Request, NativeMessageError> {
-
    let req = Request::from_reader(std::io::stdin()).map_err(NativeMessageError::ReadRequest)?;
-
    Ok(req)
-
}
+
// /// Read a request from stdin.
+
// pub fn read_request() -> Result<Request, NativeMessageError> {
+
//     let req = Request::from_reader(std::io::stdin()).map_err(NativeMessageError::ReadRequest)?;
+
//     Ok(req)
+
// }

-
// Write response to stdout.
-
fn write_response(resp: &Response) -> Result<(), NativeMessageError> {
-
    resp.to_writer(std::io::stdout())
-
        .map_err(|e| NativeMessageError::WriteResponse(resp.clone(), Box::new(e)))?;
-
    Ok(())
-
}
+
// // Write response to stdout.
+
// fn write_response(resp: &Response) -> Result<(), NativeMessageError> {
+
//     resp.to_writer(std::io::stdout())
+
//         .map_err(|e| NativeMessageError::WriteResponse(resp.clone(), Box::new(e)))?;
+
//     Ok(())
+
// }

-
/// Write a "triggered" response to stdout.
-
pub fn write_triggered(run_id: &RunId, info_url: Option<&str>) -> Result<(), NativeMessageError> {
-
    let response = if let Some(url) = info_url {
-
        Response::triggered_with_url(run_id.clone(), url)
-
    } else {
-
        Response::triggered(run_id.clone())
-
    };
-
    write_response(&response)?;
-
    Ok(())
-
}
+
// /// Write a "triggered" response to stdout.
+
// pub fn write_triggered(run_id: &RunId, info_url: Option<&str>) -> Result<(), NativeMessageError> {
+
//     let response = if let Some(url) = info_url {
+
//         Response::triggered_with_url(run_id.clone(), url)
+
//     } else {
+
//         Response::triggered(run_id.clone())
+
//     };
+
//     write_response(&response)?;
+
//     Ok(())
+
// }

-
/// Write a message indicating failure to stdout.
-
pub fn write_failed() -> Result<(), NativeMessageError> {
-
    write_response(&Response::Finished {
-
        result: RunResult::Failure,
-
    })?;
-
    Ok(())
-
}
+
// /// Write a message indicating failure to stdout.
+
// pub fn write_failed() -> Result<(), NativeMessageError> {
+
//     write_response(&Response::Finished {
+
//         result: RunResult::Failure,
+
//     })?;
+
//     Ok(())
+
// }

-
/// Write a message indicating success to stdout.
-
pub fn write_succeeded() -> Result<(), NativeMessageError> {
-
    write_response(&Response::Finished {
-
        result: RunResult::Success,
-
    })?;
-
    Ok(())
-
}
+
// /// Write a message indicating success to stdout.
+
// pub fn write_succeeded() -> Result<(), NativeMessageError> {
+
//     write_response(&Response::Finished {
+
//         result: RunResult::Success,
+
//     })?;
+
//     Ok(())
+
// }

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

-
    #[error("failed to write response to stdout: {0:?}")]
-
    WriteResponse(Response, #[source] Box<MessageError>),
+
//     #[error("failed to write response to stdout: {0:?}")]
+
//     WriteResponse(Response, #[source] Box<MessageError>),

-
    #[error("failed to create per-run parent directory {0}")]
-
    CreateState(PathBuf, #[source] std::io::Error),
+
//     #[error("failed to create per-run parent directory {0}")]
+
//     CreateState(PathBuf, #[source] std::io::Error),

-
    #[error("failed to create per-run directory {0}")]
-
    CreateRunDir(PathBuf, #[source] std::io::Error),
+
//     #[error("failed to create per-run directory {0}")]
+
//     CreateRunDir(PathBuf, #[source] std::io::Error),

-
    #[error("failed to load Radicle profile")]
-
    LoadProfile(#[source] radicle::profile::Error),
+
//     #[error("failed to load Radicle profile")]
+
//     LoadProfile(#[source] radicle::profile::Error),

-
    #[error(transparent)]
-
    Config(#[from] ConfigError),
+
//     #[error(transparent)]
+
//     Config(#[from] ConfigError),

-
    #[error(transparent)]
-
    Log(#[from] LogError),
+
//     #[error(transparent)]
+
//     Log(#[from] LogError),

-
    #[error(transparent)]
-
    RunSpec(#[from] RunSpecError),
-
}
+
//     #[error(transparent)]
+
//     RunSpec(#[from] RunSpecError),
+
// }
modified src/run.rs
@@ -4,10 +4,9 @@ use std::{
    time::SystemTime,
};

-
use radicle_ci_broker::msg::{Oid, RepoId, Request, RunId};
+
use radicle_ci_broker::msg::{helper::NativeMessageError, Oid, RepoId, Request, RunId};

use crate::{
-
    msg::NativeMessageError,
    runlog::{RunLog, RunLogError},
    runspec::{RunSpec, RunSpecError},
};