fix(note): keep a piped body when --attach is set
Description
With --attach, glab mr note create, glab mr note draft create, glab mr note update, glab mr note draft update, glab issue note, and glab incident note never read the body from stdin. A piped body was silently dropped and the note held only the attachment links.
All four MR commands and the issuable note command gated NoteBodyFromStdinOrEditor on len(attach) == 0. The new cmdutils.SkipNoteBody narrows that to the two cases that need it:
--attach -: the attachment claims standard input.- An interactive terminal: an attachment-only note must not open the editor.
Update commands now replace the existing body with a piped one and append the links. With empty stdin they keep appending the links to the existing body, as before. Help text is updated and docs/source/ regenerated with make gen-docs. The bundled glab skill now covers --attach with piped bodies and its stdin pitfalls.
Behavior change
--attach is experimental, but scripts may rely on the old "does not read stdin" behavior. With --attach <file> and no --message, standard input that is not a terminal is now read as the body:
- A pipe that stays open makes the command wait until it closes.
- In a
while readloop, the first call consumes the rest of the loop's input as its body. - To post only the attachment (or keep the existing body on
update) from a script, redirect standard input from/dev/null.--message ""does not help, because an empty message counts as no message.
The help text of every affected command says this.
Related Issues
Resolves #8720 (closed)
How has this been tested?
- New unit tests:
SkipNoteBodytable test; non-TTY piped body +--attach <file>formr note create,mr note update,mr note draft create,mr note draft update, andissue note; empty stdin +--attach <file>posts only the reference, and keeps the existing body onmr note update. Existing tests for append-to-existing on update,--attach -, and attachment-only notes on a terminal still pass. - Against a local GDK, every command was run with the pre-change and the new binary, and each note body was read back from the API:
| Command | Input | Before | After |
|---|---|---|---|
mr note create |
body piped + --attach file |
link only | body + link |
mr note create |
empty stdin + --attach file |
- | link only |
mr note create |
PNG piped + --attach - |
- | link only (image uploaded) |
mr note create |
terminal + --attach file |
- | link only, no editor |
mr note update |
body piped / empty stdin | - | replaces / appends to existing |
mr note draft create |
body piped + --attach file |
link only | body + link |
mr note draft update |
body piped / empty stdin | - | replaces / appends to existing |
issue note |
body piped + --attach file |
link only | body + link |
incident note |
body piped + --attach file |
- | body + link |
- The documented script behavior, also on the local GDK:
| Scenario | Result |
|---|---|
sleep 6 | glab mr note create 1 --attach f |
glab takes 6.3s, link only |
same with </dev/null |
glab takes 0.3s, link only |
while read loop over 3 files |
1 note, the remaining paths become its body |
same loop with </dev/null |
3 notes, link only each |
mr note update / draft update with </dev/null |
existing body kept, link appended |