mirror of
https://seed.radicle.dev/rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE.git
synced 2026-11-15 16:00:39 +08:00
The CI broker produces reports now. Signed-off-by: Lars Wirzenius <liw@liw.fi>
81 lines
2.3 KiB
Rust
81 lines
2.3 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use radicle_ci_broker::msg::{MessageError, Request, Response, RunId, RunResult};
|
|
|
|
use crate::{config::ConfigError, logfile::LogError, runinfo::RunInfoError, 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)
|
|
}
|
|
|
|
// Write response to stdout.
|
|
fn write_response(resp: &Response) -> Result<(), NativeMessageError> {
|
|
resp.to_writer(std::io::stdout())
|
|
.map_err(|e| NativeMessageError::WriteResponse(resp.clone(), e))?;
|
|
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(())
|
|
}
|
|
|
|
/// 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 error to stdout.
|
|
pub fn write_errored(s: &str) -> Result<(), NativeMessageError> {
|
|
write_response(&Response::Finished {
|
|
result: RunResult::Error(s.into()),
|
|
})?;
|
|
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),
|
|
|
|
#[error("failed to write response to stdout: {0:?}")]
|
|
WriteResponse(Response, #[source] MessageError),
|
|
|
|
#[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 load Radicle profile")]
|
|
LoadProfile(#[source] radicle::profile::Error),
|
|
|
|
#[error(transparent)]
|
|
Config(#[from] ConfigError),
|
|
|
|
#[error(transparent)]
|
|
Log(#[from] LogError),
|
|
|
|
#[error(transparent)]
|
|
RunInfo(#[from] RunInfoError),
|
|
|
|
#[error(transparent)]
|
|
RunSpec(#[from] RunSpecError),
|
|
}
|