Automatically add tasks to new Btibucket Pull request

Viewed 1066

We have several default tasks that we would like to add to every new pull request in Bitbucket. Since tasks are not supported by the Bitbucket API, the best thing I can think of is to automate it through a Selenium script, or other GUI tester. I'm thinking about kicking it off using a Jenkins job that watches for new pull requests. Can anyone think of a better way to do this?

2 Answers

I found that the tasks endpoint is not documented but is however active.

You can do the following

export PROJECT=yourProject
export REPO=yourRepo
export PR_ID=pullRequestId
export TASK_NAME=theNameOfTheTask
curl -H "Content-Type:application/json" -X POST --user "${TB_USER}:${TB_PASSWORD}" -d '{"content":{"raw":"${TASK_NAME}"}}' "https://api.bitbucket.org/2.0/repositories/${PROJECT}/${REPO}/pullrequests/${PR_ID}/tasks/"

You can also send a GET to get ALL tasks and their status

Thanks for the find!

Quick note, Bitbucket stopped supporting basic auth using your standard user/pass, you'll need to setup an AppPassword and use your normal Bitbucket username (no email).

https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/

Ex:

export PROJECT=yourProject
export REPO=yourRepo
export PR_ID=pullRequestId
export TASK_NAME=theNameOfTheTask

curl -H "Content-Type:application/json" -X POST --user "bt-username:bt-apppassword" -d "{\"content\":{\"raw\":\"${TASK_NAME}\"}}" "https://api.bitbucket.org/2.0/repositories/${PROJECT}/${REPO}/pullrequests/${PR_ID}/tasks/"
Related