Skip to content

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

Merged
mglaman merged 2 commits intomainfrom
copilot/make-mr-iid-optional
Mar 25, 2026
Merged

Make mr-iid optional: auto-select single MR or prompt interactively#332
mglaman merged 2 commits intomainfrom
copilot/make-mr-iid-optional

Conversation

Copy link
Contributor

Copilot AI commented Mar 24, 2026

mr:diff, mr:files, mr:status, and mr:logs all require mr-iid as a positional argument, which is redundant noise when an issue has only one open MR.

Changes

  • MrCommandBase::initialize() — when mr-iid is omitted on the NID path, calls ListMergeRequestsAction to fetch open MRs and applies the following logic:
State Behaviour
Zero open MRs RuntimeException with clear message
One open MR Auto-selects; prints Auto-selected MR !N: title
Multiple MRs, non-interactive Lists !iid — title to stderr, throws asking user to specify
Multiple MRs, interactive ChoiceQuestion on !iid — title (same pattern as issue:checkout)
  • MrCommandBaseTest — verifies both nid and mr-iid arguments remain OPTIONAL.

Example

# Before: always required
drupalorg mr:diff 3383637 7

# After: omit mr-iid when there's only one open MR
drupalorg mr:diff 3383637
# → Auto-selected MR !7: Fix the regression in node access
Original prompt

This section details on the original issue you should resolve

<issue_title>Make mr-iid optional: auto-select single MR or prompt interactively</issue_title>
<issue_description>## 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</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI changed the title [WIP] Make mr-iid optional and improve user experience Make mr-iid optional: auto-select single MR or prompt interactively Mar 24, 2026
Copilot AI requested a review from mglaman March 24, 2026 23:33
@mglaman mglaman marked this pull request as ready for review March 25, 2026 15:13
@mglaman mglaman merged commit 740564c into main Mar 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants