Factory: merge and close buttons on the issue card, enforced order
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0e54714436
commit
391db43949
10 files changed
+121
-16
No files matched your search
+21
-1
@@ -3011,6 +3011,15 @@ async fn factory_close_issue(Extension(user): Extension<User>, State(app): State
|
||||
return Err(ApiError(StatusCode::BAD_REQUEST, "only finished issues can be closed here".into()));
|
||||
}
|
||||
let bad = |e: anyhow::Error| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}"));
|
||||
// Closing comes after the merge. A merge done on the forge itself counts too: ask the forge when we do not know yet.
|
||||
if row["merged"].as_bool() != Some(true) {
|
||||
let pr_n: u64 = row["pr_url"].as_str().unwrap_or("").trim_end_matches('/').rsplit('/').next().and_then(|n| n.parse().ok()).unwrap_or(0);
|
||||
let merged = pr_n > 0 && g.pr(pr_n).await.map(|p| p["state"].as_str() == Some("merged")).unwrap_or(false);
|
||||
if !merged {
|
||||
return Err(ApiError(StatusCode::BAD_REQUEST, "merge the pull request first".into()));
|
||||
}
|
||||
app.store.factory_issue_set(&b.repo, b.number, &[("merged", json!(1))])?;
|
||||
}
|
||||
let text = if b.comment.trim().is_empty() { "Closed.".to_string() } else { b.comment.trim().to_string() };
|
||||
g.comment(b.number as u64, &format!("{}\n**Closed** by {}: {text}", crate::factory::BOT, user.username)).await.map_err(bad)?;
|
||||
g.close_issue(b.number as u64).await.map_err(bad)?;
|
||||
@@ -3072,6 +3081,10 @@ struct MergePr {
|
||||
/// Merge the pull request of an issue – only on the user's own click in the factory page.
|
||||
async fn factory_pr_merge(Extension(user): Extension<User>, State(app): State<AppState>, headers: axum::http::HeaderMap, Json(b): Json<MergePr>) -> ApiResult {
|
||||
let (g, row) = factory_issue_forge(&app, &user, &b.repo, b.number)?;
|
||||
// Merging comes after a positive acceptance (the issue is "done").
|
||||
if row["state"].as_str() != Some("done") {
|
||||
return Err(ApiError(StatusCode::BAD_REQUEST, "the pull request can be merged once the acceptance has passed".into()));
|
||||
}
|
||||
let method = if b.method.is_empty() { "merge" } else { b.method.as_str() };
|
||||
if !["merge", "squash", "rebase"].contains(&method) {
|
||||
return Err(ApiError(StatusCode::BAD_REQUEST, "unknown merge method".into()));
|
||||
@@ -3082,8 +3095,15 @@ async fn factory_pr_merge(Extension(user): Extension<User>, State(app): State<Ap
|
||||
return Err(ApiError(StatusCode::BAD_REQUEST, "this is not the open pull request of the issue".into()));
|
||||
}
|
||||
g.merge_pr(b.pr, method).await.map_err(|e| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}")))?;
|
||||
app.store.factory_issue_set(&b.repo, b.number, &[("pr_url", json!(pr["html_url"].as_str().unwrap_or("")))])?;
|
||||
app.store.factory_issue_set(&b.repo, b.number, &[("pr_url", json!(pr["html_url"].as_str().unwrap_or(""))), ("merged", json!(1))])?;
|
||||
app.audit(Some(&user), "factory.pr.merge", &format!("{}#{}", b.repo, b.number), &crate::auth::client_ip(&headers));
|
||||
// Give the issue its version and tag right away instead of at the next poll.
|
||||
if let Ok(cfg) = factory_repo_cfg(&app, &user, &b.repo) {
|
||||
let (app2, user2) = (app.clone(), user.clone());
|
||||
tokio::spawn(async move {
|
||||
let _ = crate::factory::poll_repo(&app2, &user2, &cfg).await;
|
||||
});
|
||||
}
|
||||
Ok(Json(json!({"ok": true})))
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user