use serde::{Serialize, Serializer};
use crate::logs::{escape, escape_field};
mod logs;
mod next_steps;
mod outcome;
mod receipt;
mod receipts;
mod status;
mod steps;
pub use crate::receipt::markdown::{
code as markdown_code, fence as markdown_fence, inline as markdown_inline, render as markdown,
};
pub use logs::*;
pub use next_steps::{copy_is_safe, failed_step_options, NextStep, NextSteps, Part};
pub use outcome::{describe_plan, describe_steps_run, Badge, Flag, Outcome, OutcomeKind};
pub use receipt::{
receipt, receipt_at, ErrorGroup, ErrorVariant, ReceiptQueryError, ReceiptRecord, Smoke, Target,
Watch,
};
pub use receipts::{
checkout_receipts, receipts, CheckoutReceiptList, ReceiptList, ReceiptListRow, ReceiptSummary,
DEFAULT_RECEIPTS_LIMIT,
};
pub use status::{
env_order, status, AttemptSummary, CellRef, CodeState, EnvCell, Evidence, Mark, NewerElsewhere,
NotKnownReason, Problem, ProblemKind, RepoRow, StaleHint, Status,
};
pub use steps::{ConnectionGap, StepKind, StepRow, StepState};
pub const SCHEMA: u32 = 1;
#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord)]
pub struct Untrusted(String);
impl Untrusted {
pub fn new(text: impl Into<String>) -> Self {
Self(text.into())
}
pub fn raw(&self) -> &str {
&self.0
}
pub fn escaped(&self) -> String {
escape(&self.0)
}
pub fn field(&self) -> String {
escape_field(&self.0)
}
}
impl From<&str> for Untrusted {
fn from(text: &str) -> Self {
Self::new(text)
}
}
impl From<String> for Untrusted {
fn from(text: String) -> Self {
Self(text)
}
}
impl Serialize for Untrusted {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(&self.0)
}
}
#[derive(Debug, Serialize)]
pub struct Versioned<T> {
pub schema: u32,
#[serde(flatten)]
pub body: T,
}
#[derive(Debug, Serialize)]
pub struct ErrorBody<E> {
pub error: E,
}
pub fn versioned<T: Serialize>(body: T) -> Versioned<T> {
Versioned {
schema: SCHEMA,
body,
}
}
pub fn versioned_error<E: Serialize>(error: E) -> Versioned<ErrorBody<E>> {
versioned(ErrorBody { error })
}
#[cfg(test)]
mod tests;