【问题标题】:How can I use github api to get all tags or releases for a project?如何使用 github api 获取项目的所有标签或版本?
【发布时间】:2013-09-25 03:46:23
【问题描述】:

我想知道如何使用 github-api 来获取项目的所有当前版本或标签。我见过documentation for tags in github-api,但我没有看到列出所有标签或列出所有版本的方法,但只列出了一个特定的标签:sha。

【问题讨论】:

标签: github github-api


【解决方案1】:

有可能,但文档可能不在您期望的位置。

http://developer.github.com/v3/git/refs/

您还可以请求子命名空间。例如,要获取所有标签 参考文献,可以调用:

GET /repos/:owner/:repo/git/refs/tags

【讨论】:

    【解决方案2】:

    今天早上,我收到了对我发布给 github 支持团队的同一个问题的回答。不知道如何正确地归因于答案,但这是他们的回应。

    引用 Github 支持团队的 Ivan Žužak 的话

    您可以使用此 API 调用获取存储库的所有标签的列表:

    http://developer.github.com/v3/repos/#list-tags

    因此,例如,发出以下 cURL 请求将返回 libgit2/libgit2 存储库的标签列表:

    $ curl -v "https://api.github.com/repos/libgit2/libgit2/tags"

    【讨论】:

    【解决方案3】:

    注意:对于 GitHub 存储库的 releases specifically,您现在拥有 (since Sept. 25th, 2013)、api to list all the releases

    列出存储库的版本

    • 对存储库具有推送访问权限的用户将收到所有版本(即已发布的版本和草稿版本)。
    • 具有拉取访问权限的用户只会收到已发布的版本。

      GET /repos/:owner/:repo/releases
      

    回应

    Status: 200 OK
    X-RateLimit-Limit: 5000
    X-RateLimit-Remaining: 4999
    
    [
      {
        "url": "https://api.github.com/repos/octocat/Hello-World/releases/1",
        "html_url": "https://github.com/octocat/Hello-World/releases/v1.0.0",
        "assets_url": "https://api.github.com/repos/octocat/Hello-World/releases/1/assets",
        "upload_url": "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name}",
        "id": 1,
        "tag_name": "v1.0.0",
        "target_commitish": "master",
        "name": "v1.0.0",
        "body": "Description of the release",
        "draft": false,
        "prerelease": false,
        "created_at": "2013-02-27T19:35:32Z",
        "published_at": "2013-02-27T19:35:32Z"
      }
    ]
    

    获取单个版本

    GET /repos/:owner/:repo/releases/:id
    

    【讨论】:

    • 有什么办法可以去掉限制吗?我只得到最后 X 个版本。
    • @NickeManarin 我不这么认为,考虑到这应该受到分页规则的限制:请参阅developer.github.com/v3/guides/traversing-with-pagination
    • 啊,我只需要在末尾附加?per_page=50。谢谢。
    • 也可能有一个Link 标头来支持分页。这需要解析以获取next url。
    【解决方案4】:

    在 v4,graphQL,你可以使用这个查询https://developer.github.com/v4/object/tag/

    query {
      repository(owner: "onmyway133", name: "Scale") {
        refs(refPrefix: "refs/tags/", last: 2) {
          edges {
            node {
              name
            }
          }
        }
      }
    }
    

    【讨论】:

      【解决方案5】:

      这将列出您在 Github 上的所有版本(标签)。可能需要根据您的标签命名约定调整 grep 部分:

      curl -s 'https://github.com/username/reponame/tags/'|grep -o "$Version v[0-9].[0-9][0-9]"
      

      如果从“克隆仓库”部分剪切-n-粘贴 URL,请记住在构建上述 URL-HTH-Terrence Houlahan 时将地址末尾的.git 去掉

      【讨论】:

      • 不,这只会列出最后几个标签。
      猜你喜欢
      • 2020-08-06
      • 1970-01-01
      • 2015-01-31
      • 2020-07-21
      • 1970-01-01
      • 1970-01-01
      • 2017-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多