我正在使用 Bitbucket API (2.0) 向 Pull Rrequests 提交评论,但我很难弄清楚如何使用 Markdown 或 HTML 发送“样式化”评论。
到目前为止,我只能以原始模式发送评论。
这是文档
这是发送原始消息的代码:
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/