Skip to content

Make mr-iid optional: auto-select single MR or prompt interactively #295

@mglaman

Description

@mglaman

Context

PR #293 added the mr:diff, mr:files, mr:status, and mr:logs commands. All of them require mr-iid as a positional argument. In practice, most issues have only one open MR, making the argument redundant noise.

Proposed behaviour

  • Zero MRs — exit with a clear error message.
  • One open MR — use it automatically (no argument needed).
  • Multiple open MRs — in interactive mode, present a choice prompt (same pattern as issue:checkout branch selection); in non-interactive mode, list the available IIDs and exit with an error asking the user to specify one.

Implementation notes

  • MrCommandBase::initialize() already resolves the issue NID and has access to $this->client and a GitLabClient. It can call ListMergeRequestsAction to fetch open MRs when mr-iid is not supplied.
  • mr-iid must stay InputArgument::OPTIONAL (Symfony disallows a required argument after an optional nid), so the runtime validation in initialize() is the right place to add the auto-selection logic.
  • The interactive prompt should use ChoiceQuestion on $mr->iid — $mr->title, consistent with the issue:checkout pattern.

Follow-up to

PR #293

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions