git-open
git-open copied to clipboard
Add a --new-pr flag to open pull-request page
My common workflow is:
- create a branch, commit, push
-
git open
- click on "Compare & pull request" button
- 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?
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
: Theref
of the source branch -
targetBranch
: Theref
of the target branch, typicallymaster
, I guess
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
Also noted that #47 and #53 are related to this as well.
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.
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.
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!
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.
gonna try to break apart the usecases:
-
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
'spull-request
command will create the PR entirely on the cmd line.
-
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.
-
checkout PR: there's a PR open and you want to check it out locally.
-
git-extras
'sgit 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:
Given that I think we should close #47 and keep this one on the roadmap. wdyt?
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)
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?
When the
--pr
option is available?
As with most projects run by volunteers, somebody has to do it.
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
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
.