Skip to main content

sloop/sources/
mod.rs

1//! Authored ticket and flow definitions live in sources. Sloop borrows them
2//! into its derived index: `post` validates a Markdown push against its author,
3//! while `pull` keeps invalid tickets visible and held when they are upserted.
4
5use std::fmt;
6use std::path::PathBuf;
7
8use crate::flow::Flow;
9use crate::frontmatter::Frontmatter;
10use crate::outcome::Outcome;
11
12pub mod exec;
13pub mod markdown;
14
15#[derive(Debug, Clone)]
16pub struct AuthoredTicket {
17    pub frontmatter: Frontmatter,
18    pub body: String,
19    pub source: String,
20    pub source_ref: String,
21    pub file_path: Option<PathBuf>,
22    pub original_content: Option<String>,
23    pub validation_error: Option<String>,
24}
25
26pub trait TicketSource: Send + Sync {
27    fn pull(&self) -> Result<Vec<AuthoredTicket>, SourceError>;
28    fn report(&self, ticket_id: &str, outcome: &Outcome) -> Result<(), SourceError>;
29}
30
31pub trait FlowSource {
32    fn pull(&self) -> Result<Vec<Flow>, SourceError>;
33}
34
35#[derive(Debug, Clone, PartialEq, Eq)]
36pub struct SourceError(String);
37
38impl SourceError {
39    pub fn new(message: impl Into<String>) -> Self {
40        Self(message.into())
41    }
42}
43
44impl fmt::Display for SourceError {
45    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
46        formatter.write_str(&self.0)
47    }
48}
49
50impl std::error::Error for SourceError {}