huskies: merge 944
This commit is contained in:
@@ -4,22 +4,21 @@
|
||||
//! or borrowed string data. They return `(plain_text, html)` pairs suitable
|
||||
//! for `ChatTransport::send_message`.
|
||||
|
||||
use crate::pipeline_state::Stage;
|
||||
use crate::service::common::item_id::extract_item_number;
|
||||
|
||||
/// Human-readable display name for a pipeline stage directory.
|
||||
pub fn stage_display_name(stage: &str) -> &'static str {
|
||||
use crate::pipeline_state::Stage;
|
||||
match Stage::from_dir(stage) {
|
||||
Some(Stage::Upcoming) => "Upcoming",
|
||||
Some(Stage::Backlog) => "Backlog",
|
||||
Some(Stage::Coding) => "Current",
|
||||
Some(Stage::Blocked { .. }) => "Blocked",
|
||||
Some(Stage::Qa) => "QA",
|
||||
Some(Stage::Merge { .. }) => "Merge",
|
||||
Some(Stage::Done { .. }) => "Done",
|
||||
Some(Stage::Archived { .. }) => "Archived",
|
||||
Some(Stage::MergeFailure { .. }) => "MergeFailure",
|
||||
None => "Unknown",
|
||||
/// Human-readable display name for a typed pipeline [`Stage`].
|
||||
pub fn stage_display_name(stage: &Stage) -> &'static str {
|
||||
match stage {
|
||||
Stage::Upcoming => "Upcoming",
|
||||
Stage::Backlog => "Backlog",
|
||||
Stage::Coding => "Current",
|
||||
Stage::Blocked { .. } => "Blocked",
|
||||
Stage::Qa => "QA",
|
||||
Stage::Merge { .. } => "Merge",
|
||||
Stage::Done { .. } => "Done",
|
||||
Stage::Archived { .. } => "Archived",
|
||||
Stage::MergeFailure { .. } => "MergeFailure",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +28,8 @@ pub fn stage_display_name(stage: &str) -> &'static str {
|
||||
pub fn format_stage_notification(
|
||||
item_id: &str,
|
||||
story_name: Option<&str>,
|
||||
from_stage: &str,
|
||||
to_stage: &str,
|
||||
from_stage: &Stage,
|
||||
to_stage: &Stage,
|
||||
) -> (String, String) {
|
||||
let number = extract_item_number(item_id).unwrap_or(item_id);
|
||||
let effective_name = story_name.filter(|n| !n.is_empty());
|
||||
@@ -39,10 +38,17 @@ pub fn format_stage_notification(
|
||||
.map(|n| format!("<em>{n}</em> "))
|
||||
.unwrap_or_default();
|
||||
|
||||
let prefix = if to_stage == "Done" { "\u{1f389} " } else { "" };
|
||||
let plain = format!("{prefix}#{number} {name_plain}\u{2014} {from_stage} \u{2192} {to_stage}");
|
||||
let from_display = stage_display_name(from_stage);
|
||||
let to_display = stage_display_name(to_stage);
|
||||
let prefix = if matches!(to_stage, Stage::Done { .. }) {
|
||||
"\u{1f389} "
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let plain =
|
||||
format!("{prefix}#{number} {name_plain}\u{2014} {from_display} \u{2192} {to_display}");
|
||||
let html = format!(
|
||||
"{prefix}<strong>#{number}</strong> {name_html}\u{2014} {from_stage} \u{2192} {to_stage}"
|
||||
"{prefix}<strong>#{number}</strong> {name_html}\u{2014} {from_display} \u{2192} {to_display}"
|
||||
);
|
||||
(plain, html)
|
||||
}
|
||||
@@ -207,29 +213,37 @@ mod tests {
|
||||
|
||||
// ── stage_display_name ────────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn stage_display_name_maps_all_known_stages() {
|
||||
assert_eq!(stage_display_name("backlog"), "Backlog");
|
||||
assert_eq!(stage_display_name("coding"), "Current");
|
||||
assert_eq!(stage_display_name("qa"), "QA");
|
||||
assert_eq!(stage_display_name("merge"), "Merge");
|
||||
assert_eq!(stage_display_name("done"), "Done");
|
||||
assert_eq!(stage_display_name("archived"), "Archived");
|
||||
assert_eq!(stage_display_name("unknown"), "Unknown");
|
||||
fn done_stage() -> Stage {
|
||||
Stage::from_dir("done").unwrap()
|
||||
}
|
||||
fn merge_stage() -> Stage {
|
||||
Stage::from_dir("merge").unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stage_display_name_unknown_slug_returns_unknown() {
|
||||
assert_eq!(stage_display_name("99_future"), "Unknown");
|
||||
assert_eq!(stage_display_name(""), "Unknown");
|
||||
fn stage_display_name_maps_all_known_stages() {
|
||||
assert_eq!(stage_display_name(&Stage::Backlog), "Backlog");
|
||||
assert_eq!(stage_display_name(&Stage::Coding), "Current");
|
||||
assert_eq!(stage_display_name(&Stage::Qa), "QA");
|
||||
assert_eq!(stage_display_name(&merge_stage()), "Merge");
|
||||
assert_eq!(stage_display_name(&done_stage()), "Done");
|
||||
assert_eq!(
|
||||
stage_display_name(&Stage::from_dir("archived").unwrap()),
|
||||
"Archived"
|
||||
);
|
||||
assert_eq!(stage_display_name(&Stage::Upcoming), "Upcoming");
|
||||
}
|
||||
|
||||
// ── format_stage_notification ─────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn format_notification_done_stage_includes_party_emoji() {
|
||||
let (plain, html) =
|
||||
format_stage_notification("353_story_done", Some("Done Story"), "Merge", "Done");
|
||||
let (plain, html) = format_stage_notification(
|
||||
"353_story_done",
|
||||
Some("Done Story"),
|
||||
&merge_stage(),
|
||||
&done_stage(),
|
||||
);
|
||||
assert_eq!(
|
||||
plain,
|
||||
"\u{1f389} #353 Done Story \u{2014} Merge \u{2192} Done"
|
||||
@@ -242,8 +256,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn format_notification_non_done_stage_has_no_emoji() {
|
||||
let (plain, _html) =
|
||||
format_stage_notification("42_story_thing", Some("Some Story"), "Backlog", "Current");
|
||||
let (plain, _html) = format_stage_notification(
|
||||
"42_story_thing",
|
||||
Some("Some Story"),
|
||||
&Stage::Backlog,
|
||||
&Stage::Coding,
|
||||
);
|
||||
assert!(!plain.contains("\u{1f389}"));
|
||||
}
|
||||
|
||||
@@ -252,8 +270,8 @@ mod tests {
|
||||
let (plain, html) = format_stage_notification(
|
||||
"261_story_bot_notifications",
|
||||
Some("Bot notifications"),
|
||||
"Upcoming",
|
||||
"Current",
|
||||
&Stage::Upcoming,
|
||||
&Stage::Coding,
|
||||
);
|
||||
assert_eq!(
|
||||
plain,
|
||||
@@ -267,15 +285,20 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn format_stage_notification_without_story_name_falls_back_to_number() {
|
||||
let (plain, html) = format_stage_notification("42_bug_fix_thing", None, "Current", "QA");
|
||||
let (plain, html) =
|
||||
format_stage_notification("42_bug_fix_thing", None, &Stage::Coding, &Stage::Qa);
|
||||
assert_eq!(plain, "#42 \u{2014} Current \u{2192} QA");
|
||||
assert_eq!(html, "<strong>#42</strong> \u{2014} Current \u{2192} QA");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_notification_non_numeric_id_uses_full_id() {
|
||||
let (plain, _html) =
|
||||
format_stage_notification("abc_story_thing", Some("Some Story"), "QA", "Merge");
|
||||
let (plain, _html) = format_stage_notification(
|
||||
"abc_story_thing",
|
||||
Some("Some Story"),
|
||||
&Stage::Qa,
|
||||
&merge_stage(),
|
||||
);
|
||||
assert_eq!(
|
||||
plain,
|
||||
"#abc_story_thing Some Story \u{2014} QA \u{2192} Merge"
|
||||
@@ -286,21 +309,26 @@ mod tests {
|
||||
fn format_stage_notification_long_name_is_preserved() {
|
||||
let long_name = "A".repeat(300);
|
||||
let (plain, _html) =
|
||||
format_stage_notification("1_story_long", Some(&long_name), "Current", "QA");
|
||||
format_stage_notification("1_story_long", Some(&long_name), &Stage::Coding, &Stage::Qa);
|
||||
assert!(plain.contains(&long_name));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_stage_notification_empty_story_name_falls_back_to_number() {
|
||||
let (plain, html) = format_stage_notification("42_story_empty", Some(""), "Current", "QA");
|
||||
let (plain, html) =
|
||||
format_stage_notification("42_story_empty", Some(""), &Stage::Coding, &Stage::Qa);
|
||||
assert_eq!(plain, "#42 \u{2014} Current \u{2192} QA");
|
||||
assert_eq!(html, "<strong>#42</strong> \u{2014} Current \u{2192} QA");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_stage_notification_unicode_name() {
|
||||
let (plain, html) =
|
||||
format_stage_notification("7_story_i18n", Some("Ünïcödé Ñämé 🎉"), "QA", "Merge");
|
||||
let (plain, html) = format_stage_notification(
|
||||
"7_story_i18n",
|
||||
Some("Ünïcödé Ñämé 🎉"),
|
||||
&Stage::Qa,
|
||||
&merge_stage(),
|
||||
);
|
||||
assert!(plain.contains("Ünïcödé Ñämé 🎉"));
|
||||
assert!(html.contains("Ünïcödé Ñämé 🎉"));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
use crate::chat::ChatTransport;
|
||||
use crate::config::ProjectConfig;
|
||||
use crate::io::watcher::WatcherEvent;
|
||||
use crate::pipeline_state::Stage;
|
||||
use crate::slog;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
@@ -19,7 +20,7 @@ use super::super::format::{
|
||||
format_agent_completed_notification, format_agent_started_notification,
|
||||
format_blocked_notification, format_error_notification, format_oauth_account_swapped,
|
||||
format_oauth_accounts_exhausted, format_rate_limit_notification, format_stage_notification,
|
||||
merge_failure_snippet, stage_display_name,
|
||||
merge_failure_snippet,
|
||||
};
|
||||
use super::super::route::rooms_for_notification;
|
||||
use super::{find_story_name_any_stage, read_story_name};
|
||||
@@ -47,11 +48,11 @@ pub fn spawn_notification_listener(
|
||||
let mut rate_limit_last_notified: HashMap<String, Instant> = HashMap::new();
|
||||
|
||||
// Pending stage-transition notifications, keyed by item_id.
|
||||
// Value: (from_display, to_stage_key, story_name).
|
||||
// Value: (from_stage, to_stage, story_name).
|
||||
// Rapid successive transitions for the same item are coalesced: the
|
||||
// original from_display is kept while to_stage_key is updated to the
|
||||
// original `from_stage` is kept while `to_stage` is updated to the
|
||||
// latest destination, so only one notification fires for the final stage.
|
||||
let mut pending_transitions: HashMap<String, (String, String, Option<String>)> =
|
||||
let mut pending_transitions: HashMap<String, (Stage, Stage, Option<String>)> =
|
||||
HashMap::new();
|
||||
let mut flush_deadline: Option<tokio::time::Instant> = None;
|
||||
|
||||
@@ -83,15 +84,13 @@ pub fn spawn_notification_listener(
|
||||
let now = tokio::time::Instant::now();
|
||||
// Flush stage transitions if their deadline has passed.
|
||||
if flush_deadline.is_some_and(|d| d <= now) {
|
||||
for (item_id, (from_display, to_stage_key, story_name)) in
|
||||
pending_transitions.drain()
|
||||
for (item_id, (from_stage, to_stage, story_name)) in pending_transitions.drain()
|
||||
{
|
||||
let to_display = stage_display_name(&to_stage_key);
|
||||
let (plain, html) = format_stage_notification(
|
||||
&item_id,
|
||||
story_name.as_deref(),
|
||||
&from_display,
|
||||
to_display,
|
||||
&from_stage,
|
||||
&to_stage,
|
||||
);
|
||||
slog!("[bot] Sending stage notification: {plain}");
|
||||
if config.status_push_enabled {
|
||||
@@ -135,15 +134,14 @@ pub fn spawn_notification_listener(
|
||||
slog!("[bot] Watcher channel closed, stopping notification listener");
|
||||
// Flush any coalesced transitions that haven't fired yet.
|
||||
if config.status_push_enabled {
|
||||
for (item_id, (from_display, to_stage_key, story_name)) in
|
||||
for (item_id, (from_stage, to_stage, story_name)) in
|
||||
pending_transitions.drain()
|
||||
{
|
||||
let to_display = stage_display_name(&to_stage_key);
|
||||
let (plain, html) = format_stage_notification(
|
||||
&item_id,
|
||||
story_name.as_deref(),
|
||||
&from_display,
|
||||
to_display,
|
||||
&from_stage,
|
||||
&to_stage,
|
||||
);
|
||||
slog!("[bot] Sending stage notification: {plain}");
|
||||
for room_id in &rooms_for_notification(&get_room_ids) {
|
||||
@@ -185,7 +183,11 @@ pub fn spawn_notification_listener(
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let from_display = stage_display_name(from_stage.as_deref().unwrap_or(""));
|
||||
let from_typed = from_stage
|
||||
.as_deref()
|
||||
.and_then(Stage::from_dir)
|
||||
.unwrap_or(Stage::Upcoming);
|
||||
let to_typed = Stage::from_dir(stage).unwrap_or(Stage::Upcoming);
|
||||
|
||||
// Look up the story name in the expected stage directory; fall
|
||||
// back to a full search so stale events still show the name.
|
||||
@@ -193,17 +195,17 @@ pub fn spawn_notification_listener(
|
||||
.or_else(|| find_story_name_any_stage(&project_root, item_id));
|
||||
|
||||
// Buffer the transition. If this item_id is already pending (rapid
|
||||
// succession), update to_stage_key to the latest destination while
|
||||
// preserving the original from_display.
|
||||
// succession), update the destination stage to the latest while
|
||||
// preserving the original from_stage.
|
||||
pending_transitions
|
||||
.entry(item_id.clone())
|
||||
.and_modify(|e| {
|
||||
e.1 = stage.clone();
|
||||
e.1 = to_typed.clone();
|
||||
if story_name.is_some() {
|
||||
e.2 = story_name.clone();
|
||||
}
|
||||
})
|
||||
.or_insert_with(|| (from_display.to_string(), stage.clone(), story_name));
|
||||
.or_insert_with(|| (from_typed, to_typed, story_name));
|
||||
|
||||
// Start or extend the debounce window.
|
||||
flush_deadline = Some(tokio::time::Instant::now() + STAGE_TRANSITION_DEBOUNCE);
|
||||
|
||||
@@ -20,7 +20,6 @@ pub(super) mod route;
|
||||
|
||||
pub use format::{
|
||||
format_blocked_notification, format_error_notification, format_stage_notification,
|
||||
stage_display_name,
|
||||
};
|
||||
pub use io::spawn_notification_listener;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user