diff options
| author | dev <dev@localhost> | 2026-11-20 18:34:26 +0000 |
|---|---|---|
| committer | dev <dev@localhost> | 2026-11-20 18:34:26 +0000 |
| commit | 895f3547043def08f0822f936ae34458315f6982 (patch) | |
| tree | 9e7b08db7225786f1d1ec5b312314801e3d09c90 /src/http | |
| parent | bbae6c8e83cf145f9af472f69591bae804d03048 (diff) | |
| download | aur-build-895f3547043def08f0822f936ae34458315f6982.tar.gz aur-build-895f3547043def08f0822f936ae34458315f6982.zip | |
usecase: one implementation of each workflow, run by both front ends
`main` opened the repository inline before its command match. `serve` opened it
again, four calls in an order that matters. The web routes wrote subscriptions,
toggles, notices and build retries straight through `db::`, so the CLI and the
UI were two independent guesses at the same product, and the guesses had already
drifted: `sub_add` fell back to repo id 1 where the CLI reported the repository
as uninitialised, and `build_retry` remembered to write the audit row while
nothing else did.
`src/usecase/` is the workflow layer now — bootstrap, detect, reviews,
subscriptions, builds, maintenance. A function earns a place here by having more
than one step in an order that matters: `approve` records the decision *and*
queues the build it authorises, because an approval that silently fails to queue
is the exact failure the review queue exists to prevent, and both front ends had
to remember to pair them.
Nothing in the layer formats output or knows a status code exists. Where the two
front ends genuinely disagree, the result carries the disagreement instead of
resolving it: `Approved::queued` is a `Result` because a failed enqueue is fatal
in the CLI — an approved candidate with no build is a stall nobody notices — and
a soft failure in the UI, which has already committed the decision and can retry
from the package page.
`src/http/routes/mutations.rs` now contains no `db::` call at all, and
`main.rs` is 314 lines with no multi-step sequence and nothing exported.
Rank map: usecase 9, http 10, composition roots 11. The layer test enforces
that usecase cannot name http, which is why `serve` starts the scheduler and the
build pool but leaves the HTTP server to `main`.
One user-visible message moves: `aur-build reject <missing>` now says
`not found: candidate N` (the review layer's wording) instead of
`no candidate #N` (main's). Both exit 1; the check moved with the workflow.
280 passed / 0 failed, clippy -D warnings clean, architecture 8/8.
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/routes/mutations.rs | 91 |
1 files changed, 39 insertions, 52 deletions
diff --git a/src/http/routes/mutations.rs b/src/http/routes/mutations.rs index 2af8b7f..ad11dfa 100644 --- a/src/http/routes/mutations.rs +++ b/src/http/routes/mutations.rs @@ -1,7 +1,6 @@ -use crate::db::{self, builds}; -use crate::review::{approve as ap, candidates}; -use crate::pipeline; use crate::http::{Req, Res, State}; +use crate::review::candidates; +use crate::usecase; use super::*; @@ -18,32 +17,29 @@ pub(crate) fn review_approve(state: &State, req: &Req, id: &str) -> Res { let identity = req.form_get("identity_hash").unwrap_or_default(); let digest = req.form_get("diff_digest").unwrap_or_default(); let note = req.form_get("note").filter(|s| !s.trim().is_empty()); - match ap::approve(db, actor(state, req), id, &identity, &digest, note.as_deref()) { - Ok(a) => { + // The same workflow the CLI runs: record the decision, then queue what it + // authorises. Only the rendering differs from here down. + match usecase::approve(&state.cfg, db, actor(state, req), &c, &identity, &digest, note.as_deref()) { + Ok(usecase::Approval::Recorded(a)) => { let mut page = chrome(state, req, "Reviews", "nav_reviews"); - page.flash = format!("approved {} (approval {}); build queued", c.pkgbase, a.id); page.has_flash = true; - match pipeline::enqueue_for_candidate(&state.cfg, db, &c) { - Ok(bid) => { - page.flash = format!("approved {}; build {} queued", c.pkgbase, short(&bid)); - page.has_flash = true; - } + match a.queued { + Ok(bid) => page.flash = format!("approved {}; build {} queued", c.pkgbase, short(&bid)), Err(e) => { page.flash = format!("approved, but the build could not be queued: {e}"); - page.has_flash = true; page.flash_err = true; } } page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 200) } - Err(ap::ApproveError::System(e)) => { + Err(e) => { let mut page = chrome(state, req, "Review failed", "nav_reviews"); page.flash = format!("the approval could not be recorded: {e}"); page.has_flash = true; page.flash_err = true; page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 500) } - Err(ap::ApproveError::Stale(stale)) => { + Ok(usecase::Approval::Refused(stale)) => { let mut page = chrome(state, req, "Review changed", "nav_reviews"); page.flash = format!("refused: {stale}"); page.has_flash = true; @@ -86,7 +82,7 @@ pub(crate) fn review_reject(state: &State, req: &Req, id: &str) -> Res { page.flash_err = true; return page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 400); }; - match ap::reject(db, actor(state, req), id, ¬e) { + match usecase::reject(db, actor(state, req), id, ¬e) { Ok(()) => { let mut page = chrome(state, req, "Reviews", "nav_reviews"); page.flash = format!("rejected #{id}; it can be re-opened from the package page"); @@ -134,7 +130,7 @@ pub(crate) fn reviews_bulk(state: &State, req: &Req) -> Res { candidates::candidate_by_id(db, *id).ok().flatten().map(|c| (*id, c.identity_hash, c.diff_digest)) }) .collect(); - let outcomes = match ap::bulk(db, actor(state, req), &items, &decision, &confirmed) { + let decisions = match usecase::bulk(&state.cfg, db, actor(state, req), &items, &decision, &confirmed) { Ok(outcomes) => outcomes, Err(e) => { let mut page = chrome(state, req, "Reviews", "nav_reviews"); @@ -146,16 +142,11 @@ pub(crate) fn reviews_bulk(state: &State, req: &Req) -> Res { }; let mut done = Vec::new(); let mut refused = Vec::new(); - for item in outcomes { - match &item.outcome { - ap::BulkOutcome::Approved(_) => { - if let Some(c) = &item.candidate { - let _ = pipeline::enqueue_for_candidate(&state.cfg, db, c); - done.push(c.pkgbase.clone()); - } - } - ap::BulkOutcome::Rejected => done.push(item.pkgbase().to_string()), - ap::BulkOutcome::Refused(r) => refused.push(format!("{}: {r}", item.pkgbase())), + for d in decisions { + match d { + usecase::Decision::Approved { pkgbase, .. } => done.push(pkgbase), + usecase::Decision::Rejected { pkgbase } => done.push(pkgbase), + usecase::Decision::Refused { pkgbase, why } => refused.push(format!("{pkgbase}: {why}")), } } let mut page = chrome(state, req, "Reviews", "nav_reviews"); @@ -175,12 +166,12 @@ pub(crate) fn sub_add(state: &State, req: &Req) -> Res { let Some(name) = req.form_get("pkgbase").map(|s| s.trim().to_string()).filter(|s| !s.is_empty()) else { return flash_sub(state, req, "give a pkgbase name", true); }; - let rid = db::repo_id(db).unwrap_or(1); - let url = format!("https://aur.archlinux.org/{name}.git"); - match db::subscribe(&db.writer, rid, &name, &url) { - Ok(_) => { - let _ = crate::watch::detect::check_pkgbase(&state.cfg, db, &name); - flash_sub(state, req, &format!("subscribed {name} and ran a first check"), false) + match usecase::subscribe(db, &name, None) { + Ok(s) => { + // A subscription nobody has checked yet looks identical to one that + // is simply up to date, so the first detection is part of adding it. + let _ = usecase::check(&state.cfg, db, &s.pkgbase); + flash_sub(state, req, &format!("subscribed {} and ran a first check", s.pkgbase), false) } Err(e) => flash_sub(state, req, &format!("could not subscribe: {e}"), true), } @@ -189,32 +180,31 @@ pub(crate) fn sub_add(state: &State, req: &Req) -> Res { pub(crate) fn sub_pause(state: &State, req: &Req) -> Res { let db = &state.db; let name = req.form_get("pkgbase").unwrap_or_default(); - let cur = db::get_subscription(db, &name).ok().flatten().map(|s| s.state); - let next = match cur { - Some(SubscriptionState::Active) => SubscriptionState::Paused, - Some(SubscriptionState::Paused) => SubscriptionState::Active, - Some(other) => return flash_sub(state, req, &format!("{name} is {other}: nothing to pause"), true), - None => return flash_sub(state, req, &format!("no subscription for {name}"), true), - }; - let _ = db::set_subscription_state(&db.writer, &name, next); - flash_sub(state, req, &format!("{name}: {next}"), false) + match usecase::toggle_pause(db, &name) { + Ok(usecase::Pause::Now(next)) => flash_sub(state, req, &format!("{name}: {next}"), false), + Ok(usecase::Pause::NotApplicable(other)) => { + flash_sub(state, req, &format!("{name} is {other}: nothing to pause"), true) + } + Ok(usecase::Pause::Unknown) | Err(_) => { + flash_sub(state, req, &format!("no subscription for {name}"), true) + } + } } pub(crate) fn sub_remove(state: &State, req: &Req) -> Res { - let db = &state.db; let name = req.form_get("pkgbase").unwrap_or_default(); - let _ = db::set_subscription_state(&db.writer, &name, SubscriptionState::Removed); + let _ = usecase::unsubscribe(&state.db, &name); flash_sub(state, req, &format!("{name}: removed"), false) } pub(crate) fn notice_ack(state: &State, req: &Req) -> Res { let id: i64 = req.form_get("id").and_then(|s| s.parse().ok()).unwrap_or(0); - let _ = db::acknowledge_notice(&state.db.writer, id); + let _ = usecase::acknowledge_notice(&state.db, id); Res::redirect("/attention") } pub(crate) fn package_rebuild(state: &State, req: &Req, name: &str) -> Res { - match pipeline::enqueue_manual_rebuild(&state.cfg, &state.db, name) { + match usecase::manual_rebuild(&state.cfg, &state.db, name) { Ok(id) => { let mut page = chrome(state, req, "Builds", "nav_builds"); page.flash = format!( @@ -235,7 +225,7 @@ pub(crate) fn package_rebuild(state: &State, req: &Req, name: &str) -> Res { } pub(crate) fn package_withdraw(state: &State, req: &Req, name: &str) -> Res { - match pipeline::publish::withdraw_package(&state.cfg, &state.db, name) { + match usecase::withdraw_package(&state.cfg, &state.db, name) { Ok(()) => Res::redirect("/packages"), Err(e) => { let mut page = chrome(state, req, "Index", "nav_packages"); @@ -248,7 +238,7 @@ pub(crate) fn package_withdraw(state: &State, req: &Req, name: &str) -> Res { } pub(crate) fn build_cancel(state: &State, req: &Req, id: &str) -> Res { - let _ = builds::request_cancel(&state.db, id); + let _ = usecase::cancel(&state.db, id); let mut page = chrome(state, req, "Builds", "nav_builds"); page.flash = format!("cancellation requested for {}; it stops at the next step boundary", short(id)); page.has_flash = true; @@ -256,11 +246,8 @@ pub(crate) fn build_cancel(state: &State, req: &Req, id: &str) -> Res { } pub(crate) fn build_retry(state: &State, req: &Req, id: &str) -> Res { - match builds::retry(&state.db, id) { - Ok(()) => { - let _ = db::audit(&state.db.writer, "web", "web", "build.retry", "build", id, serde_json::json!({})); - Res::redirect(&format!("/builds/{id}")) - } + match usecase::retry(&state.db, "web", id) { + Ok(()) => Res::redirect(&format!("/builds/{id}")), Err(e) => { let mut page = chrome(state, req, "Builds", "nav_builds"); page.flash = format!("could not retry: {e}"); |
