Draft: feat(mr): glab mr note supports all commenting APIs

Description

This mega MR migrates https://gitlab.com/viktomas/note to glab as a POC.

There are 3 user-facing changes that might require a major version release (see the separate section)


  Add a comment or note to a merge request, or resolve/unresolve discussions.                                           
         
  USAGE  
         
    glab mr note [command] [<id> | <branch>] [--flags]                         
            
  EXAMPLES  
            
    # Add a comment to merge request with ID 123                               
    $ glab mr note 123 -m "Looks good to me!"                                  
                                                                               
    # Add a comment to the merge request for the current branch                
    $ glab mr note -m "LGTM"                                                   
                                                                               
    # Open your editor to compose a multi-line comment                         
    $ glab mr note 123                                                         
                                                                               
    # Pipe a comment from stdin                                                
    $ echo "LGTM" | glab mr note 123                                           
                                                                               
    # Add a diff comment on line 42 of main.go                                 
    $ glab mr note 123 --file main.go --line 42 -m "Needs refactoring"         
                                                                               
    # Add a diff comment on lines 10-15 (multiline range)                      
    $ glab mr note 123 --file main.go --line 10:15 -m "Extract this block"     
                                                                               
    # Add a diff comment on a removed line (old side)                          
    $ glab mr note 123 --file main.go --old-line 7 -m "Why was this removed?"  
                                                                               
    # Add a file-level diff comment (no line specified)                        
    $ glab mr note 123 --file main.go -m "General comment on this file"        
                                                                               
    # Reply to an existing discussion (full or prefix ID)                      
    $ glab mr note 123 --reply abc12345 -m "I agree!"                          
                                                                               
    # Add a confidential internal note                                         
    $ glab mr note 123 --internal -m "Internal feedback for maintainers"       
                                                                               
    # Resolve a discussion by note ID                                          
    $ glab mr note 123 --resolve 3107030349                                    
                                                                               
    # Unresolve a discussion by note ID                                        
    $ glab mr note 123 --unresolve 3107030349                                  
            
  COMMANDS  
            
    delete [<mr-id> | <branch>] <note-id> [--yes] [--flags]      Delete a note from a merge request
    draft [command]                                              Manage draft (unpublished) notes on a merge request
    list [<id> | <branch>] [--flags]                             List discussions on a merge request
    resolve  <discussion-id> [<mr-id> | <branch>]                Resolve a discussion on a merge request
    review [<mr-id> | <branch>] [--flags]                        Batch-Create draft notes from JSON on stdin
    unresolve  <discussion-id> [<mr-id> | <branch>]              Unresolve a discussion on a merge request
    update [<mr-id> | <branch>] <note-id> [-m <body>] [--flags]  Update a note on a merge request
         
  FLAGS  
         
    --file                                                       File path for a diff comment (targets the latest MR diff version).
    -h --help                                                    Show help for this command.
    --internal                                                   Create a confidential internal note (uses flat Notes API).
    --line                                                       Line in the new version: a single number or a range N:M.
    -m --message                                                 Comment or note message.
    --old-line                                                   Line in the old version (for commenting on removed lines).
    --reply                                                      Reply to an existing discussion by ID (full or 8+ char prefix).
    -R --repo                                                    Select another repository. Can use either `OWNER/REPO` or `GROUP/NAMESPACE/REPO` format. Also accepts full URL or Git URL.
    --resolve                                                    Resolve the discussion containing the specified note ID.
    --unique                                                     Don't create a comment or note if it already exists.
    --unresolve                                                  Unresolve the discussion containing the specified note ID.

Known upstream issues

The following two GitLab issues make commenting on MR diffs unreliable:

User-Facing Changes

None of these warrant a major version bump, but stay on the lookout for further breaking changes during implementation.

1. General notes now create threaded discussions

glab mr note -m "text" currently creates a flat, non-resolvable note via the Notes API. After migration, it creates a discussion thread via the Discussions API.

  • Notes become resolvable (they weren't before)
  • Notes become threaded (replies create a thread instead of triggering a type conversion)
  • This matches GitLab web UI behavior

Unlikely to break anyone — scripts would have to be filtering by resolvable: false to notice.

2. --unique checks all notes (not just first page)

Currently --unique only checks the first 30 notes (DefaultListLimit). After migration, it paginates through all notes. This is a bug fix — dedup was silently broken on MRs with 30+ notes.

3. --resolve/--unresolve accept discussion ID in addition to note ID

The existing --resolve <note-id> behavior is preserved. New resolve/unresolve subcommands accept discussion IDs (with 8+ char prefix matching). Additive only.

Resolves ability to add MR comment for specific file and... (#1311 - closed)

How has this been tested?

Screenshots (if appropriate):

Edited by Tomas Vik

Merge request reports

Loading