如何使用GitHub API? [英] How do I make use of the GitHub API?

查看:239
本文介绍了如何使用GitHub API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定它告诉我使用什么意思:

I am not sure what it means when it tells me to use:

获取/repos/:owner/:repo/commits/:sha

GET /repos/:owner/:repo/commits/:sha

如何使用该API调用来检索所需的信息?

How can I use that API call to retrieve the information I am looking for?

推荐答案

获取/repos/:owner/:repo/commits/:sha

GET /repos/:owner/:repo/commits/:sha

  • GET是用于调用此API端点的HTTP方法.

    • GET is the HTTP method to use in order to invoke this API endpoint.

      :owner是用户或组织的名称(例如octocat

      :owner is the name of the user or organization (eg. octocat is the name of a user).

      :repo是所选用户或组织拥有的存储库的名称(例如,octocat用户共享

      :repo is the name of a repository owned by the chosen user or organization (eg. the octocat user shares the Spoon-Knife repository)

      :sha是40个字节长的 唯一标识符 的Git对象

      :sha is the 40 bytes long unique identifier of a Git Object

      您必须在呼叫之前加上 根端点 -> https://api.github.com.

      You have to prepend you call with the root endpoint -> https://api.github.com.

      考虑这一点,以便显示

      • 提交 bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f
      • 在资源库中汤匙
      • 属于用户 octocat
      • The commit bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f
      • In the repository Spoon-Knife
      • Belonging to the user octocat

      一个人会向以下网址发出 GET Http调用

      One would issue a GET Http call to the following url

      https://api.github.com/repos/octocat/勺刀/commits/bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f

      例如,使用以下curl命令...

      For instance, using the following curl command...

      $ curl https://api.github.com/repos/octocat/Spoon-Knife/commits/bb4cc8d3b2e14b3
      af5df699876dd4ff3acd00b7f
      

      ...将返回以下Json有效负载

      ...will return the following Json payload

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

      Update

      As rightfully pointed at by @matsjoyce, numerous libraries abstract this low level operations and expose a more user friendly interface. Most of them are listed at https://developer.github.com/libraries/

      这篇关于如何使用GitHub API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆