summaryrefslogtreecommitdiffstats
path: root/src/watch
diff options
context:
space:
mode:
Diffstat (limited to 'src/watch')
-rw-r--r--src/watch/detect.rs32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/watch/detect.rs b/src/watch/detect.rs
index d5f5c46..084052f 100644
--- a/src/watch/detect.rs
+++ b/src/watch/detect.rs
@@ -184,10 +184,9 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result<CheckRepor
let Some(base) = accepted else {
// §7.1b: nothing to diff against — this is a first introduction.
- return match upsert_candidate(db, pb, None, &nc)? {
- Upsert::Created { id, kind } => Ok(report(Outcome::Candidate { id, kind })),
- other => Ok(report(outcome_of(other))),
- };
+ let up = upsert_candidate(db, pb, None, &nc)?;
+ score(db, cfg, pb, &recipe, &digests, None, candidate_id_of(&up));
+ return Ok(report(outcome_of(up)));
};
// Same identity as what we already serve: nothing happened.
@@ -221,9 +220,34 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result<CheckRepor
}
let up = upsert_candidate(db, pb, Some(&base), &nc)?;
+ score(db, cfg, pb, &recipe, &digests, Some(&base), candidate_id_of(&up));
Ok(report(outcome_of(up)))
}
+fn candidate_id_of(up: &Upsert) -> Option<i64> {
+ match up {
+ Upsert::Created { id, .. } | Upsert::Collapsed { id, .. } | Upsert::Superseded { new: id, .. } => Some(*id),
+ Upsert::PreviouslyRejected | Upsert::Unchanged => None,
+ }
+}
+
+/// Advisory risk scoring (§6). Best-effort: a scoring failure must never lose a
+/// candidate, so this logs rather than propagates.
+fn score(
+ db: &Db,
+ cfg: &Config,
+ pb: &Pkgbase,
+ recipe: &Recipe,
+ digests: &[SourceDigest],
+ accepted: Option<&ReleaseRow>,
+ candidate_id: Option<i64>,
+) {
+ let Some(id) = candidate_id else { return };
+ if let Ok(a) = crate::review::risk::assess(db, cfg, pb, recipe, digests, accepted) {
+ let _ = crate::review::candidates::set_risk(db, id, &a.level, &a.signals);
+ }
+}
+
fn outcome_of(up: Upsert) -> Outcome {
match up {
Upsert::Created { id, kind } => Outcome::Candidate { id, kind },