简体   繁体   中英

How to submit pull request via CLI to Bitbucket?

What is the simplest way to perform a git pull request via CLI. I am tired of going to Bitbucket the whole time to create a pull request manually. Which is quite simple indeed:

  1. Pull requests tab
  2. Create pull request
  3. Select source and destiny branches (edit comments, reviewers, etc)
  4. Confirm

Pretty simple. How can I achieve this behavior through cli? Let's say, in my teams' repository, I want to perform a PR from develop to master branch.

I have been checking documentation and it doesn't seem so obvious. It asks me to choose a starting commit and, in the previous steps I described, I don't even get the chance to choose which commit should the PR start from.

You could use a command line tool like curl on the bitbucket rest api . How to create a pull request with HTTP POST is documented here .

Give it a try:

 curl \ 
 -X POST \
 -H "Content-Type: application/json" \
 -u username:password \
  https://bitbucket.org/api/2.0/repositories/account/reponame/pullrequests \
 -d @pullrequest.json

with file pullrequest.json containing

 { 
     "title": "Merge some branches", 
     "description": "stackoverflow example",
     "source": { 
         "branch": { 
            "name": "mybranchToMerge" 
          }, 
          "repository": { 
            "full_name": "account/reponame" 
          } 
     }, 
     "destination": { 
         "branch": { 
             "name": "master" 
          } 
      }, 
      "reviewers": [ { "username": "reviewerUsername" } ], 
      "close_source_branch": false 
}

For more options look here:

Bitbucket: Send a pull request via command line?

More about git request-pull can be found here:

Difference between 'git request-pull' and 'pull request'

Probably the answer to your question is disappointing, as Pull Requests are not a native feature of git they are not supported through the CLI or any other standard git tool. Additionally there is no standard protocol for Pull Requests even outside of standard git . Each platform ( GitLab , GitHub etc.) provides its own flavor of Pull Requests .

Since you question is about Pull Requests in general and not about Pull Requests on a specific provider the answer is that it cannot be done.

If you are using bitbucket enterprise, i prepared a script to create/delete pull requests - https://github.com/psadi/bbcli .

It also handles adding of default reviewers automatically to your PR which is configured in your repo settings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM