If you want to create a Pull Request from the command line, you can use the REST API :
curl -s -u USER:PASSWD -X POST -H 'Content-Type: application/json' -d 'JSON_struct_with_data' http://SERVER:PORT/rest/api/1.0/projects/PRJKEY/repos/REPONAME/pull-requests
Check the doc of REST API for the details on the JSON data block.
Ouch! I get a lot of groans about the the arcane Gerrit syntax (git push origin HEAD:refs/for/MAIN) and the above is not an improvement.
I was hoping that there was something no more complicated in terms of syntax, configurations, required tools to be installed, passwords, etc. than Gerrit for creating a Bitbucket pull requests.
I can't see anything in that link that shows me how to create a pull request from the command line. I have created pull requests in the Bitbucket web-interface, I've downloaded pull requests from the command line, but I've never found a way to create pull requests from the command line.
The best option is probably to use a couple different tools developed for Stash and/or BItBucket Cloud to do this. The REST API should be similar between them (even though their codebases aren't necessarily the same).
See the excellent utilities I came across from this StackOverflow answer.
the Attlassian team have stash (ruby): https://bitbucket.org/atlassian/stash-command-line-tools
Zhemao has bitbucket-cli (python): https://bitbucket.org/zhemao/bitbucket-cli
Good spot. It is also easy to install them via `gem install atlassian-stash`. Once you've run `stash configure` you can easily operate on a large number of repos in a loop if you are dealing with a massive find/replace for example.
Sadly it only operates on https remote-url configured repos even though it should be able to map ssh:// or git repos to the SSH counterpart since the `stash configure` requires the web URL and the repo URL should largely match.
Given a local folder like PROJECTNAME if you are updating a duplicated entry across multiple repositories you can `cd PROJECTNAME` and then run the script below (assuming you setup the `git create-pull-request` alias.
for repo in `ls -A`; do
git remote set-url origin https://stash.internal:8444/scm/PROJECTNAME/$(basename $(pwd)).git ;
git create-pull-request branches/JIRA-123 master @reviewer1 @reviewer2 ;
git remote set-url origin ssh://email@example.com:7999/PROJECTNAME/$(basename $(pwd)).git;
popd 2>&1 >/dev/null ;
I am getting this:
/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::NIL is deprecated
/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::Data is deprecated
/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::TRUE is deprecated
/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::FALSE is deprecated
/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::Fixnum is deprecated
/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::Bignum is deprecated
/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::TimeoutError is deprecated
Traceback (most recent call last):
11: from /var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/import.rb:10:in `block in <top (required)>'
10: from /var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/delegates.rb:8:in `run!'
9: from /var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/runner.rb:82:in `run!'
8: from /var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/runner.rb:422:in `run_active_command'
7: from /var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/command.rb:155:in `run'
6: from /var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/command.rb:180:in `call'
5: from /var/lib/gems/2.5.0/gems/atlassian-stash-0.7.0/bin/stash:142:in `block (2 levels) in <top (required)>'
4: from /var/lib/gems/2.5.0/gems/atlassian-stash-0.7.0/lib/atlassian/stash/git.rb:50:in `ensure_within_git!'
3: from /var/lib/gems/2.5.0/gems/atlassian-stash-0.7.0/bin/stash:144:in `block (3 levels) in <top (required)>'
2: from /var/lib/gems/2.5.0/gems/atlassian-stash-0.7.0/lib/atlassian/stash/pull_request.rb:101:in `create_pull_request'
1: from /usr/lib/ruby/2.5.0/json/common.rb:156:in `parse'
/usr/lib/ruby/2.5.0/json/common.rb:156:in `parse': 765: unexpected token at '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> (JSON::ParserError)
<p>The document has moved <a href="https://bitbucket...">here</a>.</p>
Any idea how to resolve it?
You are calling an URL that redirects to another one for some (hopefully good) reason.
The library you are using is not handling this redirect automatically and you get the response "302 - what you are looking for is not here, but it's there".
So you should either find the option in the library you are using to follow the redirection when it occurs, or you must check first your HTTP response code before processing the HTTP response message.
On HTTP code 302, you should call the new URL.
Still no news matching Gerrit w.r.t. ease of use on this?
All I want is:
We’ve been building a plugin to integrate Bitbucket Server and Jenkins CI, and I’m excited to announce that our alpha is ready to download and install. It lets you seamlessly configure a Jenkins job ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events