Factory acceptance phase and issue restart
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3f39f4bd65
commit
e09e295f60
8 files changed
+246
-8
No files matched your search
@@ -163,6 +163,7 @@ pub fn router(app: AppState) -> Router {
|
||||
.route("/account/factory/test", post(test_factory))
|
||||
.route("/factory/overview", get(factory_overview))
|
||||
.route("/factory/poll", post(factory_poll))
|
||||
.route("/factory/issues/restart", post(factory_restart))
|
||||
.route("/account/factory/connection/test", post(test_factory_connection))
|
||||
.route("/factory/drafts", post(factory_new_draft))
|
||||
.route("/factory/drafts/{id}", get(factory_draft))
|
||||
@@ -2652,6 +2653,47 @@ async fn factory_poll(Extension(user): Extension<User>, State(app): State<AppSta
|
||||
Ok(Json(json!({"errors": errors})))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct RestartIssue {
|
||||
repo: String,
|
||||
number: i64,
|
||||
/// Where to re-enter the flow: new (review again), approved (build again) or qa (acceptance again).
|
||||
to: String,
|
||||
}
|
||||
|
||||
/// Put a finished, failed or rejected issue back into the flow at the chosen stage.
|
||||
async fn factory_restart(Extension(user): Extension<User>, State(app): State<AppState>, Json(b): Json<RestartIssue>) -> ApiResult {
|
||||
let bad = |m: &str| ApiError(StatusCode::BAD_REQUEST, m.to_string());
|
||||
let row = app.store.factory_issue(&b.repo, b.number)?.filter(|r| r["owner_id"].as_str() == Some(user.id.as_str())).ok_or_else(|| ApiError(StatusCode::NOT_FOUND, "unknown issue".into()))?;
|
||||
let state = row["state"].as_str().unwrap_or("");
|
||||
if ["review", "building", "testing"].contains(&state) {
|
||||
return Err(bad("a phase is running for this issue – wait until it ends"));
|
||||
}
|
||||
if !["new", "approved", "qa"].contains(&b.to.as_str()) {
|
||||
return Err(bad("unknown target stage"));
|
||||
}
|
||||
if b.to == "qa" && row["branch"].as_str().unwrap_or("").is_empty() {
|
||||
return Err(bad("nothing was built yet – restart at review or build"));
|
||||
}
|
||||
let mut fields: Vec<(&str, Value)> = vec![("state", json!(b.to)), ("attempts", json!(0)), ("note", json!(""))];
|
||||
if b.to != "qa" {
|
||||
fields.push(("rounds", json!(0)));
|
||||
}
|
||||
if b.to == "new" {
|
||||
fields.push(("scenarios", json!("")));
|
||||
// Answers given before count as read; the new review starts from the issue as it is now.
|
||||
}
|
||||
app.store.factory_issue_set(&b.repo, b.number, &fields)?;
|
||||
let s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
|
||||
if let Some(cfg) = s.repos.iter().find(|r| r.url == b.repo).map(|r| s.resolve(r)) {
|
||||
if let Ok(g) = crate::factory::Forge::new(&cfg) {
|
||||
let labels = if b.to == "new" { vec![cfg.label.clone()] } else { vec![cfg.label.clone(), format!("factory:{}", b.to)] };
|
||||
let _ = g.set_labels(b.number as u64, &labels).await;
|
||||
}
|
||||
}
|
||||
Ok(Json(json!({"ok": true})))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct ConnTest {
|
||||
id: String,
|
||||
|
||||
Reference in new issue
Block a user