tix-tracker 0.12.0

A terminal issue tracker: markdown + YAML frontmatter issues with a kanban TUI and CLI
Documentation
#[allow(clippy::wildcard_imports)]
use super::*;

/// `mentions_list`: the local user's pending mentions, as text and as data.
pub(super) fn mentions_list(config: &Config, store: &Store, _args: &Value) -> ToolOutcome {
    let _ = config;
    match cmd_mentions::pending(store) {
        Ok(pending) => {
            let text = if pending.is_empty() {
                "no pending mentions".to_string()
            } else {
                pending
                    .iter()
                    .map(cmd_mentions::line)
                    .collect::<Vec<_>>()
                    .join("\n")
            };
            let rows: Vec<Value> = pending
                .iter()
                .map(|mention| {
                    json!({
                        "id": mention.id,
                        "issue_number": mention.issue_number,
                        "issue_file": mention.issue_file,
                        "body": mention.body,
                        "context": mention.context,
                        "created": mention.created,
                        "state": match mention.state {
                            crate::mentions::MentionState::Unread => "unread",
                            crate::mentions::MentionState::Read => "read",
                        },
                    })
                })
                .collect();
            Ok(success_result(text, json!({ "mentions": rows })))
        }
        Err(e) => Ok(error_result(crate::error::render_error(&e))),
    }
}

/// `mentions_mark_read`: the one mutating mention answer.
pub(super) fn mentions_mark_read(_config: &Config, store: &Store, args: &Value) -> ToolOutcome {
    let id = req_string(args, "id")?;
    match cmd_mentions::mark_read(store, &id) {
        Ok(message) => {
            let mention = cmd_mentions::find(store, &id).ok();
            let value = mention.map_or_else(
                || json!({ "id": id }),
                |mention| {
                    json!({
                        "id": mention.id,
                        "issue_number": mention.issue_number,
                        "state": match mention.state {
                            crate::mentions::MentionState::Unread => "unread",
                            crate::mentions::MentionState::Read => "read",
                        },
                    })
                },
            );
            Ok(success_result(message, value))
        }
        Err(e) => Ok(error_result(crate::error::render_error(&e))),
    }
}

pub(super) fn dispatch(
    config: &Config,
    store: &Store,
    name: &str,
    arguments: &Value,
) -> Option<ToolOutcome> {
    match name {
        "mentions_list" => Some(mentions_list(config, store, arguments)),
        "mentions_mark_read" => Some(mentions_mark_read(config, store, arguments)),
        _ => None,
    }
}