use std::path::PathBuf;
use std::time::Instant;
use crate::commands::args::{ClassifyArgs, CollectArgs, ReportArgs};
use crate::commands::deployments::DeploymentsCollectArgs;
use crate::commands::incidents::IncidentsCollectArgs;
use crate::commands::jira::JiraSyncArgs;
use crate::commands::{classify, collect, deployments, dora, incidents, jira, pr_metrics, report};
use crate::commands::{dora::DoraArgs, pr_metrics::PrMetricsArgs};
use crate::core::config::Config;
use crate::core::db::Database;
use crate::core::progress::ProgressBus;
use super::stage::{AuditSweepStats, SweepStage};
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct SweepOptions {
pub output: Option<PathBuf>,
pub weeks: Option<u32>,
}
pub async fn run_full_sweep(
config: &Config,
db: &mut Database,
options: &SweepOptions,
progress: Option<&ProgressBus>,
) -> anyhow::Result<AuditSweepStats> {
let _ = progress;
if let Some(dir) = options.output.as_ref() {
std::fs::create_dir_all(dir)?;
}
let mut stats = AuditSweepStats::default();
let t = Instant::now();
let args = CollectArgs {
weeks: options.weeks,
allow_stale: true,
..CollectArgs::default()
};
stats.record(
SweepStage::Collect,
t,
collect::run(config.clone(), db, args).await,
);
let t = Instant::now();
let args = ClassifyArgs {
weeks: options.weeks,
..ClassifyArgs::default()
};
stats.record(
SweepStage::Classify,
t,
classify::run(config.clone(), db, args).await,
);
let t = Instant::now();
stats.record(
SweepStage::JiraSync,
t,
jira::run_sync(config.clone(), db, JiraSyncArgs::default()).await,
);
let t = Instant::now();
stats.record(
SweepStage::Deployments,
t,
deployments::run(config.clone(), db, DeploymentsCollectArgs::default()).await,
);
let t = Instant::now();
stats.record(
SweepStage::Incidents,
t,
incidents::run(config.clone(), db, IncidentsCollectArgs::default()),
);
let t = Instant::now();
stats.record(
SweepStage::Dora,
t,
dora::run(config.clone(), db, DoraArgs::default()),
);
let t = Instant::now();
let args = PrMetricsArgs {
weeks: options.weeks,
csv: true,
output: options.output.as_ref().map(|d| d.join("pr-metrics.csv")),
};
stats.record(
SweepStage::PrMetrics,
t,
pr_metrics::run(config.clone(), db, args),
);
let t = Instant::now();
let args = ReportArgs {
output: options.output.clone(),
..ReportArgs::default()
};
stats.record(SweepStage::Report, t, report::run(config.clone(), db, args));
tracing::info!(summary = %stats.summary(), "audit sweep finished");
Ok(stats)
}