diff options
Diffstat (limited to 'src/review')
| -rw-r--r-- | src/review/approve.rs | 121 | ||||
| -rw-r--r-- | src/review/candidates.rs | 14 | ||||
| -rw-r--r-- | src/review/diff.rs | 124 | ||||
| -rw-r--r-- | src/review/intake.rs | 17 | ||||
| -rw-r--r-- | src/review/risk.rs | 30 |
5 files changed, 178 insertions, 128 deletions
diff --git a/src/review/approve.rs b/src/review/approve.rs index c5b2f07..26963d6 100644 --- a/src/review/approve.rs +++ b/src/review/approve.rs @@ -1,4 +1,4 @@ -use crate::db::{self, approvals, candidates, CandidateState, *}; +use crate::db::{self, approvals, candidates, CandidateRow, CandidateState, Db}; use crate::error::{Error, Missing, Refused, Result}; use crate::time; @@ -43,64 +43,68 @@ pub fn approve( let actor = actor.to_string(); let ih = identity_hash.to_string(); let dd = diff_digest.to_string(); - let note = note.map(|s| s.to_string()); + let note = note.map(std::string::ToString::to_string); let at = time::now(); - db.writer.tx(move |tx| -> Result<std::result::Result<Approval, ApproveError>> { - let subject = candidates::review_subject_in(tx, candidate_id)? - .ok_or_else(|| Error::not_found(Missing::Candidate(candidate_id)))?; - let id = subject.id; - let base = subject.base_release_id; - let current_base = subject.current_base_release_id; + db.writer + .tx(move |tx| -> Result<std::result::Result<Approval, ApproveError>> { + let subject = candidates::review_subject_in(tx, candidate_id)? + .ok_or_else(|| Error::not_found(Missing::Candidate(candidate_id)))?; + let id = subject.id; + let base = subject.base_release_id; + let current_base = subject.current_base_release_id; - if !subject.state.is_open() { - return Ok(Err(ApproveError::Stale(Stale::NotPending { state: subject.state.to_string() }))); - } - if subject.identity_hash != ih { - return Ok(Err(ApproveError::Stale(Stale::Identity { expected: ih.clone(), actual: subject.identity_hash }))); - } - if subject.diff_digest != dd { - return Ok(Err(ApproveError::Stale(Stale::Diff { expected: dd.clone(), actual: subject.diff_digest }))); - } - if base != current_base { - return Ok(Err(ApproveError::Stale(Stale::Base { expected: base, actual: current_base }))); - } + if !subject.state.is_open() { + return Ok(Err(ApproveError::Stale(Stale::NotPending { state: subject.state.to_string() }))); + } + if subject.identity_hash != ih { + return Ok(Err(ApproveError::Stale(Stale::Identity { + expected: ih.clone(), + actual: subject.identity_hash, + }))); + } + if subject.diff_digest != dd { + return Ok(Err(ApproveError::Stale(Stale::Diff { expected: dd.clone(), actual: subject.diff_digest }))); + } + if base != current_base { + return Ok(Err(ApproveError::Stale(Stale::Base { expected: base, actual: current_base }))); + } - let approval_id = approvals::record_in( - tx, - &approvals::Decision { + let approval_id = approvals::record_in( + tx, + &approvals::Decision { + candidate_id: id, + base_release_id: base, + at: &at, + decision: "approved", + risk_level: &subject.risk_level, + diff_digest: &dd, + identity_hash: &ih, + note: note.as_deref(), + }, + )?; + candidates::resolve_in(tx, id, CandidateState::Approved, &at)?; + db::audit_in( + tx, + &db::AuditEntry::human( + &at, + &actor, + "approve", + "candidate", + &id.to_string(), + serde_json::json!({"approval": approval_id, "identity": ih, "pkgbase_id": subject.pkgbase_id}), + ), + )?; + Ok(Ok(Approval { + id: approval_id, candidate_id: id, base_release_id: base, - at: &at, - decision: "approved", - risk_level: &subject.risk_level, - diff_digest: &dd, - identity_hash: &ih, - note: note.as_deref(), - }, - )?; - candidates::resolve_in(tx, id, CandidateState::Approved, &at)?; - db::audit_in( - tx, - &db::AuditEntry::human( - &at, - &actor, - "approve", - "candidate", - &id.to_string(), - serde_json::json!({"approval": approval_id, "identity": ih, "pkgbase_id": subject.pkgbase_id}), - ), - )?; - Ok(Ok(Approval { - id: approval_id, - candidate_id: id, - base_release_id: base, - decision: "approved".into(), - diff_digest: dd, - identity_hash: ih, - })) - }) - .map_err(ApproveError::System)? + decision: "approved".into(), + diff_digest: dd, + identity_hash: ih, + })) + }) + .map_err(ApproveError::System)? } pub fn reject(db: &Db, actor: &str, candidate_id: i64, note: &str) -> Result<()> { @@ -111,7 +115,12 @@ pub fn reject(db: &Db, actor: &str, candidate_id: i64, note: &str) -> Result<()> let state = candidates::state_in(tx, candidate_id)? .ok_or_else(|| Error::not_found(Missing::Candidate(candidate_id)))?; if !state.is_open() { - return Err(Error::conflict(Refused::WrongState { entity: "candidate", id: candidate_id.to_string(), found: state.to_string(), expected: "pending" })); + return Err(Error::conflict(Refused::WrongState { + entity: "candidate", + id: candidate_id.to_string(), + found: state.to_string(), + expected: "pending", + })); } let identity = candidates::identity_in(tx, candidate_id)? .ok_or_else(|| Error::not_found(Missing::Candidate(candidate_id)))?; @@ -141,7 +150,7 @@ pub struct BulkItem { impl BulkItem { pub fn pkgbase(&self) -> &str { - self.candidate.as_ref().map(|c| c.pkgbase.as_str()).unwrap_or("(gone)") + self.candidate.as_ref().map_or("(gone)", |c| c.pkgbase.as_str()) } } @@ -157,7 +166,7 @@ pub enum BulkOutcome { /// only way to reach it, and the alias is what carries the /// feature-conditional visibility. mod bulk_refusal { - use super::*; + use super::{Error, Stale}; #[derive(Debug, thiserror::Error)] pub enum BulkRefusal { diff --git a/src/review/candidates.rs b/src/review/candidates.rs index 236f85b..f90b1ef 100644 --- a/src/review/candidates.rs +++ b/src/review/candidates.rs @@ -2,8 +2,8 @@ use crate::db::{self, candidates as sql, Db, Pkgbase, ReleaseRow}; use crate::error::Result; pub use crate::db::candidates::{ - all as all_candidates, by_id as candidate_by_id, mark_viewed, pending as pending_candidates, - set_diff_digest, NewCandidate, + all as all_candidates, by_id as candidate_by_id, mark_viewed, pending as pending_candidates, set_diff_digest, + NewCandidate, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -15,8 +15,14 @@ pub enum Upsert { Unchanged, } -pub(crate) fn upsert_candidate(db: &Db, pb: &Pkgbase, accepted: Option<&ReleaseRow>, nc: &NewCandidate) -> Result<Upsert> { - let kind = if accepted.is_some() { db::candidate_kind::NEW_VERSION } else { db::candidate_kind::FIRST_INTRODUCTION }; +pub(crate) fn upsert_candidate( + db: &Db, + pb: &Pkgbase, + accepted: Option<&ReleaseRow>, + nc: &NewCandidate, +) -> Result<Upsert> { + let kind = + if accepted.is_some() { db::candidate_kind::NEW_VERSION } else { db::candidate_kind::FIRST_INTRODUCTION }; let base = accepted.map(|a| a.id); let pkgbase_id = pb.id; let nc = nc.clone(); diff --git a/src/review/diff.rs b/src/review/diff.rs index 39d9066..f997b3c 100644 --- a/src/review/diff.rs +++ b/src/review/diff.rs @@ -1,7 +1,8 @@ use crate::config::Config; -use crate::db::{self, *}; +use crate::db::{self, CandidateRow, Db, Recipe, ReleaseRow, SourceDigest, UpstreamPin}; use crate::error::Result; use crate::git; +use std::fmt::Write as _; #[derive(Debug, Clone)] pub struct Panel { @@ -31,9 +32,7 @@ pub fn panels(cfg: &Config, db: &Db, c: &CandidateRow, base: Option<&ReleaseRow> } out.push(digest_delta(base, c)); out.push(pin_delta(base, c)); - let old_recipe = recipe_of(db, base.candidate_id.and_then(|cid| { - candidate_snapshot_id(db, cid) - })); + let old_recipe = recipe_of(db, base.candidate_id.and_then(|cid| candidate_snapshot_id(db, cid))); let new_recipe = recipe_of(db, Some(c.snapshot_id)); if let (Some(old), Some(new)) = (&old_recipe, &new_recipe) { out.push(source_delta(old, new)); @@ -45,9 +44,7 @@ pub fn panels(cfg: &Config, db: &Db, c: &CandidateRow, base: Option<&ReleaseRow> out.push(Panel { name: "recipe_full", title: "Full recipe", - body: snap - .map(|s| s.srcinfo_json.clone()) - .unwrap_or_else(|| "(no snapshot)".into()), + body: snap.map_or_else(|| "(no snapshot)".into(), |s| s.srcinfo_json.clone()), }); } Ok(out) @@ -67,27 +64,27 @@ fn source_delta(old: &Recipe, new: &Recipe) -> Panel { let mut body = String::new(); for s in &new.source { if !old.source.contains(s) { - body.push_str(&format!("+ {s}\n")); + let _ = writeln!(body, "+ {s}"); } } for s in &old.source { if !new.source.contains(s) { - body.push_str(&format!("- {s}\n")); + let _ = writeln!(body, "- {s}"); } } let old_hosts = crate::urlutil::hosts(&old.source); let new_hosts = crate::urlutil::hosts(&new.source); for h in new_hosts.difference(&old_hosts) { - body.push_str(&format!("! new source host: {h}\n")); + let _ = writeln!(body, "! new source host: {h}"); } for h in old_hosts.difference(&new_hosts) { - body.push_str(&format!("! source host gone: {h}\n")); + let _ = writeln!(body, "! source host gone: {h}"); } for (i, sum) in new.sha256sums.iter().enumerate() { if sum.eq_ignore_ascii_case("SKIP") { match old.sha256sums.get(i) { Some(prev) if prev != "SKIP" && !prev.is_empty() => { - body.push_str(&format!("! [{i}] checksum removed (was {prev}, now SKIP)\n")) + let _ = writeln!(body, "! [{i}] checksum removed (was {prev}, now SKIP)"); } _ => {} } @@ -115,10 +112,10 @@ fn dependency_delta(old: &Recipe, new: &Recipe) -> Panel { let oset: std::collections::BTreeSet<String> = crate::pkgver::dep_names(o).into_iter().collect(); let nset: std::collections::BTreeSet<String> = crate::pkgver::dep_names(n).into_iter().collect(); for d in nset.difference(&oset) { - body.push_str(&format!("+ {label}: {d}\n")); + let _ = writeln!(body, "+ {label}: {d}"); } for d in oset.difference(&nset) { - body.push_str(&format!("- {label}: {d}\n")); + let _ = writeln!(body, "- {label}: {d}"); } } if !old.checkdepends.is_empty() && new.checkdepends.is_empty() { @@ -131,34 +128,34 @@ fn build_env_delta(old: &Recipe, new: &Recipe) -> Panel { let mut body = String::new(); for o in &new.options { if !old.options.contains(o) { - body.push_str(&format!("+ options: {o}\n")); + let _ = writeln!(body, "+ options: {o}"); } } for o in &old.options { if !new.options.contains(o) { - body.push_str(&format!("- options: {o}\n")); + let _ = writeln!(body, "- options: {o}"); } } for a in &new.arch { if !old.arch.contains(a) { - body.push_str(&format!("+ arch: {a}\n")); + let _ = writeln!(body, "+ arch: {a}"); } } for a in &old.arch { if !new.arch.contains(a) { - body.push_str(&format!("- arch: {a}\n")); + let _ = writeln!(body, "- arch: {a}"); } } if old.pkgbase != new.pkgbase { - body.push_str(&format!("! pkgbase renamed: {} -> {}\n", old.pkgbase, new.pkgbase)); + let _ = writeln!(body, "! pkgbase renamed: {} -> {}", old.pkgbase, new.pkgbase); } let old_set: std::collections::BTreeSet<String> = old.pkgnames.iter().cloned().collect(); let new_set: std::collections::BTreeSet<String> = new.pkgnames.iter().cloned().collect(); for p in new_set.difference(&old_set) { - body.push_str(&format!("+ split package: {p}\n")); + let _ = writeln!(body, "+ split package: {p}"); } for p in old_set.difference(&new_set) { - body.push_str(&format!("- split package: {p}\n")); + let _ = writeln!(body, "- split package: {p}"); } Panel { name: "buildenv", title: "Build-env delta", body } } @@ -166,9 +163,15 @@ fn build_env_delta(old: &Recipe, new: &Recipe) -> Panel { fn install_delta(old: &Recipe, new: &Recipe) -> Panel { let mut body = String::new(); match (&old.install, &new.install) { - (None, Some(f)) => body.push_str(&format!("+ install script added: {f}\n")), - (Some(f), None) => body.push_str(&format!("- install script removed: {f}\n")), - (Some(a), Some(b)) if a != b => body.push_str(&format!("! install script changed: {a} -> {b}\n")), + (None, Some(f)) => { + let _ = writeln!(body, "+ install script added: {f}"); + } + (Some(f), None) => { + let _ = writeln!(body, "- install script removed: {f}"); + } + (Some(a), Some(b)) if a != b => { + let _ = writeln!(body, "! install script changed: {a} -> {b}"); + } _ => {} } if crate::recipe::bodies_changed(&old.pkgbuild, &new.pkgbuild) { @@ -182,18 +185,20 @@ fn version_delta(base: Option<&ReleaseRow>, c: &CandidateRow) -> Panel { match base { Some(b) => { let (bv, cv) = (b.version(), c.version()); - body.push_str(&format!("{bv} -> {cv}\n")); + let _ = writeln!(body, "{bv} -> {cv}"); if b.epoch != c.epoch { - body.push_str(&format!("epoch bump: {} -> {}\n", b.epoch, c.epoch)); + let _ = writeln!(body, "epoch bump: {} -> {}", b.epoch, c.epoch); } if b.pkgrel != c.pkgrel && b.pkgver == c.pkgver { - body.push_str(&format!("pkgrel change: {} -> {}\n", b.pkgrel, c.pkgrel)); + let _ = writeln!(body, "pkgrel change: {} -> {}", b.pkgrel, c.pkgrel); } if crate::pkgver::is_downgrade(&bv, &cv) { body.push_str("DOWNGRADE: AUR now offers a lower version than we serve\n"); } } - None => body.push_str(&format!("first introduction: {}\n", c.version())), + None => { + let _ = writeln!(body, "first introduction: {}", c.version()); + } } Panel { name: "version", title: "Version delta", body } } @@ -205,24 +210,32 @@ fn digest_delta(base: &ReleaseRow, c: &CandidateRow) -> Panel { for n in &new { match old.iter().find(|o| o.index == n.index) { Some(o) if o.digest != n.digest => { - body.push_str(&format!( - "! [{}] {} {} -> {}\n", - n.index, n.url, short(&o.digest), short(&n.digest) - )); + let _ = writeln!(body, "! [{}] {} {} -> {}", n.index, n.url, short(&o.digest), short(&n.digest)); + } + Some(_) => { + let _ = writeln!(body, " [{}] {} unchanged", n.index, n.url); + } + None => { + let _ = writeln!( + body, + "+ [{}] {} NEW ({}{})", + n.index, + n.url, + n.kind, + if n.skip_declared && !n.is_vcs() { + ", sha256sums=SKIP" + } else if n.is_vcs() { + ", pinned commit" + } else { + "" + } + ); } - Some(_) => body.push_str(&format!(" [{}] {} unchanged\n", n.index, n.url)), - None => body.push_str(&format!( - "+ [{}] {} NEW ({}{})\n", - n.index, - n.url, - n.kind, - if n.skip_declared && !n.is_vcs() { ", sha256sums=SKIP" } else if n.is_vcs() { ", pinned commit" } else { "" } - )), } } for o in &old { if !new.iter().any(|n| n.index == o.index) { - body.push_str(&format!("- [{}] {} REMOVED\n", o.index, o.url)); + let _ = writeln!(body, "- [{}] {} REMOVED", o.index, o.url); } } Panel { name: "digests", title: "Source digest delta", body } @@ -238,26 +251,39 @@ fn pin_delta(base: &ReleaseRow, c: &CandidateRow) -> Panel { for n in &new { match old.iter().find(|o| o.index == n.index) { Some(o) if o.commit != n.commit => { - body.push_str(&format!( - "! [{}] {} {} -> {} (branch {})\n", - n.index, n.url, short(&o.commit), short(&n.commit), n.branch.as_deref().unwrap_or("?") - )); + let _ = writeln!( + body, + "! [{}] {} {} -> {} (branch {})", + n.index, + n.url, + short(&o.commit), + short(&n.commit), + n.branch.as_deref().unwrap_or("?") + ); + } + Some(_) => { + let _ = writeln!(body, " [{}] {} unchanged", n.index, n.url); + } + None => { + let _ = writeln!(body, "+ [{}] {} at {}", n.index, n.url, short(&n.commit)); } - Some(_) => body.push_str(&format!(" [{}] {} unchanged\n", n.index, n.url)), - None => body.push_str(&format!("+ [{}] {} at {}\n", n.index, n.url, short(&n.commit))), } } Panel { name: "upstream", title: "Upstream delta", body } } fn short(s: &str) -> String { - if s.len() > 12 { s[..12].to_string() } else { s.to_string() } + if s.len() > 12 { + s[..12].to_string() + } else { + s.to_string() + } } pub fn render_text(ps: &[Panel]) -> String { let mut s = String::new(); for p in ps { - s.push_str(&format!("### {}\n{}\n", p.title, p.body)); + let _ = write!(s, "### {}\n{}\n", p.title, p.body); } s } diff --git a/src/review/intake.rs b/src/review/intake.rs index 7d84544..78e4eb6 100644 --- a/src/review/intake.rs +++ b/src/review/intake.rs @@ -11,7 +11,11 @@ //! and review decides what a candidate means. use crate::config::Config; -use crate::db::{self, model::*, Db, Pkgbase}; +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; @@ -47,19 +51,14 @@ pub fn record( /// published yet — the reason a build would fail on a missing dep, said before /// it runs. fn missing_deps(db: &Db, pb: &Pkgbase, recipe: &Recipe) -> Vec<String> { - let ours = match db::our_package_names(db) { - Ok(o) => o, - Err(_) => return Vec::new(), - }; + 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) - .map(|s| s.is_some()) - .unwrap_or(false) - || db::get_pkgbase(db, &dep).map(|p| p.is_some()).unwrap_or(false); + 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); } diff --git a/src/review/risk.rs b/src/review/risk.rs index e48ca24..4c9575f 100644 --- a/src/review/risk.rs +++ b/src/review/risk.rs @@ -1,4 +1,8 @@ -use crate::db::{self, model::*, Db}; +use crate::db::{ + self, + model::{Recipe, ReleaseRow, SourceDigest, UpstreamPin}, + Db, +}; use crate::error::Result; use crate::pkgver; @@ -22,8 +26,17 @@ pub mod level { const FETCHING_BUILD_TOOLS: &[&str] = &["cargo", "npm", "go", "pip", "python", "ruby", "deno", "rust", "nodejs"]; const BUILD_SYSTEM_FILES: &[&str] = &[ - "Cargo.toml", "Cargo.lock", "package.json", "setup.py", "pyproject.toml", "Makefile", "CMakeLists.txt", - "meson.build", "go.mod", "Gemfile", "build.gradle", + "Cargo.toml", + "Cargo.lock", + "package.json", + "setup.py", + "pyproject.toml", + "Makefile", + "CMakeLists.txt", + "meson.build", + "go.mod", + "Gemfile", + "build.gradle", ]; #[derive(Debug, Clone, Default)] @@ -32,8 +45,7 @@ pub(crate) struct Assessment { pub signals: Vec<String>, } -impl Assessment { -} +impl Assessment {} pub(crate) fn assess( db: &Db, @@ -94,7 +106,7 @@ pub(crate) fn assess( } fn accepted_pins(accepted: Option<&ReleaseRow>) -> Vec<UpstreamPin> { - accepted.map(|a| a.pins()).unwrap_or_default() + accepted.map_or_default(super::super::db::model::ReleaseRow::pins) } fn compare_recipes(old: &Recipe, new: &Recipe, s: &mut SignalSet) { @@ -120,9 +132,7 @@ fn compare_recipes(old: &Recipe, new: &Recipe, s: &mut SignalSet) { for (i, sum) in new.sha256sums.iter().enumerate() { if sum.eq_ignore_ascii_case("SKIP") { match old.sha256sums.get(i) { - Some(prev) if prev != "SKIP" && !prev.is_empty() => { - s.add(&format!("sums-to-skip:{i}"), level::HIGH) - } + Some(prev) if prev != "SKIP" && !prev.is_empty() => s.add(&format!("sums-to-skip:{i}"), level::HIGH), _ => {} } } @@ -172,7 +182,7 @@ fn upstream_touches_build_system(cfg: &crate::config::Config, from: &str, to: &s return false; } let range = format!("{from}..{to}"); - for dir in std::fs::read_dir(&cache).into_iter().flatten().filter_map(|d| d.ok()) { + for dir in std::fs::read_dir(&cache).into_iter().flatten().filter_map(std::result::Result::ok) { let path = dir.path(); if let Ok(files) = crate::git::git(Some(&path), &["diff", "--name-only", &range]) { if files.lines().any(|f| BUILD_SYSTEM_FILES.iter().any(|b| f.ends_with(b))) { |
