How do I post a pull request comment using BitBucket REST api 2.0?
Asked Answered
O

3

17

Using REST API 1.0, I can do the following

POST /api/1.0/repositories/{owner}/{repo}/pullrequests/1/comments

What is the equivalent of this in 2.0? 2.0 documentation for pullrequests resource states "Finally, you can use this resource to manage the comments on a pull request as well." I don't see a POST for comments similar to 1.0 companion; nor does PUT do anything about comments.

Is posting comments on a PR supported in 2.0?

Oldest answered 9/12, 2015 at 17:27 Comment(0)
B
12

I know it has been quite a long time since the question was asked, but for people coming to this post:

Bitbucket finally added a way to post comments using their 2.0 API. You check the documentation for more info.

And here is an example:

curl -X POST -d '{"content": { "raw": "your comment" }}' $URL
Benedictus answered 24/9, 2019 at 19:43 Comment(4)
Note that, when this question was asked, "Bitbucket" only referred to the cloud product (bitbucket.org). Now there's also Bitbucket Server, fka Stash, which has a different API (tied to the BB Server version).Drool
True, I am referring to the cloud in this case. Thanks for pointing out @JimRedmond.Benedictus
This worked for me after adding this to the headers: Content-Type: application/jsonMoonlighting
The url should be: developer.atlassian.com/bitbucket/api/2/reference/resource/… or developer.atlassian.com/bitbucket/api/2/reference/resource/…Axum
I
4

Unfortunately pull request comments are currently read-only in 2.0. We are definitely keen to finish that API, but these efforts have been rather under prioritized.

For now, 1.0 remains the only way to mutate PR comments.

Also see: https://answers.atlassian.com/questions/32977327/are-you-planning-on-offering-an-update-pull-request-comment-api

Itemize answered 10/12, 2015 at 4:59 Comment(2)
Thank you. Perhaps a line of text in 2.0 API documentation to this effect will save lot of time for future searches.Oldest
is this still the case?Bilow
S
1

First you need to get pull request id using this command :

curl -s --request GET --url '{bitbucket_url}/rest/api/1.0/projects/{project_key}/repos/{repo_key}/pull-requests?State=OPEN&at=refs/heads/'${BranchName}'&direction=OUTGOING' --header 'Content-Type: application/json' -H 'Authorization:Basic {bitbucket_authentication_token}' | sed -n 's/.*"values":\[{"id":\([0-9]*\).*/\1/p'

And then add the comment using this command :

curl --request POST '{bitbucket_url}/rest/api/1.0/projects/{project_key}/repos/{repo_key}/pull-requests/{pull_request_id}/comments' --header 'Content-Type: application/json' -d {"text": "Add your comment here"} -H 'Authorization:Basic {bitbucket_authentication_token}'
Shakti answered 23/11, 2021 at 12:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.