如何在python中使用BitBucket API发布拉取请求注释



我正在尝试通过 REST API 向位桶拉取请求添加注释。我得到的回复总是 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&#39;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>

我找到了Bitbucket REST API 1.0版本的解决方案。

API 格式如下:-

    /
  • rest/api/1.0/projects//repos//pull-requests//comments.

用于添加注释的 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 : 链接

最新更新