Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,641,978
Community Members
 
Community Events
196
Community Groups

Creating a Pull Request from a Bamboo Plan

We have some plans ( both build and deploy) that do commit and pushes of branches. We would like to create a pull request automatically after a branch is pushed. Is there a quick way to do this? 

If we have to use Bitbucket APIs. Is there an example/documentation of how to use Python APIs for this purpose?

Thanks,

1 answer

1 accepted

2 votes
Answer accepted
Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Apr 15, 2019

Hi @Subhi Andrews

You could use a script task and call a REST API to create the pull request.

Below you can find two examples using the curl command, one for Bitbucket cloud and another for server.


Bitbucket Cloud

 curl https://api.bitbucket.org/2.0/repositories/<USER_NAME>/<REPOSITORY>/pullrequests \
    -u <USER_NAME>:<APP_PASSWORD> \
    --request POST \
    --header 'Content-Type: application/json' \
    --data '{
        "title": "<PULL-REQUEST TITLE>",
        "description": "<PULL-REQUEST DESCRIPTION>",
        "source": {
            "branch": {
                "name": "<SOURCE_BRANCH>"
                }
            },
            "destination": {
                "branch": {
                    "name": "<DESTINATION_BRANCH>"
                }
            }
        }'

Reference: /repositories/{username}/{repo_slug}/pullrequests - Bitbucket API
⚠️Please make sure you create an app password with read/write permission for pull-requests.

Bitbucket server

curl <BITBUCKET_URL>/rest/api/1.0/projects/<PROJECT>/repos/<REPOSITORY-SLUG>/pull-requests \
    -u <USERNAME>:<PASSWORD> \
    --request POST \
    --header 'Content-Type: application/json' \
    --data '{
    "title": "<PULL-REQUEST TITLE>",
    "description": "<PULL-REQUEST DESCRIPTION>",
    "fromRef": {
        "id": "<SOURCE BRANCH>",
        "repository": {
            "slug": "<REPOSITORY_SLUG>",
            "project": {
                "key": "<PROJECT>"
            }
        }
    },
    "toRef": {
        "id": "<DESTINATION BRANCH>",
        "repository": {
            "slug": "<REPOSITORY SLUG>",
            "project": {
                "key": "<PROJECT>"
            }
        }
    }
}'

Reference: /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/archive - Bitbucket Server - REST

I hope that helps.

 

@Daniel Santos , Thanks. Could you also help us with APIs for merging the pull request?

We probably need to extract pull-request id from the creation of pull-request step.

Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Apr 22, 2019

Hi @Subhi Andrews

That should be the right direction.

  • Were you able to get it working?
  • Do you need it for Bitbucket cloud or server?

We were able to create Pull-Requests from Script task. Need an automatic merge from another script task or the same script task.

We use Bitbucket server

Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Apr 23, 2019

You will need to extract both the pull request ID version to merge it.

This is the call you can use:

Bitbucket server

curl -X POST <BITBUCKET_URL>/rest/api/1.0/projects/<PROJECT>/repos/<REPOSITORY_SLUG>/pull-requests/<PULL_REQUEST_ID>/merge?version=<VERSION> \
-u <USERNAME>:<PASSWORD> \
--header "Content-Type:application/json" \
--header "Accept:application/json"

Reference: /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/merge - Bitbucket Server REST API

Please keep us posted on your progres =]

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events