perfgate 0.17.0

Core library for perfgate performance budgets and baseline diffs
Documentation
use crate::domain::BinaryBlame;
use anyhow::Context;
use std::fs;
use std::path::PathBuf;

pub struct BlameRequest {
    pub baseline_lock: PathBuf,
    pub current_lock: PathBuf,
}

pub struct BlameOutcome {
    pub blame: BinaryBlame,
}

pub struct BlameUseCase;

impl BlameUseCase {
    pub fn execute(&self, req: BlameRequest) -> anyhow::Result<BlameOutcome> {
        let baseline_content = fs::read_to_string(&req.baseline_lock)
            .with_context(|| format!("failed to read baseline lockfile {:?}", req.baseline_lock))?;
        let current_content = fs::read_to_string(&req.current_lock)
            .with_context(|| format!("failed to read current lockfile {:?}", req.current_lock))?;

        let blame = crate::domain::compare_lockfiles(&baseline_content, &current_content);

        Ok(BlameOutcome { blame })
    }
}