bash - 如何通过 API 对 Bitbucket Pull Request 进行 Markdown/HTML 评论?

标签 bash api bitbucket pull-request

我正在使用 Bitbucket API (2.0) 向 Pull Rrequests 提交评论,但我很难弄清楚如何使用 Markdown 或 HTML 发送“样式化”评论。

到目前为止,我只能以原始模式发送评论。

这是文档

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/comments#post

这是发送原始消息的代码:


BITBUCKET_API_ROOT="https://api.bitbucket.org/2.0"
BITBUCKET_STATUS_API="$BITBUCKET_API_ROOT/repositories/$BITBUCKET_NAMESPACE/$BITBUCKET_REPOSITORY/pullrequests/$PR_ID/comments"


MESSAGE="this is my message."

echo "Pushing comment to $BITBUCKET_STATUS_API..."
curl --request POST $BITBUCKET_STATUS_API \
--user $BITBUCKET_USERNAME:$BITBUCKET_ACCESS_TOKEN \
--header "Content-Type:application/json" \
--silent \
--data "{\"content\": { \"raw\": \"$MESSAGE\" }}"

尝试以这种方式指定 Markdown :

--data "{\"content\": { \"raw\": \"$MESSAGE\", \"markup\": \"markdown\"  }}"

结果:

{"type": "error", "error": {"fields": {"content.markup": "extra keys not allowed"}, "message": "Bad request"}}

尝试其他方法,例如指定 html 字段也没有帮助。

最佳答案

我很确定这是文档中的错误。您可以查看他们在有人评论 PR 时发送的请求。他们发送数据:--data '{"content":{"raw":"test **2**"}}'。您可以在响应中检查使用什么渲染器来解析您的消息。
所以只需发送带有 markdown 的原始消息,Bitbucket 将使用 markdown 渲染器来显示它。
您可以在 community.atlassian.com 上找到一堆问题,例如:
https://community.atlassian.com/t5/Bitbucket-questions/Is-it-possible-to-reply-to-a-pull-request-comment-via-Bitbucket/qaq-p/1047943
https://community.atlassian.com/t5/Bitbucket-questions/How-to-post-html-comments-on-pull-request-via-2-0-api/qaq-p/1066809
他们都没有来自 Atlassian 的答案。

关于bash - 如何通过 API 对 Bitbucket Pull Request 进行 Markdown/HTML 评论?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58483236/

相关文章:

bash - 如何从文件路径中提取目录路径?

regex - Bash - 从不包含特定模式的文件中获取行

security - 用于服务器到服务器 API 安全的 OAuth

php - 使用 BASH 存储和循环 MySQL 获取的结果?

linux - ksh脚本+在shell脚本中打印参数内容

javascript - 带有Angular的ASP.NET Core上的级联下拉列表

java - 推特搜索 Api 连接超时

git - 将代码从 Mercurial 移动到 Bitbucket

ssh - Google 计算引擎公钥

Jenkins bitbucket oauth 插件 - 限制登录团队