【发布时间】:2014-10-04 14:04:33
【问题描述】:
当它告诉我使用时,我不确定它是什么意思:
GET /repos/:owner/:repo/commits/:sha
如何使用该 API 调用来检索我正在寻找的信息?
【问题讨论】:
标签: github-api
当它告诉我使用时,我不确定它是什么意思:
GET /repos/:owner/:repo/commits/:sha
如何使用该 API 调用来检索我正在寻找的信息?
【问题讨论】:
标签: github-api
GET /repos/:owner/:repo/commits/:sha
GET 是用于调用此 API 端点的 HTTP 方法。
:owner 是用户或组织的名称(例如,octocat 是 user 的名称)。
:repo 是所选用户或组织拥有的存储库的名称(例如,octocat 用户共享 Spoon-Knife 存储库)
:sha 是 Git 对象的 40 字节长unique identifier
您必须在通话前加上 root endpoint -> https://api.github.com。
考虑到这一点,为了展示
可以向以下网址发出 GET Http 调用
https://api.github.com/repos/octocat/Spoon-Knife/commits/bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f
例如,使用以下 curl 命令...
$ curl https://api.github.com/repos/octocat/Spoon-Knife/commits/bb4cc8d3b2e14b3
af5df699876dd4ff3acd00b7f
...将返回以下 Json 有效负载
{
"sha": "bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f",
"commit": {
"author": {
"name": "The Octocat",
"email": "octocat@nowhere.com",
"date": "2014-02-04T22:38:36Z"
},
"committer": {
"name": "The Octocat",
"email": "octocat@nowhere.com",
"date": "2014-02-12T23:18:55Z"
},
"message": "Create styles.css and updated README",
...[snipped for brevity]...
"patch": "@@ -0,0 +1,17 @@\n+* {\n+ margin:0px;\n+ padding:0px;\n+}\n+\n+#octocat {\n+ display: block;\n+ width:384px;\n+ margin: 50px auto;\n+}\n+\n+p {\n+ display: block;\n+ width: 400px;\n+ margin: 50px auto;\n+ font: 30px Monaco,\"Courier New\",\"DejaVu Sans Mono\",\"Bitstream Vera Sans Mono\",monospace;\n+}"
}
]
}
正如 @matsjoyce 正确指出的那样,许多库抽象了这种低级操作并提供了更加用户友好的界面。其中大部分都列在 https://developer.github.com/libraries/
【讨论】: