I am a long time git user, we have just started using Alassian Stash here at Ciena.
I am wondering if there is a command line version of initiating a git-pull-request, rather than using the web front end.
As a developer, I am already using git from the command line, after doing a git push, I now have to flip to a browser enter in a bunch of info that was already there in my terminal (branch name, commit comment, etc).
It would be nice if there was a git-pull-request command where a developer could submit the request from the terminal. Perhaps you already have this, but I don't find it in the Docs.
thanks in advance,
Craig...
Hi again Craig,
I've written a Ruby command line helper for Stash. You can find the source, along with installation and usage instructions on Bitbucket:
https://bitbucket.org/atlassian/stash-command-line-tools
Please let me know how you go with it, as I will be continuing to contribute and improve it. Feel free to fork and improve it too! :)
Cheers,
Seb
Seb,
I am getting quite a few ruby errors when attemping to run 'stash configure' or 'stash help' Seems like the gem<-->git connection isn't quite there:
cmiller@onw-cmiller-04:~/ws/staf-tcl$ stash configure
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- git (LoadError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.2/bin/../lib/atlassian/stash/pullrequest.rb:5
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.2/bin/../lib/stash_cli.rb:2
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.2/bin/../lib/stash_cli.rb:2:in `each'
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.2/bin/../lib/stash_cli.rb:2
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.2/bin/stash:4
from /usr/local/bin/stash:19:in `load'
from /usr/local/bin/stash:19
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Justin,
That did the trick to get past that error.
Now I am seeing an error when I try to run the command:
cmiller@onw-cmiller-04:~/ws/staf-tcl$ stash pull-request pull-request-test develop @dreed @dschmidt
error: Repository does not seem to be hosted in Stash. Use --trace to view backtrace
Which makes sense since 'stash configure' did not ask for the repository name to use.
I tried adding the repository to my .stashconfig.yml, but still no joy.
Craig...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The script extracts the project key and repository name by parsing the output of git remote -v. Do you have multiple remotes configured? Eg one to stash and one to somewhere else?
Would you mind posting what the result of `git remote -v` is?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK, I thought it was getting it from the .stashconfig.yml file. Here's the output:
cmiller@onw-cmiller-04:~/ws/staf-tcl$ git remote -v
origin ssh://git@stash.ciena.com:7999/CESTA/staf-tcl.git (fetch)
origin ssh://git@stash.ciena.com:7999/CESTA/staf-tcl.git (push)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure I see it (line 52), the \w+ isn't going to match the hyphen.
thanks, Craig...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, thanks! There is a bug in the repo extraction (I absentmindedly didn't take into account non word characters, thus the hyphen is throwing things off). Let me fix it and deploy a new version of the gem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've updated the regular expression to handle all supported Stash project keys and repository names. If you update the gem, should be all fine. Sorry for that bug, I was rushing to get the script out the door!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Seb. Sorry to be difficult, but now I am getting an SSL issue:
cmiller@onw-cmiller-04:~/ws/staf-tcl$ stash pull-request --trace pull-request-test develop @dreed @dschmidt
/usr/lib/ruby/1.8/net/http.rb:586:in `connect': SSL_connect returned=1 errno=0 state=unknown state: unknown protocol (OpenSSL::SSL::SSLError)
from /usr/lib/ruby/1.8/net/http.rb:586:in `connect'
from /usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
from /usr/lib/ruby/1.8/net/http.rb:542:in `start'
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.3/bin/../lib/atlassian/stash/pullrequest.rb:83:in `create_pull_request'
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.3/bin/stash:82
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.3/bin/../lib/atlassian/stash/git.rb:20:in `ensure_within_git!'
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.3/bin/stash:80
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/command.rb:180:in `call'
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/command.rb:180:in `call'
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/command.rb:155:in `run'
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/runner.rb:402:in `run_active_command'
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/runner.rb:78:in `run!'
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/delegates.rb:7:in `run!'
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/import.rb:10
from /usr/local/bin/stash:19
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Craig, no worries - you're not being difficult. I needed to sort out these problems anyway, unfortunately you're victim to the first user effect - it's what happens when I code outside of work hours :).
I've pushed version 0.1.4 to rubygems, which should fix the ssl issue. Sorry for needing to make so many releases, and thanks for trailing this out! If you're a ruby wizard (I'm not!) feel free to fork the project and customise it, and send it back via a pull request!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Seb. More problems. I think it is because my stash URL is using ssh, not https
cmiller@onw-cmiller-04:~/ws/staf-tcl$ stash --trace pull-request pull-request-test develop @dreed @dschmidt
/usr/lib/ruby/1.8/net/http.rb:2030:in `read_status_line': wrong status line: "SSH-2.0-SSHD-CORE-0.7.0-ATLASSIAN-M2" (Net::HTTPBadResponse)
from /usr/lib/ruby/1.8/net/http.rb:2017:in `read_new'
from /usr/lib/ruby/1.8/net/http.rb:1051:in `request'
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.4/bin/../lib/atlassian/stash/pullrequest.rb:82:in `create_pull_request'
from /usr/lib/ruby/1.8/net/http.rb:543:in `start'
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.4/bin/../lib/atlassian/stash/pullrequest.rb:82:in `create_pull_request'
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.4/bin/stash:82
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.4/bin/../lib/atlassian/stash/git.rb:20:in `ensure_within_git!'
from /var/lib/gems/1.8/gems/atlassian-stash-0.1.4/bin/stash:80
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/command.rb:180:in `call'
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/command.rb:180:in `call'
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/command.rb:155:in `run'
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/runner.rb:402:in `run_active_command'
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/runner.rb:78:in `run!'
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/delegates.rb:7:in `run!'
from /var/lib/gems/1.8/gems/commander-4.1.2/lib/commander/import.rb:10
from /usr/local/bin/stash:19
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When configuring the gem, did you put the server url as accessible by the web browser? i.e. http(s)://stash.mycompany.com/ ? You shouldn't use the SSH url that is used for cloning, as the scripts use the Stash rest api rather than ssh.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Seb,
OK, so I have gone and manually edited the .stashconfig.yml file, but I am still unclear on what URL the command is looking for?
I have used http://stash.mycompany.com, and http://stash.mycompany.com/project/XYZ/repos/myrepo/ and both fail with the following error:
cmiller@onw-cmiller-04:~$ stash pull-request pull-request-test develop @dreed @dschmidt
fatal: Not a git repository (or any parent up to mount parent )
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
error: fatal: Not a git repository. Use --trace to view backtrace
Can you email the correct URL?
thanks,
Craig...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The configuration file needs the Stash URL, i.e. http://stash.mycompany.com/ (not the project and repo structure). The project and repository values are extracted from the push url from your Git repository. This allows you to create pull requests across many repositories in the one Stash instance.
The error you are getting (not a git repository) is because you are running the command from your home directory, rather than from within a working copy of a clone repository from Stash.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My appologies again. Good catch. OK, I am in my repo dir, and trying it again with just the URL you suggested, and I get the following error:
cmiller@onw-cmiller-04:~/ws/staf-tcl$ stash --trace pull-request pull-request-test develop @dreed @dschmidt
Repository "staf-tcl" of project with key "CESTA" has no branch "pull-request-test"
cmiller@onw-cmiller-04:~/ws/staf-tcl$ git branch
develop
* feature/pull-request-test
master
pull-request-test
cmiller@onw-cmiller-04:~/ws/staf-tcl$ git push
Everything up-to-date
cmiller@onw-cmiller-04:~/ws/staf-tcl$
thanks,
Craig..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I suspect that this will be the same error you get in the Stash web ui. You are asking the "pull-request-test" branch to be merged into the "develop" branch. Your local repository has branches "feature/pull-request-test" and "pull-request-test". You've only checked if the former (which is the checked out branch) has been pushed to the repository. Ensure that the branch "pull-request-test" has been pushed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good news, Seb. It is working!
However, in discussing with my Dev group, they don't like that the stash password is stored in the clear (in the yml file). Is there a way to have the gem ask for the password (with no echo), much like sudo does?
thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I had added this earlier, and for some reason the comment was lost.
The good news is that the pull-request too works! However it stores the stash server password in the clear, which is usually not a good idea.
Is it possible to have the pull-request tool prompt the user for the stash server password? This would eliminate the requirement to store the password.
thanks,
Craig...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, this is already done. If you don't provide a password in the configuration stage, the password will be prompted.
Read more here: http://blogs.atlassian.com/2012/11/stash-pull-requests-from-the-command-line/
ps - maybe email is a better way to continue communication, I feel that we are pushing answers to its limits! sruiz@atlassian.com if you want to continue chatting!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Craig, I had this problem too (though I was using JRuby so it looked a little different). Running "gem install git" resolved the problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Craig - I'm currently working on such a script. I hope to release it in a day or two.
Do you have any requirements or suggestions on how you might want to invoke the script - I'm open to suggestions! It currently works as follows:
$ git create-pr [sourcebranch] target [@reviewer1 @reviewer2]
Thoughts?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Seb,
That is great. It looks like git create-pr would already figure out the branch name, is there a way to pick up the last commit comment (perhaps via commit show)?
I look forward to give the script a try when you are ready.
thanks,
Craig...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.