#[allow(clippy::wildcard_imports)]
use super::*;
pub(super) fn require_relation_kind(
args: &Value,
key: &str,
) -> std::result::Result<crate::relationships::RelationKind, Value> {
let advice = format!("pass `{key}` blocks|blocked_by|duplicates|related");
let Some(value) = args.get(key).filter(|v| !v.is_null()) else {
return Err(error_result(
crate::relationships::Diagnostic::unknown_kind(
"kind",
format!("relation type required: {advice}"),
)
.to_string(),
));
};
let Some(raw) = value.as_str() else {
return Err(error_result(format!(
"invalid input: `{key}` must be a string naming one of blocks, blocked_by, duplicates, related"
)));
};
crate::commands::link::require_kind_named(Some(raw), &advice)
.map_err(|e| error_result(crate::error::render_error(&e)))
}
pub(super) fn relationship_value(rel: &crate::relationships::Relationship) -> Value {
json!({
"id": rel.id,
"from": rel.from,
"to": rel.to,
"kind": rel.kind.as_str(),
"display": rel.display,
})
}
pub(super) fn resolve_number(store: &Store, raw: &str) -> std::result::Result<u32, ()> {
store
.get(crate::commands::parse_selector(store, raw).map_err(|_| ())?)
.map(|i| i.number)
.map_err(|_| ())
}
pub(super) fn with_graph<T, F>(store: &Store, f: F) -> std::result::Result<T, Value>
where
F: FnOnce(&crate::relationships::RelationshipGraph<'_>) -> std::result::Result<T, Value>,
{
let (issues, done_column) = store
.graph_source()
.map_err(|e| error_result(crate::error::render_error(&e)))?;
let graph = crate::commands::graph_over(&issues, &done_column);
f(&graph)
}
pub(super) fn with_number_resolution(
store: &Store,
raw: &str,
not_found: impl FnOnce() -> Value,
) -> Value {
match crate::commands::parse_selector(store, raw) {
Ok(_) => not_found(),
Err(e) => error_result(crate::error::render_error(&e)),
}
}
pub(super) struct HierarchySnapshot {
pub(super) index: crate::hierarchy::HierarchyIndex,
pub(super) issues: Vec<Issue>,
pub(super) done_column: String,
}
pub(super) fn hierarchy_snapshot(store: &Store) -> std::result::Result<HierarchySnapshot, ()> {
let (index, issues, done_column) = crate::commands::parent::source(store).map_err(|_| ())?;
Ok(HierarchySnapshot {
index,
issues,
done_column,
})
}
pub(super) fn required_number(store: &Store, args: &Value) -> std::result::Result<u32, ()> {
let raw = req_string(args, "issue")?;
resolve_number(store, &raw)
}
pub(super) fn missing_issue(number: u32) -> Value {
error_result(
crate::error::TixError::NotFound(format!("issue #{number} is not in the current snapshot"))
.to_string(),
)
}