首页 > 解决方案 > 使用 GitHub API 将降价表作为 Pull Request 评论发布到 GitHub

问题描述

我可以使用 API 将文本发布到 GitHub 上的拉取请求

https://api.github.com/repos/aftab-hassan/pagerankassignment/pulls/2/comments

并使用以下作为主体

{
  "body": "Nice change",
  "commit_id": "5dfc67045edc45ed102f6bf6ad0c1209fdd2ef38",
  "path": "README",
  "position": 4
}

我正在尝试发布一个如下的降价表作为正文而不是上面的纯文本。

First Header | Second Header
------------ | -------------
Content from cell 1 | Content from cell 2
Content in the first column | Content in the second column

但是,它给了我如下错误

{
    "message": "Problems parsing JSON",
    "documentation_url": "https://developer.github.com/v3/pulls/comments/#create-a-comment"
}

我确实尝试将正文类型更改为文本而不是 json。我还尝试将\ns 添加到降价正文,因为它跨越多行。但是,这些尝试似乎都不起作用,并且给了我与上述相同的错误。

{
  "body": "First Header | Second Header\n
------------ | -------------\n
Content from cell 1 | Content from cell 2\n
Content in the first column | Content in the second column",
  "commit_id": "5dfc67045edc45ed102f6bf6ad0c1209fdd2ef38",
  "path": "README",
  "position": 4
}

如何通过 Postman 在 GitHub 上发布降价表作为对拉取请求的评论?

标签: githubmarkdown

解决方案


您的 JSON 字符串应该只包含转义的换行符,而不是文字的换行符。所以body变成

"First Header | Second Header\n------------ | -------------\nContent from cell 1 | Content from cell 2\nContent in the first column | Content in the second column"

查看此答案,以更灵活地处理 JSON 的任意输入。


推荐阅读