From 3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 Mon Sep 17 00:00:00 2001 From: aur-build Date: Sun, 22 Nov 2026 10:36:24 +0000 Subject: rustfmt,lints: pin the formatting, adopt the idiom lints, pay them off rustfmt.toml fixes the shape the tree is written in (120 columns, small items kept on one line) and one canonical pass makes it the truth. [lints.clippy] names the idiom lints worth enforcing and leaves out the two that would add doc-comment boilerplate rather than remove it. The tree pays them off here: write!/writeln! instead of push_str(&format!()), let-else instead of match-on-Option, borrows where a thread entry point only reads what it owns, no `&self` on a Copy state and no `self` nobody reads. ops::to_prometheus gains one gauge helper: a metric's HELP, TYPE and value are now emitted by the same call instead of three. --- src/review/approve.rs | 121 +++++++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 56 deletions(-) (limited to 'src/review/approve.rs') 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> { - 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> { + 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 { -- cgit v1.2.3