atlassian-api / atlassian-python-api

Atlassian Python REST API wrapper
https://atlassian-python-api.readthedocs.io
Apache License 2.0
1.34k stars 661 forks source link

[Bitbucket cloud] problems adding comment in a pull request #1222

Open ivandw opened 1 year ago

ivandw commented 1 year ago

Hello there, im trying to generate a comment in a pull request using bitbucket cloud and im getting an error.

Steps to reproduce:

using this sample code block, im trying to generate a comment in the pull request 101 of some repo inside my org of bitbucket cloud.

from atlassian.bitbucket import Bitbucket
project="myproj"
repository="myrepo"
pull_request_id="101"
text="test"
bitbucket = Bitbucket(url="https://api.bitbucket.org", username="bitbucket-user", password="user-app-password")

bitbucket.add_pull_request_comment(project, repository, pull_request_id, text)

im getting this error:

- python3 post_comment.py

Traceback (most recent call last):
  File "post_comment.py", line 10, in <module>
    bitbucket.add_pull_request_comment(project, repository, pull_request_id, text)
  File "/opt/homebrew/lib/python3.11/site-packages/atlassian/bitbucket/__init__.py", line 1989, in add_pull_request_comment
    return self.post(url, data=body)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/atlassian/rest_client.py", line 333, in post
    response = self.request(
               ^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/atlassian/rest_client.py", line 257, in request
    self.raise_for_status(response)
  File "/opt/homebrew/lib/python3.11/site-packages/atlassian/rest_client.py", line 487, in raise_for_status
    raise HTTPError(error_msg, response=response)
requests.exceptions.HTTPError

atlassian-python-api version 3.41.0 Python version 3.11.4 pip version 23.2.1

any suggestions? i can confirm that the username and app password is working well since i can create the pr comment using curl with the same credentials.

Thanks in advice.

nigelsim commented 2 months ago

I'm encountering the same issue. If you bump up the logging you'll find it's sending a request like this:

DEBUG:atlassian.rest_client:curl --silent -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' --data '"{\"text\": \"test\"}"' 'https://api.bitbucket.org/2.0/repositories/myproj/myrepository/pullrequests/123/comments'

The body is incorrect. It should be something like {"content": {"raw": "test"}} https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-pull-request-id-comments-post

apanzerj commented 2 months ago

Any workaround?

Spacetown commented 2 months ago

Any workaround?

Feel free to raise a PR to fix the issue.

nigelsim commented 2 months ago

I just used the REST API directly. It's very straight forward. API Ref

Regarding the PR I worry that if this one is out of date, then there may be a whole chunk that are also, and doing this piecemeal will just be frustrating for future users. Better to review the whole API.