如何在 python 中使用 BitBucket API 发布拉取请求评论? [英] How to POST a pull request comment using BitBucket API in python?

查看:111
本文介绍了如何在 python 中使用 BitBucket API 发布拉取请求评论?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 REST API 向 bitbucket 拉取请求添加评论.我得到的回复总是 404

I am trying to add comment to bitbucket pull request through REST API. Response I get is 404 always

首先我尝试使用 python requests 库,然后使用 curl 命令

First I tried with python requests library, then curl command

#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 版本的解决方案.

I found the solution with Bitbucket REST API 1.0 version.

API 格式如下:-

  • /rest/api/1.0/projects//repos//pull-requests//评论.

用于添加注释的 Python 代码:

Python code used to add comment:

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 参考:链接

这篇关于如何在 python 中使用 BitBucket API 发布拉取请求评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆