REST API for creating pull requests
it'd be really super cool if there was an API for creating pull requests :)
see github's api
Comments (21)
-
-
To merge a PR, just do:
curl -X POST https://api.bitbucket.org/2.0/repositories/{user}/{slug}/pullrequests/{id}/accept
or:
curl -X POST https://api.bitbucket.org/2.0/repositories/{user}/{slug}/pullrequests/{id}/decline
Both take an optional
message
parameter that allow you to explain why you're accepting or declining. In the former case that becomes the commit message of the merge. -
We're close to releasing this API and are in the final stages of making some tweaks to them. As result, minor changes may be introduced.
-
-
assigned issue to
-
assigned issue to
-
- changed component to api
-
- changed status to resolved
-
great! thanks!
-
Would like to know once its released.
-
@Milli Sami this was released last month: http://blog.bitbucket.org/2013/11/12/api-2-0-new-function-and-enhanced-usability/
-
- changed component to API
-
Does this still work? Can you give an example for use with POSTMAN. I'm trying to send a json object like:
{ src: "t1", title: "Woo Hoo", dest: "master", description: "this could be the one", reviewers: "dan_shumaker" }
And it's not working, the response is "Bad request".
-
I got it with some guess work:
{ "destination": { "branch": { "name": "master" } }, "source": { "branch": { "name": "t1" } }, "title": "R with POSTMAN BITBUCKET API" }
-
Thanks @Dan Shumaker!
-
Thanks @Dan Shumaker!
-
Has anyone had luck with this working? I keep getting an error message:
{ "type": "error", "error": { "fields": { "source": [ "This field is required." ], "title": [ "This field is required." ] }, "message": "Bad request" } }
-
[~Adam Y] Try using a json payload like I mentioned above. As your response message indicates it looks like you did not include a source or title field in your payload, but it could also be that the json structure was wrong in some way.
-
@Adam Y , @Erik van Zijst, @Smilyan Pavlov I've created a node module to use the bitbucket api. Currently it only creates and lists pull requests but it still might be helpful to you.
https://www.npmjs.com/package/bitbucket-cmd
I know there are other bitbucket tools out there but none of them were really what I wanted or needed.
Hopefully helpful!
-
That's great, thank you @Dan Shumaker
-
Hey
I do request via guzzle on php. But got this error:
{"type": "error", "error": {"fields": {"source": ["This field is required."]}, "message": "Bad request"}}
Code:
<?php $data = array( 'destination' => array( 'branch' => array('name' => 'master'), ), 'source' => array( 'branch' => array('name' => 'feature/4507'), 'repository' => array( 'full_name' => 'diluschenko/beloglazov.pro.v2', ), ), 'title' => $title, 'access_token' => $this->accessToken, ); $params = array( 'type' => 'POST', 'url' => 'https://api.bitbucket.org/2.0/repositories/diluschenko/beloglazov.pro.v2/pullrequests', 'options' => array( 'headers' => array( 'Accept' => 'application/json', ), 'form_params' => $data, ), ); $response = $this->connector->sendRequest($params);
What's wrong?
-
Answer:
<?php $data = array( 'destination' => array( 'branch' => array('name' => 'master'), ), 'source' => array( 'branch' => array('name' => 'feature/4507'), ), 'title' => $title, ); $params = array( 'type' => 'POST', 'url' => 'https://api.bitbucket.org/2.0/repositories/diluschenko/beloglazov.pro.v2/pullrequests?access_token=$this->accessToken', 'options' => array( 'headers' => array( 'Accept' => 'application/json', ), 'json' => $data, ), ); $response = $this->connector->sendRequest($params);
-
When you do a PUT over a existing pull request the reviewers list may not change, with syntax for POST like the example "-d reviewers=evzijst -d reviewers=nvenegas -d reviewers=..." didn't work, and if using a -F of curl the results is:
{ "type": "error", "error": { "fields": { "reviewers": [ "Malformed reviewers list" ] }, "message": "Bad request" } }
The curl:
curl -X PUT \ https://api.bitbucket.org/2.0/repositories/user/repo/pullrequests/123 \ -H 'authorization: Basic abcdefghijklmnopqrstuvwxyz==' \ -F 'title=Updated PR' \ # works perfect -F close_source_branch=true \ # works perfect -F reviewers=user1 \ # FAIL -F reviewers=user2 # FAIL
- Log in to comment
The last 2 parameters are optional. The default destination is the repo's main branch.
If you're creating a PR between forks, make the POST on the destination repo's URL, and add:
Additionally you can add reviewers by repeating the
reviewers
param 1 or more times: