Factory: Telegram message on question and failed

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard ZinkandClaude Sonnet 5.5 committed 2026-11-19 10:22:21 +01:00
1 parent 45503de195
commit ccad2c1f6e
4 files changed
+42

No files matched your search

+6
View File
@@ -3,6 +3,12 @@
All notable changes to CodeCraft. Versions follow [Semantic Versioning](https://semver.org/);
until 1.0, minor versions may contain breaking changes.
## [Unreleased]
### Added
- **Factory: Telegram message when an issue needs you** – a question from the review (with the questions) or a failure (build blocked, build/acceptance failed, rework limit reached) is sent to the paired Telegram chat, in the language of your web UI, with a link to the issue. Nothing is sent without a paired bot.
## [v202611-00062] – 2026-11-18
### Added
+23
View File
@@ -974,6 +974,7 @@ async fn review(app: Arc<App>, user: User, cfg: RepoCfg, issue: Value, comments:
let qs: Vec<String> = res["questions"].as_array().map(|a| a.iter().filter_map(|q| q.as_str().map(|q| format!("- {q}"))).collect()).unwrap_or_default();
set(&[("state", json!("question")), ("note", json!(summary))]);
let _ = g.set_labels(n as u64, &status_labels(&cfg, "question")).await;
alert(&app, &cfg.url, n, "question", &if qs.is_empty() { summary.clone() } else { qs.join("\n") }).await;
bot_comment(&g, n as u64, &format!("**Review: questions before this can be built.** {summary}\n\n{}\n\nAnswer in a comment; the review starts again automatically.", qs.join("\n"))).await;
// Remember the newest comment (including this one) so only later answers count.
if let Ok(all) = g.comments(n as u64).await {
@@ -1067,6 +1068,7 @@ async fn build_fail(app: &Arc<App>, g: &Forge, cfg: &RepoCfg, n: i64, why: &str)
if attempts >= cfg.build.max_attempts {
let _ = app.store.factory_issue_set(&cfg.url, n, &[("state", json!("failed")), ("attempts", json!(attempts)), ("note", json!(why))]);
let _ = g.set_labels(n as u64, &status_labels(cfg, "failed")).await;
alert(&app, &cfg.url, n, "failed", &why).await;
bot_comment(g, n as u64, &format!("**Build failed:** {why}.")).await;
} else {
let _ = app.store.factory_issue_set(&cfg.url, n, &[("state", json!("approved")), ("attempts", json!(attempts)), ("note", json!(why))]);
@@ -1111,6 +1113,7 @@ async fn build(app: Arc<App>, user: User, cfg: RepoCfg, issue: Value, comments:
let reason = res["reason"].as_str().unwrap_or(&summary).trim().to_string();
set(&[("state", json!("failed")), ("note", json!(reason))]);
let _ = g.set_labels(n as u64, &status_labels(&cfg, "failed")).await;
alert(&app, &cfg.url, n, "failed", &reason).await;
bot_comment(&g, n as u64, &format!("**Build: cannot be built as specified.** {reason}")).await;
notify(&app, &user, &format!("Factory #{n}"), &format!("build blocked – {reason}"), n).await;
return;
@@ -1177,6 +1180,7 @@ async fn qa_fail(app: &Arc<App>, g: &Forge, cfg: &RepoCfg, n: i64, why: &str) {
if attempts >= cfg.qa.max_attempts {
let _ = app.store.factory_issue_set(&cfg.url, n, &[("state", json!("failed")), ("attempts", json!(attempts)), ("note", json!(why))]);
let _ = g.set_labels(n as u64, &status_labels(cfg, "failed")).await;
alert(&app, &cfg.url, n, "failed", &why).await;
bot_comment(g, n as u64, &format!("**Acceptance failed to run:** {why}.")).await;
} else {
let _ = app.store.factory_issue_set(&cfg.url, n, &[("state", json!("qa")), ("attempts", json!(attempts)), ("note", json!(why))]);
@@ -1251,6 +1255,7 @@ async fn qa(app: Arc<App>, user: User, cfg: RepoCfg, issue: Value) {
if round >= cfg.max_rework {
set(&[("state", json!("failed")), ("note", json!(findings.clone()))]);
let _ = g.set_labels(n as u64, &status_labels(&cfg, "failed")).await;
alert(&app, &cfg.url, n, "failed", &findings.clone()).await;
bot_comment(&g, n as u64, &format!("**Acceptance failed after {} rework rounds.** {summary}\n\n{table}\n{findings}", cfg.max_rework)).await;
notify(&app, &user, &format!("Factory #{n}"), "acceptance failed, rework limit reached", n).await;
} else {
@@ -1287,6 +1292,7 @@ async fn fail_or_retry(app: &Arc<App>, g: &Forge, cfg: &RepoCfg, n: i64, why: &s
if attempts >= cfg.review.max_attempts {
let _ = app.store.factory_issue_set(&cfg.url, n, &[("state", json!("failed")), ("attempts", json!(attempts)), ("note", json!(why))]);
let _ = g.set_labels(n as u64, &status_labels(cfg, "failed")).await;
alert(&app, &cfg.url, n, "failed", &why).await;
bot_comment(g, n as u64, &format!("**Failed:** {why}.")).await;
} else {
let _ = app.store.factory_issue_set(&cfg.url, n, &[("state", json!("new")), ("attempts", json!(attempts)), ("note", json!(why))]);
@@ -1298,6 +1304,23 @@ pub(crate) async fn notify(app: &App, user: &User, title: &str, body: &str, issu
let _ = crate::push::send_to_user(app, &user.id, &payload).await;
}
/// Tell the user on Telegram (if paired) that an issue needs them: a question to answer or a failure.
pub(crate) async fn alert(app: &App, repo: &str, n: i64, what: &str, detail: &str) {
let Ok(Some(row)) = app.store.factory_issue(repo, n) else { return };
let Some(owner) = row["owner_id"].as_str() else { return };
let de = crate::telegram::german(app, owner);
let name = repo.trim_end_matches(".git").rsplit('/').next().unwrap_or(repo);
let head = match (what, de) {
("question", true) => "❓ Frage zu",
("question", false) => "❓ Question on",
(_, true) => "❌ Fehlgeschlagen:",
(_, false) => "❌ Failed:",
};
let detail: String = detail.trim().chars().take(600).collect();
let text = format!("{head} {name} #{n} – {}\n\n{detail}\n\n{}/issues/{n}", row["title"].as_str().unwrap_or(""), repo.trim_end_matches(".git"));
crate::telegram::notify_user(app, owner, &text).await;
}
/// One pass over a repository: take up new issues, restart reviews after answers.
pub async fn poll_repo(app: &Arc<App>, user: &User, cfg: &RepoCfg) -> Result<()> {
let g = Forge::new(cfg)?;
+9
View File
@@ -260,6 +260,15 @@ fn user(app: &App, user_id: &str) -> Result<User> {
app.store.user(user_id)?.filter(|u| !u.disabled).ok_or_else(|| anyhow!("account disabled"))
}
/// Send a message (HTML-escaped) to the user's paired Telegram chat; silent when there is none.
pub async fn notify_user(app: &App, user_id: &str, text: &str) {
let s = load(app, user_id);
let (true, Some(chat)) = (!s.token.is_empty(), s.chat_id) else { return };
if let Err(e) = (Bot { token: s.token }).send(chat, &esc(text), None).await {
tracing::warn!("telegram: notification not sent: {e:#}");
}
}
/// The user reads German (language preference of the web UI).
pub fn german(app: &App, user_id: &str) -> bool {
let prefs: Value = app.store.user_setting(user_id, "prefs").unwrap_or_default();
+4
View File
@@ -3,6 +3,10 @@
* under "unreleased"; scripts/release.sh renames the key to the release version.
*/
export const WHATS_NEW: Record<string, { en: string[]; de: string[] }> = {
unreleased: {
en: ["Factory: Telegram message when an issue gets a question or fails"],
de: ["Factory: Telegram-Nachricht, wenn ein Issue eine Frage hat oder fehlschlägt"],
},
"202611-00062": {
en: ["Factory: the parallel limit per project is now respected exactly", "Factory: remove issues from the board; issues deleted on the forge disappear by themselves"],
de: ["Factory: das Parallel-Limit pro Projekt wird jetzt genau eingehalten", "Factory: Issues vom Board entfernen; im Forge gelöschte Issues verschwinden von selbst"],