//! Turning a detected change into a scored candidate is one operation: //! `record`, so the watcher never has to know the order of review's writes. use crate::config::Config; use crate::db::{ self, model::{Recipe, ReleaseRow, SourceDigest}, Db, Pkgbase, }; use crate::error::Result; use crate::review::candidates::{self, NewCandidate, Upsert}; use crate::review::risk; /// Record a detected change as a candidate, scored. A change that collapsed or /// was already rejected is recorded as such and scored only if a row exists. pub fn record( db: &Db, cfg: &Config, pb: &Pkgbase, recipe: &Recipe, digests: &[SourceDigest], accepted: Option<&ReleaseRow>, nc: &NewCandidate, ) -> Result { let up = candidates::upsert_candidate(db, pb, accepted, nc)?; let id = match &up { Upsert::Created { id, .. } | Upsert::Collapsed { id, .. } | Upsert::Superseded { new: id, .. } => *id, // Nothing was written, so there is nothing to score. Upsert::PreviouslyRejected | Upsert::Unchanged => return Ok(up), }; // Scoring is advisory: a candidate that cannot be scored is still a // candidate, and a reviewer sees the diff either way. if let Ok(a) = risk::assess(db, cfg, recipe, digests, accepted) { let _ = db::candidates::set_risk(db, id, &a.level, &a.signals); } let _ = db::candidates::set_missing_deps(db, id, &missing_deps(db, pb, recipe)); Ok(up) } /// Dependencies we build ourselves but have not published yet, so a build that /// would fail on one says so before it runs. fn missing_deps(db: &Db, pb: &Pkgbase, recipe: &Recipe) -> Vec { let Ok(ours) = db::our_package_names(db) else { return Vec::new() }; let mut out = Vec::new(); for dep in crate::pkgver::dep_names(&recipe.depends) { if ours.contains(&dep) || dep == pb.name || recipe.pkgnames.contains(&dep) { continue; } let ours_to_publish = db::get_subscription(db, &dep).is_ok_and(|s| s.is_some()) || db::get_pkgbase(db, &dep).is_ok_and(|p| p.is_some()); if ours_to_publish { out.push(dep); } } out.sort(); out }