git-open icon indicating copy to clipboard operation
git-open copied to clipboard

Add a --new-pr flag to open pull-request page

Open paulirish opened this issue 7 years ago • 13 comments

My common workflow is:

  1. create a branch, commit, push
  2. git open
  3. click on "Compare & pull request" button
  4. once the page loads, fill it out and submit PR

There's not much value in me opening the branch page. ideally a flag like --new-pr would open the create-a-pull-request link directly.

So:

env BROWSER=echo git open
# https://github.com/GoogleChrome/lighthouse/tree/bootuptime-edit

env BROWSER=echo git open --new-pr
# https://github.com/GoogleChrome/lighthouse/compare/bootuptime-edit?expand=1

anyone else interested in this one? (looks like #64 basically wanted the same thing)

do bitbucket/gitlab/vsts have similar URLs?

paulirish avatar Oct 31 '17 22:10 paulirish

For Bitbucket, it looks like this:

https://server/projects/PROJECTNAME/repos/REPONAME/pull-requests?create&sourceBranch=refs%2Fheads%2FSOURCEBRANCH&targetBranch=refs%2Fheads%2Fmaster

The following query parameters are added to the pull-requests URL:

  • create: no value
  • sourceBranch: The ref of the source branch
  • targetBranch: The ref of the target branch, typically master, I guess

nwinkler avatar Nov 01 '17 07:11 nwinkler

This is what is shown when you push a new branch to a GitLab server (our internal gitlab in this case, with faked domain name)

$ git push origin test-branch
Counting objects: 3, done.
Writing objects: 100% (3/3), 281 bytes | 281.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for test-branch, visit:
remote:   https://gitlab.domain.info/Frank/test/merge_requests/new?merge_request%5Bsource_branch%5D=test-branch
remote:
To gitlab.domain.info:Frank/test.git
 * [new branch]      test-branch -> test-branch

Tested with our internal gitlab as well as on gitlab.com, for merge requests from a forked repo and for merge requests within one repo. The URL stays the same.

Note that GitLab doesn't use the term Pull Request, but the term Merge Request

ffes avatar Nov 01 '17 11:11 ffes

Also noted that #47 and #53 are related to this as well.

ffes avatar Nov 01 '17 11:11 ffes

When I pushed an additional commit to a existing merge request, the GitLab server gives this response:

$ git push origin add-mobile-docs
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 2.54 KiB | 2.54 MiB/s, done.
Total 5 (delta 2), reused 0 (delta 0)
remote:
remote: View merge request for add-mobile-docs:
remote:   https://gitlab.domain.info/docs/Kopano/merge_requests/1
remote:
To gitlab.domain.info:docs/Kopano.git
   61bd71b..67de78d  add-mobile-docs -> add-mobile-docs

As far as I know, there is no way to determine this id from anything we know of in the local git repo.

ffes avatar Nov 03 '17 12:11 ffes

About the name of the option... --issue opens the webpage of the issue. --pr is planned to open a new PR based on the current branch name.

To think about the future and flags that might get added: is --new-pr not a better name for this feature?

This way --new-issue (somebody could want/make this) could open the new issue page.

ffes avatar Nov 03 '17 12:11 ffes

To think about the future and flags that might get added: is --new-pr not a better name for this feature?

@ffes good call. yes, that's more appropriate. i updated the title. maybe it'll be --new-pr and -r

https://gitlab.domain.info/Frank/test/merge_requests/new?merge_request%5Bsource_branch%5D=test-branch

perfect. thanks!

paulirish avatar Nov 03 '17 16:11 paulirish

This a duplicate of #47 now for the most part?

As I said there git-extras has 2 commands for git pr and git mr, https://github.com/tj/git-extras which we can reference.

However since this just opens a link in the browser I'm more for this than #47 specifically since for that one it was retrieving info using the api while this one you don't need to.

derimagia avatar Feb 04 '18 17:02 derimagia

gonna try to break apart the usecases:

  1. new PR: pushed brand new branch and i want to create a PR for it
    • This issue (#103) is about opening the webpage that lets you create the branch
    • git-extras's pull-request command will create the PR entirely on the cmd line.
  2. view PR: pushed new commits to a branch with a PR open. I want to open the existing PR page for it
    • The majority of issue #47 is about this usecase
    • this is kinda similar to our --issue flag, but instead of viewing the source issue (that the branch is named after), we're viewing the PR.
  3. checkout PR: there's a PR open and you want to check it out locally.
    • git-extras's git pr does this for a given PR number
    • hub checkout does this for a pull request URL

I think we can all agree 3 is not for this project. (I personally use hub checkout for it)

I'm more for this than #47

Aye. I'm also more excited for the new pr usecase versus the view pr one.

Additionally, view pr is just a click away if we have new pr implemented:

image

Given that I think we should close #47 and keep this one on the roadmap. wdyt?

paulirish avatar Feb 04 '18 21:02 paulirish

Agreed! I went ahead and closed #47 (I added git-repo for to the suggestion list because it has a lot of more complicated, api-specific features). Keeping this one open for opening the link to a new PR (or MR) / compare branch page)

derimagia avatar Mar 10 '18 17:03 derimagia

About the name of the option... --issue opens the webpage of the issue. --pr is planned to open a new PR based on the current branch name.

To think about the future and flags that might get added: is --new-pr not a better name for this feature?

This way --new-issue (somebody could want/make this) could open the new issue page.

When the --pr option is available?

fogmoon avatar Feb 21 '19 03:02 fogmoon

When the --pr option is available?

As with most projects run by volunteers, somebody has to do it.

ffes avatar Feb 21 '19 06:02 ffes

As with most projects run by volunteers, somebody has to do it.

Sorry for my naive question. Just for I saw the planned word.

I use the following code to open Github pull requests list. Hope it's helpful for who use Github.

$ git diff $ZSH_CUSTOM/plugins/git-open/git-open
@@ -17,6 +17,7 @@ git open [remote] [branch]

   Available options are
 i,issue!      open issues page
+p,pr!         open prs gage
 "

 # https://github.com/koalaman/shellcheck/wiki/SC1090
@@ -25,11 +26,13 @@ SUBDIRECTORY_OK='Yes' . "$(git --exec-path)/git-sh-setup"

 # Defaults
 is_issue=0
+is_pr=0
 protocol="https"

 while test $# != 0; do
   case "$1" in
   --issue) is_issue=1;;
+  --pr) is_pr=1;;
   --) shift; break ;;
   esac
   shift
@@ -162,6 +165,9 @@ IFS='/' read -r -a pathargs <<<"$urlpath"
 if (( is_issue )); then
   # For issues, take the numbers and preprend 'issues/'
   providerBranchRef="/issues/${branch//[^0-9]/}"
+elif (( is_pr )); then
+  # For prs, just open pr list page
+  providerBranchRef="/pulls/"
 else
   # Make # and % characters url friendly
   #   github.com/paulirish/git-open/pull/24

fogmoon avatar Feb 23 '19 04:02 fogmoon

As you mentioned yourself, this opens the pull requests list only on GitHub.

But this issue is actually about opening a new PR when your are in your local feature branch and just have pushed that branch to the remote repo.

If you make the option --prs (note the extra s) and open a new PR, we will work from there. I would love to have GitLab support as well, since that is what I use in my daily workflow at the office.

Also know that --pr is suggested to open the page of the current PR you are working on in your specific named feature branch, similar to --issue.

ffes avatar Feb 23 '19 07:02 ffes