story-kit: merge 261_story_bot_notifications_when_stories_move_between_stages
This commit is contained in:
@@ -17,10 +17,13 @@
|
||||
|
||||
mod bot;
|
||||
mod config;
|
||||
pub mod notifications;
|
||||
|
||||
pub use config::BotConfig;
|
||||
|
||||
use crate::io::watcher::WatcherEvent;
|
||||
use std::path::Path;
|
||||
use tokio::sync::broadcast;
|
||||
|
||||
/// Attempt to start the Matrix bot.
|
||||
///
|
||||
@@ -28,8 +31,12 @@ use std::path::Path;
|
||||
/// absent or `enabled = false`, this function returns immediately without
|
||||
/// spawning anything — the server continues normally.
|
||||
///
|
||||
/// When the bot is enabled, a notification listener is also spawned that
|
||||
/// posts stage-transition messages to all configured rooms whenever a work
|
||||
/// item moves between pipeline stages.
|
||||
///
|
||||
/// Must be called from within a Tokio runtime context (e.g., from `main`).
|
||||
pub fn spawn_bot(project_root: &Path) {
|
||||
pub fn spawn_bot(project_root: &Path, watcher_tx: broadcast::Sender<WatcherEvent>) {
|
||||
let config = match BotConfig::load(project_root) {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
@@ -45,8 +52,9 @@ pub fn spawn_bot(project_root: &Path) {
|
||||
);
|
||||
|
||||
let root = project_root.to_path_buf();
|
||||
let watcher_rx = watcher_tx.subscribe();
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = bot::run_bot(config, root).await {
|
||||
if let Err(e) = bot::run_bot(config, root, watcher_rx).await {
|
||||
crate::slog!("[matrix-bot] Fatal error: {e}");
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user