I tried to use Atlassian Python library to create a comment for my PR and failed.
from atlassian import Bitbucket
bb = Bitbucket(
url='https://api.bitbucket.org',
username='anton_merzliakov',
password='<app-password>')
resp = bb.add_pull_request_comment('<project>', '<repo>', '<pr-id>', 'new comment')
The authentication definitely works correctly because some API calls work, just not the add_pull_request_comment
Using a debugger I found out what happened. The server returned:
{
"type": "error",
"error": {
"message": "Bad request",
"fields": {
"text": "extra keys not allowed",
"content": "required key not provided"
}
}
}
This is the very same error message I was getting trying to create a comment manually: https://community.atlassian.com/t5/Bitbucket-questions/Creating-a-PR-comment-via-REST-API/qaq-p/2406796 If the library itself doesn't know what keys to use, I definitely don't.
So, maybe I'm using an old version of the Python library? Maybe there's a workaround? Does Atlassian even support its Python library?
Patrik S told me the correct command, but I'm still curious why the Python library cannot do the same, or how to make it use this very command.
The correct manual command is
curl -X POST -u USERNAME:APP_PASSWORD 'https://api.bitbucket.org/2.0/repositories/<workspace>/<Repository>/pullrequests/<Pull Request ID>/comments' --header 'Content-Type: application/json' --data '{"content":{"raw":"testing one comment"}}'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.