cartulary 0.3.0-alpha.1

The knowledge layer of your project — decisions, issues, docs, all in one place.
Documentation
//! Check the per-issue event log against the configured workflow.

use crate::domain::model::check::{validate_event_chain, CheckViolationKind, Severity};
use crate::domain::usecases::check::{CheckViolation, IssueCheckCtx, IssueFinding, IssueRule};

pub struct EventLogIntegrityRule;

pub const RULE_ID: &str = "issue/event-log-integrity";

impl IssueRule for EventLogIntegrityRule {
    fn id(&self) -> &'static str {
        RULE_ID
    }

    fn find(&self, ctx: &IssueCheckCtx<'_>) -> anyhow::Result<Vec<IssueFinding>> {
        let mut out = Vec::new();
        for (path, issue) in ctx.issues {
            for cause in validate_event_chain(&issue.events, issue.status.as_str(), ctx.statuses) {
                let kind = CheckViolationKind::EventLogBroken { cause };
                out.push(CheckViolation {
                    rule_id: RULE_ID,
                    path: path.clone(),
                    severity: Severity::Error,
                    kind,
                });
            }
        }
        Ok(out.into_iter().map(IssueFinding::report).collect())
    }
}