diff --git a/CHANGELOG.md b/CHANGELOG.md index 23ccc30..d9237ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,16 @@ All notable changes to CodeCraft. Versions follow [Semantic Versioning](https://semver.org/); until 1.0, minor versions may contain breaking changes. +## [Unreleased] + +### Added + +- **Factory: remove issues from the board** – a "Remove from board" button for issues that are not running, and issues deleted on the forge (404) disappear from the board by themselves at the next poll. + +### Fixed + +- **Factory: the "parallel" limit was exceeded** – phases were counted by their run rows, which appear only after the checkout, so one poll could start more phases than allowed (2 allowed, 4 running). They are now counted by issue state, which is set before a phase starts. + ## [v202611-00061] – 2026-11-18 ### Changed diff --git a/server/src/api.rs b/server/src/api.rs index a18cc48..7a9b4ea 100644 --- a/server/src/api.rs +++ b/server/src/api.rs @@ -176,6 +176,7 @@ pub fn router(app: AppState) -> Router { .route("/factory/release/preview", get(factory_release_preview)) .route("/factory/release", post(factory_release)) .route("/factory/issues/close", post(factory_close_issue)) + .route("/factory/issues/remove", post(factory_remove_issue)) .route("/factory/issues/pr", get(factory_pr)) .route("/factory/issues/pr/merge", post(factory_pr_merge)) .route("/account/factory/connection/test", post(test_factory_connection)) @@ -2836,6 +2837,17 @@ async fn factory_close_issue(Extension(user): Extension, State(app): State Ok(Json(json!({"ok": true}))) } +/// Take an issue off the factory board (the issue on the forge is not touched). Not while a phase runs. +async fn factory_remove_issue(Extension(user): Extension, State(app): State, headers: axum::http::HeaderMap, Json(b): Json) -> ApiResult { + let (_, row) = factory_issue_forge(&app, &user, &b.repo, b.number)?; + if matches!(row["state"].as_str(), Some("review" | "building" | "testing")) { + return Err(ApiError(StatusCode::BAD_REQUEST, "a phase is running – wait for it to end or stop it first".into())); + } + app.store.factory_issue_delete(&b.repo, b.number)?; + app.audit(Some(&user), "factory.issue.remove", &format!("{}#{}", b.repo, b.number), &crate::auth::client_ip(&headers)); + Ok(Json(json!({"ok": true}))) +} + #[derive(Deserialize)] struct PrQuery { repo: String, diff --git a/server/src/factory.rs b/server/src/factory.rs index fea0b90..bf1638a 100644 --- a/server/src/factory.rs +++ b/server/src/factory.rs @@ -562,6 +562,14 @@ impl Forge { Ok(!matches!(v["state"].as_str(), Some("closed"))) } + /// Has the issue been deleted on the forge (404)? Other errors (network, token) count as "still there". + pub async fn issue_gone(&self, number: u64) -> bool { + match self.call(reqwest::Method::GET, self.rp(&format!("/issues/{number}")), None).await { + Err(e) => e.to_string().contains("404"), + Ok(_) => false, + } + } + pub async fn close_issue(&self, number: u64) -> Result<()> { match self.kind { Kind::Gitlab => self.call(reqwest::Method::PUT, self.rp(&format!("/issues/{number}")), Some(json!({"state_event": "close"}))).await.map(|_| ()), @@ -1353,6 +1361,14 @@ pub async fn poll_repo(app: &Arc, user: &User, cfg: &RepoCfg) -> Result<()> app.store.factory_issue_set(&cfg.url, n, &[("state", json!("closed"))])?; } } + // Issues deleted on the forge leave the board (closed ones stay: they still exist there). + for row in app.store.factory_issues(&user.id)?.into_iter().filter(|r| r["repo"].as_str() == Some(cfg.url.as_str()) && !matches!(r["state"].as_str(), Some("review" | "building" | "testing"))) { + let n = issue_no(&row); + if n > 0 && !open.contains(&n) && g.issue_gone(n as u64).await { + tracing::info!("factory {}: #{n} was deleted on the forge – removed from the board", cfg.url); + app.store.factory_issue_delete(&cfg.url, n)?; + } + } // Merged issues get their version and tag. if let Err(e) = crate::factory_version::version_pass(app, user, cfg).await { tracing::warn!("factory {}: versions: {e:#}", cfg.url); diff --git a/server/src/store.rs b/server/src/store.rs index 22b3d6a..030e50b 100644 --- a/server/src/store.rs +++ b/server/src/store.rs @@ -1497,6 +1497,12 @@ impl Store { Ok(()) } + /// Remove an issue from the factory board (runs and cost statistics stay). + pub fn factory_issue_delete(&self, repo: &str, number: i64) -> Result<()> { + self.conn.lock().unwrap().execute("DELETE FROM factory_issues WHERE repo_url = ?1 AND number = ?2", params![repo, number])?; + Ok(()) + } + /// Update the given columns (whitelisted) of an issue. pub fn factory_issue_set(&self, repo: &str, number: i64, fields: &[(&str, Value)]) -> Result<()> { const COLS: [&str; 11] = ["title", "state", "attempts", "rounds", "last_comment", "scenarios", "branch", "pr_url", "note", "author", "version"]; @@ -1586,7 +1592,9 @@ impl Store { } pub fn factory_running(&self, repo: &str) -> Result { - Ok(self.conn.lock().unwrap().query_row("SELECT COUNT(*) FROM factory_runs WHERE repo_url = ?1 AND status = 'running'", [repo], |r| r.get(0))?) + // Counted by issue state, not by run rows: the state is set before the phase is spawned, the run row + // only once its checkout is done – counting runs let a single poll start more phases than allowed. + Ok(self.conn.lock().unwrap().query_row("SELECT COUNT(*) FROM factory_issues WHERE repo_url = ?1 AND state IN ('review', 'building', 'testing')", [repo], |r| r.get(0))?) } /// Runs with token and cost totals (joined from the usage table). diff --git a/web/src/components/Factory.tsx b/web/src/components/Factory.tsx index 48731a1..d514289 100644 --- a/web/src/components/Factory.tsx +++ b/web/src/components/Factory.tsx @@ -348,6 +348,20 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) { setBusy(false); } }; + const removeIssue = async () => { + if (!selected) return; + if (!(await confirmDialog({ message: t("factory.removeConfirm", { n: selected.number }), confirmLabel: t("factory.remove"), danger: true }))) return; + setBusy(true); + try { + await post("/factory/issues/remove", { repo: selected.repo, number: selected.number }); + setSel(""); + await reload(); + } catch (e: any) { + toast(e.message); + } finally { + setBusy(false); + } + }; const closeIssue = async () => { if (!selected) return; const comment = await promptDialog({ title: t("factory.closeTitle"), message: t("factory.closeMsg", { n: selected.number }), defaultValue: t("factory.closeDefault"), confirmLabel: t("factory.close") }); @@ -503,6 +517,11 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) { )} + {selected && !["review", "building", "testing"].includes(selected.state) && ( + + )} {selected && selected.state === "done" && (