(a1a5d69) Add tags to a ticket with append --tags, keeping the ones it carries, and bump to 0.32.18
`set --tags` writes the whole field, so adding one tag to a ticket that
already carries some meant reading it first and retyping every one of
them. 30a2b34 wrote that down in the skill as the way to do it; this is
the flag that makes it unnecessary.
The merge is idempotent and ordered. A tag the ticket already carries is
reported as no change rather than added twice, which is the point of the
flag: the caller does not have to know what is there. A new one goes on
the end in the order it was given rather than sorting the field under
whoever last touched it. Values are split on commas the way the stored
field is, so `--tags "bug, tui"` names two tags and matches the two a
ticket carrying them already holds; without that the pair would land as
a single tag nothing can filter by and would not match itself on the
next call. `split_tags` is that rule, lifted out of `parse_tags` so the
argument and the field are separated by the same code.
It writes the same `Kind::Tags` entry `set --tags` writes, so `--actor`
and `--actor-from-git` come with it. Tags are logged wherever they move,
and the one command that adds to them without replacing them would
otherwise be the one tag change the log missed. The before and after are
read off the field rather than off the flag, so an append of `beta` onto
`alpha` reads as the pair and not as what the call asked for.
`non_empty` rather than the `clearable` that `set --tags` takes: that
message names `--clear`, and `append` has none, so it would send the
caller looking here for a flag that is `set`'s. A value that is only
separators reaches the handler and is refused there, in the words
`appended_items` refuses an all-blank section with. Emptying the field
stays `set --clear tags`.
`TAG_FLAGS` becomes pairs of command and flag, because `ls --tag` and
`append --tags` are spelled differently and one rule naming both options
would tell fish that each command accepts the other's. `add --tags` and
`set --tags` deliberately get no value rule and are recorded in the
test's `TAG_LIST_FLAGS` instead: they take the whole list, so the token
at the cursor is `bug,tui` and fish replaces a token entire, throwing
away what is already typed. The honesty test now walks `tag` and `tags`
both, so the next tag argument has to say which of the two it is.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
b4534eb86d
commit
7470255a22
@@ -1135,12 +1135,83 @@ pub fn cmd_append(args: &AppendArgs, start: &Path, sink: &mut Sink) -> Result<()
|
||||
changed.push(section.label);
|
||||
}
|
||||
|
||||
// Through `apply`, unlike the sections above: appending a section always adds
|
||||
// something, and appending a tag the ticket already carries is the no-op this flag
|
||||
// exists to make free.
|
||||
if !args.tags.is_empty() {
|
||||
let next =
|
||||
set_metadata_field(&content, "Tags", &appended_tags(&content, &args.tags)?, &title)?;
|
||||
apply(&mut content, &mut changed, "tags", next);
|
||||
}
|
||||
|
||||
// The only way to reach here with nothing to write is a `--tags` the ticket already
|
||||
// satisfied, since every other field on this command adds or refuses. Reported in the
|
||||
// words `set` uses for the same answer.
|
||||
if changed.is_empty() {
|
||||
report(sink, &[], &title, "Appended to")?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
save_ticket(&worklane_dir, &status, &uuid, &title, None, &content)?;
|
||||
|
||||
// Tags are logged wherever they change, so the one command that adds to them without
|
||||
// replacing them logs too. Same shape as `set`'s, down to the before and after being
|
||||
// read off the field rather than off the flag: what the entry records is where the
|
||||
// field went, not what this call asked for.
|
||||
if changed.contains(&"tags") {
|
||||
write_entry(
|
||||
&worklane_dir,
|
||||
&uuid,
|
||||
Kind::Tags,
|
||||
&change(
|
||||
&parse_ticket_field(&original, "Tags"),
|
||||
&parse_ticket_field(&content, "Tags"),
|
||||
),
|
||||
&resolve_actor(args.actor.as_deref(), args.actor_from_git),
|
||||
"",
|
||||
)?;
|
||||
}
|
||||
|
||||
report(sink, &changed, &title, "Appended to")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The ticket's tags with the call's merged onto the end, or the refusal for a call that
|
||||
/// named none.
|
||||
///
|
||||
/// A tag the ticket already carries is not added a second time, which is the whole
|
||||
/// difference from `set --tags`: appending means the caller does not have to know what is
|
||||
/// there already, so naming one that is reports no change rather than doubling it. New
|
||||
/// ones go on the end in the order they were given rather than sorted, so the field goes
|
||||
/// on reading as what was added when.
|
||||
///
|
||||
/// The values are split on commas the way the stored field is, so `--tags "bug, tui"`
|
||||
/// names two tags and matches the two a ticket carrying them already holds. Without that
|
||||
/// the pair would land as a single tag nothing can filter by, which is what `tag_value`
|
||||
/// refuses outright for the vocabulary; here it is split instead, because `set --tags`
|
||||
/// takes the comma form on this same field and refusing it on its counterpart would be a
|
||||
/// trap.
|
||||
///
|
||||
/// A call whose every value comes out blank is refused rather than written, the way
|
||||
/// [`appended_items`] refuses one: `--tags ","` names nothing, and writing the field back
|
||||
/// unchanged would report an append that never happened. Emptying the field is
|
||||
/// `set --clear tags`.
|
||||
fn appended_tags(content: &str, values: &[String]) -> Result<String> {
|
||||
let added: Vec<String> = values.iter().flat_map(|value| split_tags(value)).collect();
|
||||
if added.is_empty() {
|
||||
return Err(anyhow!("Nothing to append to the tags: every value given was blank"));
|
||||
}
|
||||
|
||||
let mut tags = parse_tags(content);
|
||||
for tag in added {
|
||||
if !tags.contains(&tag) {
|
||||
tags.push(tag);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(tags.join(", "))
|
||||
}
|
||||
|
||||
/// Record a relation from one ticket to another.
|
||||
///
|
||||
/// One side is written and the inverse is derived wherever it is shown. `blocked by`
|
||||
|
||||
Reference in New Issue
Block a user