feat(mr): move mr note create --draft and mr note publish to mr note draft

Description

Moves pending review comments (draft notes) to a glab mr note draft noun that owns the whole review lifecycle, as agreed in #8574 (closed).

Command Replaces
glab mr note draft create glab mr note create --draft
glab mr note draft list new (design from !3963 (closed))
glab mr note draft update new (#8569 (closed))
glab mr note draft delete new (design from !3963 (closed))
glab mr note draft publish glab mr note publish

Breaking, experimental surface: glab mr note create --draft and glab mr note publish are removed with no deprecation period. Both were marked (EXPERIMENTAL). Please call this out in the release notes.

Notes for reviewers:

  • draft update sends the draft's existing position back with the new body. The API clears the position otherwise (gitlab#631434 (closed)). Drafts on images are refused, because client-go does not decode image coordinates.
  • --file/--line/--old-line resolution is shared by mr note create and draft create through mrutils.DiffPosition.
  • Flag-only checks (--line without --file, short --reply prefix, missing --yes when non-interactive) run before any API call or editor prompt.
  • glab mr note list now prints on <path> for file-level comments, which previously showed no location.
  • Test_MrNotePublish_Integration moved to draft/publish as TestDraftPublish_Integration and creates its fixture with draft create.

Resolves #8574 (closed) Closes #8569 (closed)

Also carries over the list/discard design from !3963 (closed) under the new noun.

How has this been tested?

  • make test: 5532 tests pass.
  • golangci-lint run --new-from-rev=origin/main, scripts/comment-overlap, make check-args check-embed, markdownlint, and vale: clean.
  • TestDraftPublish_Integration passes against a local GDK.
  • End to end against a local GDK: created general, single-line, line-range, removed-line, reply, stdin, and attachment-only drafts; listed them as text, JSON, and with --file; updated each kind and confirmed through the API that positions (including line_range line codes) were preserved, while a raw PUT without position wiped them; deleted with and without --yes; published with -m, --internal, and --reviewer-state and confirmed the drafts landed as diff notes on the original lines.

Test locally

You need a GitLab instance you can write to (GDK works) and an open MR with a diff. Check out the MR's source branch in a local clone, so commands resolve the MR from the current branch.

# In this repo
make build
G="$PWD/bin/glab"

# In a clone of the test project, on the MR's source branch
$G mr note draft create -m "General comment"
$G mr note draft create --file <path> --line <N> -m "Diff comment"
$G mr note draft create --file <path> --line <N>:<M> -m "Range comment"
id=$($G mr note draft create --file <path> --old-line <N> -m "Removed line"); echo "$id"
disc=$($G mr note list -F json | jq -r '.[] | select(.notes[0].system | not) | .id[0:8]' | head -1)
$G mr note draft create --reply "$disc" -m "Reply"

$G mr note draft list
$G mr note draft list --file <path>
$G mr note draft list -F json | jq '.[] | {id, position}'

# The comment should stay on the same line (check the MR page or the JSON above)
$G mr note draft update "$id" -m "Edited"

# Prompts; pass --yes to skip. Non-interactive without --yes must fail before any API call.
$G mr note draft delete <draft-note-id>

$G mr note draft publish -m "Summary" --reviewer-state requested_changes
$G mr note draft list                 # "No pending review comments found."
$G mr note list --type diff           # published diff comments on the original lines

# The old surface is gone
$G mr note create -m x --draft        # unknown flag: --draft

Integration test (needs the cli-automated-testing/test project on the target instance):

GITLAB_TEST_HOST=<url> GITLAB_TOKEN_TEST=<token>   go test -tags=integration ./internal/commands/mr/note/draft/publish/ -run TestDraftPublish_Integration

Screenshots (if appropriate):

Demo recorded against a local GDK:

Edited by Andrei Zubov

Merge request reports

Loading
Loading