簡體   English   中英

使用GitHub API將markdown表作為Pull Request注釋發布到GitHub

[英]Posting a markdown table as Pull Request comment to GitHub using GitHub API

我可以使用API​​將文本發布到GitHub上的拉取請求中

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

並使用下面作為正文

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

我正在嘗試將諸如下面的markdown表作為正文而不是上面的純文本發布。

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。 我還嘗試將\\n s添加到markdown主體中,因為它跨越多行。 但是,這些嘗試似乎都無效,並且給了我與上述相同的錯誤。

{
  "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
}

如何通過郵遞員在MarkGitHub上發布markdown表作為對請求的注釋?

您的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中的任意輸入。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM