(4179958) Add a Relations section for blocked by, regression of and relates to, and bump to 0.11.0
`relate` is the only writer of the section, the way `chown` is the only writer of Owner: a relation names a target that has to be resolved to a uuid first, so `set` and `append` are deliberately kept out of it. One flag per kind, so an unknown kind is a usage error rather than a line refused on the way back out. One direction is stored and the inverse is derived by a scan. `blocked by` goes on the gated ticket, whose move `mv` now refuses while the target is not done, naming every open blocker; `-f` bypasses it beside the backward and skipping moves. A target that is not on the board warns and allows the move. The rendered block is built outside `content_trim` and passed in, since half of it comes from other tickets. The section is created on demand rather than by `add`, so a ticket written before it existed gains it without being regenerated. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
b56b31d2d9
commit
3085b0226f
+81
-3
@@ -501,16 +501,25 @@ impl Board {
|
||||
fn detail_of(card: &Card) -> Detail {
|
||||
let ticket = &card.ticket;
|
||||
let content = std::fs::read_to_string(&ticket.path).unwrap_or_default();
|
||||
let mut out = content_trim(&content, false);
|
||||
|
||||
let uuid = parse_ticket_field(&content, "ID");
|
||||
let comments = match ticket.path.parent().and_then(|status| status.parent()) {
|
||||
let worklane_dir = ticket.path.parent().and_then(|status| status.parent());
|
||||
|
||||
// Both of these read the tree beside the ticket, and both fall back to nothing: one
|
||||
// unreadable file must not take the board down with it. The relations cost a scan of
|
||||
// the board, paid only while a ticket is open and only on a tick that changed
|
||||
// something, which is what already reloads every card.
|
||||
let relations = worklane_dir
|
||||
.and_then(|dir| relations_block(&content, dir, false).ok())
|
||||
.unwrap_or_default();
|
||||
let comments = match worklane_dir {
|
||||
Some(worklane_dir) => {
|
||||
read_comments(&worklane_dir.join("comments").join(&uuid)).unwrap_or_default()
|
||||
}
|
||||
None => Vec::new(),
|
||||
};
|
||||
|
||||
let mut out = content_trim(&content, false, &relations);
|
||||
|
||||
out.push('\n');
|
||||
out.push_str(&format_comments_with(&comments, false));
|
||||
Detail {
|
||||
@@ -2666,4 +2675,73 @@ mod tests {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// The detail view is the second renderer of a ticket body, so it resolves a
|
||||
/// relation the way `show` does rather than printing the uuid the file stores.
|
||||
///
|
||||
/// The section goes in `extra`, after the metadata, which is not where `relate`
|
||||
/// writes it. Position is the CLI's test to make; this one is about the lookup.
|
||||
#[test]
|
||||
fn the_detail_view_resolves_a_relation_to_a_title() {
|
||||
let dir = board_dir();
|
||||
let target = "22222222-0000-4000-8000-000000000000";
|
||||
write_ticket(&dir, "backlog", target, "The target", "");
|
||||
write_ticket(
|
||||
&dir,
|
||||
"backlog",
|
||||
"11111111-0000-4000-8000-000000000000",
|
||||
"A holder",
|
||||
&format!("\n## Relations\n- blocked by {target}\n"),
|
||||
);
|
||||
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
|
||||
let text = &board.detail.as_ref().expect("no detail").text;
|
||||
assert!(text.contains("blocked by (2222222) The target"), "{text:?}");
|
||||
assert!(!text.contains(target), "the bare uuid was drawn: {text:?}");
|
||||
}
|
||||
|
||||
/// The far end of a relation stores nothing, so the board derives it too.
|
||||
#[test]
|
||||
fn the_detail_view_derives_the_other_end() {
|
||||
let dir = board_dir();
|
||||
let holder = "11111111-0000-4000-8000-000000000000";
|
||||
write_ticket(
|
||||
&dir,
|
||||
"backlog",
|
||||
holder,
|
||||
"A holder",
|
||||
"\n## Relations\n- blocked by 22222222-0000-4000-8000-000000000000\n",
|
||||
);
|
||||
write_ticket(&dir, "backlog", "22222222-0000-4000-8000-000000000000", "The target", "");
|
||||
|
||||
let mut board = one_board(&dir);
|
||||
// The holder sorts first by title, so the target is the card below it.
|
||||
board.select_card(1, SCREEN);
|
||||
board.toggle_detail();
|
||||
|
||||
let text = &board.detail.as_ref().expect("no detail").text;
|
||||
assert!(text.contains("blocks (1111111) A holder"), "{text:?}");
|
||||
}
|
||||
|
||||
/// The CLI refuses a relations line it cannot read, naming the ticket. The board
|
||||
/// cannot: one hand-edited file must not take every other card down with it.
|
||||
#[test]
|
||||
fn a_relations_line_that_cannot_be_read_still_draws_the_ticket() {
|
||||
let dir = board_dir();
|
||||
write_ticket(
|
||||
&dir,
|
||||
"backlog",
|
||||
"11111111-0000-4000-8000-000000000000",
|
||||
"A holder",
|
||||
"\n## Relations\n- depends on 22222222-0000-4000-8000-000000000000\n",
|
||||
);
|
||||
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
|
||||
let text = &board.detail.as_ref().expect("no detail").text;
|
||||
assert!(text.contains("A description."), "the body was lost: {text:?}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user