Bitbucket: Send a pull request via command line?

前端 未结 4 1843
日久生厌
日久生厌 2020-12-07 17:50

I have to send a lot of pull requests, so I would rather use the bash command line than bitbucket\'s web interface.

Usage example: $ git-req username

相关标签:
4条回答
  • 2020-12-07 17:55

    Bitbucket with it's RESTful API 2.0 supports managing pull requests without interface. In CLI you can request it with CURL. This older version of the documentation has better interface details.

    Get pull request data with CURL

    To get full data about specific pull request:

    $ curl --user s3m3n:bbpassword https://bitbucket.org/api/2.0/repositories/s3m3n/reponame/pullrequests/4
    

    In return I get JSON with full info about my pull request #4 (put your username twice, password and reponame in command).

    Create new pull request with RESTClient

    To create new pull request we need to provide a lot of data with POST command, below how it looks in my RESTClient:

    RESTClient Firefox

    After firing Bitbucket shows pull request immediately:

    Bitbucket screenshot

    Create new pull request with CURL

    You can still create the same pull request with one liner:

    $ curl -X POST -H "Content-Type: application/json" -u s3m3n:bbpassword https://bitbucket.org/api/2.0/repositories/s3m3n/reponame/pullrequests -d '{ "title": "Merge some branches", "description": "stackoverflow example", "source": { "branch": { "name": "choose branch to merge with" }, "repository": { "full_name": "s3m3n/reponame" } }, "destination": { "branch": { "name": "choose branch that is getting changes" } }, "reviewers": [ { "username": "some other user needed to review changes" } ], "close_source_branch": false }'
    

    REST browser tool (discontinued)

    If you want to test all possible methods of API hop to REST browser tool of Bitbucket. It will show you all possible requests while returning your real repo's data.

    0 讨论(0)
  • 2020-12-07 17:58

    I wasn't too satisfied with the answers in this thread, so I created an package for it:

    https://www.npmjs.com/package/bitbucket-pr

    Instructions:

    npm i -g bitbucket-pr

    ... Go to folder where you want to create a pull request ...

    bitbucket-pr

    0 讨论(0)
  • 2020-12-07 18:02

    There are 2 repos on bitbucket that could help:

    the Attlassian team have stash (ruby): https://bitbucket.org/atlassian/bitbucket-server-cli

    Zhemao has bitbucket-cli (python): https://bitbucket.org/zhemao/bitbucket-cli

    both have pull request feature from command line.

    0 讨论(0)
  • 2020-12-07 18:13

    Tried and tested :

    1. Generate personal access token by clicking here

    2. Save the Unique token id, append it after "Bearer in header".

    For example: "Authorization : Bearer MDg4MzA4NTcfhtrhthyt/Thyythyh "

    Complete JSON sample here:

    Step 1 to enter the details and necessary headers

    1. Try running it Step 2

    2. Output on BitBucket, You will be able to see the pull request Final output

    Command Line Syntax:

    curl -i -X POST    -H "Authorization:Bearer MDg4MzA4NTk/TlMSS6Ea"    -H "X-Atlassian-Token:no-check"    -H "Content-Type:application/json"    -d '{"description":"1. Changes made 2. Changes made 3. Hello hanges","closed":false,"fromRef":{"id":"refs\/heads\/branch","repository":{"name":"From Repository ","project":{"key":"ProjectName"},"slug":"From Repository "}},"state":"OPEN","title":"Merge changes from branch to master","locked":false,"reviewers":[],"open":true,"toRef":{"id":"refs\/heads\/master","repository":{"name":"RepoName","project":{"key":"ProjectName"},"slug":"RepoName"}}}'  'https://bitbucket.agile.com/rest/api/1.0/projects/projectName/repos/repoName/pull-requests'
    
    0 讨论(0)
提交回复
热议问题