huskies: merge 856
This commit is contained in:
@@ -115,6 +115,65 @@ pub fn format_oauth_accounts_exhausted(earliest_reset_msg: &str) -> (String, Str
|
||||
(plain, html)
|
||||
}
|
||||
|
||||
/// Format an agent-started notification message.
|
||||
///
|
||||
/// Sent when an agent transitions to the Running state.
|
||||
/// Returns `(plain_text, html)` suitable for `ChatTransport::send_message`.
|
||||
pub fn format_agent_started_notification(
|
||||
item_id: &str,
|
||||
story_name: Option<&str>,
|
||||
agent_name: &str,
|
||||
) -> (String, String) {
|
||||
let number = extract_item_number(item_id).unwrap_or(item_id);
|
||||
let name = story_name.unwrap_or(item_id);
|
||||
let plain = format!("\u{1F916} #{number} {name} \u{2014} {agent_name} started");
|
||||
let html = format!(
|
||||
"\u{1F916} <strong>#{number}</strong> <em>{name}</em> \u{2014} {agent_name} started"
|
||||
);
|
||||
(plain, html)
|
||||
}
|
||||
|
||||
/// Format an agent-completed notification message.
|
||||
///
|
||||
/// Sent when an agent finishes processing a story (gates passed or failed).
|
||||
/// Returns `(plain_text, html)` suitable for `ChatTransport::send_message`.
|
||||
pub fn format_agent_completed_notification(
|
||||
item_id: &str,
|
||||
story_name: Option<&str>,
|
||||
agent_name: &str,
|
||||
success: bool,
|
||||
) -> (String, String) {
|
||||
let number = extract_item_number(item_id).unwrap_or(item_id);
|
||||
let name = story_name.unwrap_or(item_id);
|
||||
let (emoji, result) = if success {
|
||||
("\u{2705}", "completed") // ✅
|
||||
} else {
|
||||
("\u{274C}", "failed") // ❌
|
||||
};
|
||||
let plain = format!("{emoji} #{number} {name} \u{2014} {agent_name} {result}");
|
||||
let html = format!(
|
||||
"{emoji} <strong>#{number}</strong> <em>{name}</em> \u{2014} {agent_name} {result}"
|
||||
);
|
||||
(plain, html)
|
||||
}
|
||||
|
||||
/// Extract the first non-empty line from a merge failure reason, truncated to `max_len` chars.
|
||||
///
|
||||
/// Used to produce a compact snippet for chat notifications.
|
||||
pub fn merge_failure_snippet(reason: &str, max_len: usize) -> String {
|
||||
let line = reason
|
||||
.lines()
|
||||
.find(|l| !l.trim().is_empty())
|
||||
.unwrap_or(reason);
|
||||
let mut chars = line.chars();
|
||||
let truncated: String = chars.by_ref().take(max_len).collect();
|
||||
if chars.next().is_some() {
|
||||
format!("{truncated}\u{2026}") // append …
|
||||
} else {
|
||||
truncated
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user