Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

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

Merged
merged 1 commit into from
Dec 29, 2020
Merged

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

merged 1 commit into from
Dec 29, 2020

Conversation

maxice8
Copy link
Collaborator

@maxice8 maxice8 commented Dec 29, 2020

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

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)

Copy link
Owner

@profclems profclems left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on!

commands/mr/mrutils/mrutils.go Outdated Show resolved Hide resolved
@profclems profclems added enhancement New feature or request cmd: issue Related to issues management labels Dec 29, 2020
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 <branch>.

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.
@maxice8
Copy link
Collaborator Author

maxice8 commented Dec 29, 2020

I have reorgnized, instead of lots of ifs we just check if len(mrs) == 0 and error out then continue without needing to check any if conditions

Copy link
Owner

@profclems profclems left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@profclems profclems merged commit 369bfe7 into profclems:trunk Dec 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cmd: issue Related to issues management enhancement New feature or request size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support OWNER:branch for querying Merge Requests
2 participants