Skip to content

feat(commands/mr/mrutils): add OWNER:branch support

Kerri Miller requested to merge github/fork/maxice8/owner-branch-support into trunk

Created by: maxice8

Description

This adds support for querying Merge Requests via '[OWNER:]branch'.

Users can ask mr view <branch>, and it will look for a merge request with the source branch of .

If it finds none then error out. If it finds only one then it returns the merge request to the user. If it finds more than one it then prompts the user to pick one of the merge requests and returns the picked one.

If the user passes the optional OWNER: field then it also tries to it to the username of the creator of the merge request.

Example: The user passes profclems:foo

It will search all merge requests for ones with the source branch foo

If it finds none then it errors out. If it finds one it tries to match the Author.Username to profclems, returning it if it matches or erroring out if it doesn't. If it finds more than one, it checks if any of the merge requests matches the Author.Username field and if matched it returns it otherwise it errors out.

This should affect all programs that uses mrutils.GetOpenMRForBranch, which while not directly used by any of the commands, it is always called when the functions mrutils.MRsFromArgs, mrutils.MRFromArgsWithOpts and mrutils.MRFromArgs are used.

Users of mrutils.MRFromArgs:

  • commands/mr/revoke/mr_revoke.go
  • commands/mr/update/mr_update.go
  • commands/mr/subscribe/mr_subscribe.go
  • commands/mr/todo/mr_todo.go
  • commands/mr/rebase/mr_rebase.go
  • commands/mr/note/mr_note_create.go
  • commands/mr/mrutils/mrutils.go
  • commands/mr/merge/mr_merge.go
  • commands/mr/unsubscribe/mr_unsubscribe.go
  • commands/mr/issues/mr_issues.go
  • commands/mr/approvers/mr_approvers.go
  • commands/mr/approve/mr_approve.go
  • commands/mr/diff/diff.go

Users of mrutils.MRsFromArgs:

  • commands/mr/close/mr_close.go
  • commands/mr/reopen/mr_reopen.go
  • commands/mr/delete/mr_delete.go

Users of mrutils.MRFromArgsWithOpts:

  • commands/mr/view/mr_view.go

I have filtered out commands/mr/mrutils/mrutils.go because some of the functions above use the functions below

Related Issue

Resolves #440 (closed)

How Has This Been Tested?

See screenshots for testing. Needs more extensive testing with other commands.

Screenshots (if appropriate):

Matching a number

image

Matching a branch name that matches a single MR (without and with OWNER: and failure to match due to bad OWNER:)

image

Matching branch with multiple MRs but filtering interactively

image image

Matching branch with multiple MRs but filtering by OWNER:

image

Failure to match a branch with multiple MRs due to bad OWNER:

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation
  • Chore (Related to CI or Packaging to platforms)

Merge request reports