GitHub API 没有返回行号

GitHub API not returning line number

我正在尝试使用 v3 GitHub API 在线创建评论。 Rhe 文档说明如下:

Note: To comment on a specific line in a file, you need to first determine the position of that line in the diff. The GitHub REST API v3 offers the application/vnd.github.v3.diff media type. To see a pull request diff, add this media type to the Accept header of a call to the single pull request endpoint.

Link 到文档。但是当我尝试发出请求时,它会回复:

[
        {
            "sha": "7ed12345678911cd0d8c6bf34fa547aaa6eab5b6",
            "filename": "README.md",
            "status": "modified",
            "additions": 1,
            "deletions": 1,
            "changes": 2,
            "blob_url": "https://github.com/johnsnow/demo/blob/37422b7241b0dadcdac1af53f8e33baba7b489bd/README.md",
            "raw_url": "https://github.com/johnsnow/demo/raw/37422b7241b0dadcdac1af53f8e33baba7b489bd/README.md",
            "contents_url": "https://api.github.com/repos/johnsnow/demo/contents/README.md?ref=37422b7241b0dadcdac1af53f8e33baba7b489bd",
            "patch": "@@ -1,6 +1,6 @@\n # Application model for Java 8\n \n-We provide a basic model for JDK 1.8 / Spark based web applications.\n+AWe provide a basic model for JDK 1.8 / Spark based web applications."
        }
 ]

API 没有显示差异。

请求示例:

curl -X GET \
  'https://api.github.com/repos/johnsnow/demo/pulls/20/files?access_token=some_token' \
  -H 'Accept: application/vnd.github.v3.diff' 

让我们仔细看看您引用的文档中的最后一句话:

To see a pull request diff, add this media type to the Accept header of a call to the single pull request endpoint.

但是您请求 "List pull requests files" endpoint。从请求的末尾删除 /files URL:

curl -X GET \
  'https://api.github.com/repos/johnsnow/demo/pulls/20?access_token=some_token' \
  -H 'Accept: application/vnd.github.v3.diff'