【问题标题】:how to obtain a JSON representation of a Git/GitHub reposity如何获取 Git/GitHub 存储库的 JSON 表示
【发布时间】:2013-06-08 23:47:29
【问题描述】:

我正在制作一个游戏原型,它将使用 Git 存储库、其分支、合并等信息作为游戏关卡的来源。

有没有办法获取 Git 存储库“历史记录”并将其保存为 JSON 格式?更好的是,是否可以获得 GitHub 存储库的 JSON 表示?

我很乐意让 Linux 存储库成为游戏的最后一个阶段,也让人们使用他们自己的本地存储库。

【问题讨论】:

    标签: linux git github


    【解决方案1】:

    您可以使用 Github API 获取所有这些信息

    http://developer.github.com/

    回购合作者:http://developer.github.com/v3/repos/collaborators/

    回购提交:http://developer.github.com/v3/repos/commits/

    回购内容:http://developer.github.com/v3/repos/contents/

    回购分叉:http://developer.github.com/v3/repos/forks/

    获取 github.com/holman/play 提交的示例 URL

    https://api.github.com/repos/holman/play/commits
    

    【讨论】:

      【解决方案2】:

      你看过developer API documentation吗?

      您需要的确切信息取决于您所说的“GitHub 存储库的 JSON 表示”的确切含义,因为它与 GitHub 如何公开它有关,但可以在他们的Repositories section. 中找到详细信息。

      总的来说,GitHub API 是一个 RESTful 接口,因此它遵循典型的 REST 规则。鉴于他们是一家 Ruby 商店,它可能还会遵循 Ruby 的 REST API 实践,这可能有助于您进行试验。

      【讨论】:

        【解决方案3】:

        其他人已经指出了使用 github API 解决此问题的方法。您的问题也留下了仅使用 git 而不是 github 来执行此操作的可能性。 JSON 的优点在于它只是文本,因此您只需使用 git log 即可生成它。

        $ echo "[" && git log -n5 --pretty=format:\"%H\", && echo "]"
        [
        "216e8824cfac3d3a46eac23fb177566829f2f236",
        "8b0357b71fa824114f9db96954b364a8f815fd50",
        "bd394fd40184df8b22e45fb6aaa1fc1c3c6dc31a",
        "c35af70eaedcdd05b56496e555f33c65286e85ba",
        "9e65dfd39de1732bc114bee184f595a6f091680c",
        ]
        

        我知道你最终会需要比这更多的细节,但这是一个起点。

        好的,这是另一个例子。这很有趣。

        $ echo "[" && git log -n5 --pretty=format:'{ "author": "%an", "subject":"%s" }', && echo "]"
        [
        { "author": "Saul Torrell", "subject":"June 21 release - operator systems" },
        { "author": "Saul Torrell", "subject":"Missing topic for june 11 release." },
        { "author": "Saul Torrell", "subject":"June 11 release." },
        { "author": "Saul Torrell", "subject":"new topic." },
        { "author": "Saul Torrell", "subject":"Added extra sauce to the frobnicator." },
        ]
        

        【讨论】:

          猜你喜欢
          • 2017-02-23
          • 2010-10-11
          • 2013-03-20
          • 1970-01-01
          • 2011-11-19
          • 2021-02-26
          • 1970-01-01
          • 2017-09-01
          • 2015-12-21
          相关资源
          最近更新 更多