我正在尝试通过REST API向bitbucket拉取请求添加注释。我得到的响应始终是404
首先我尝试使用python请求库,然后使用curl命令
#python code
link = 'https://<base-url>/2.0/repositories/<project_name>/views_source/pullrequests/<pull-request-id>/comments'
r = requests.post(link, verify=False)
#windows command
curl -X POST -d "{\"text\" : \"test comment\"}" https://<base-url>/2.0/repositories/<project_name>/views_source/pullrequests/<pull-request-id>/comments
我遇到的错误如下:-
part of python output:
<h2>Oops, you've found a dead link</h2>
curl output
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><status><status-code>404</status-code><message>null for uri: https://<base-url>/rest/api/1.0/repositories/<repo-name>/views_source/<comment-id>/comments</message></status>
答案 0 :(得分:0)
我找到了使用Bitbucket REST API 1.0版本的解决方案。
API格式如下:-
用于添加注释的Python代码:
import requests
headers = {'content-type': 'application/json'}
commentLink = 'https://base-url//rest/api/1.0/projects/<project_name>/repos/<repo_name>/pull-requests/<pull_request_id>/comments'
res = requests.post(commentLink, verify=False, auth=(username,password), headers=headers, data=json.dumps({'text': <comment>}))
对API的引用:Link