How can I use github api to get all tags or releases for a project?

我怕爱的太早我们不能终老 提交于 2020-01-01 04:51:08

问题


I would like to know how to use the github-api to get all the current releases or tags for a project. I have seen the documentation for tags in github-api but I don't see a way to list all tags or list all releases but only list a specific tag by :sha.


回答1:


It's possible, but the documentation is perhaps not in the place you'd expect it to be.

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

You can also request a sub-namespace. For example, to get all the tag references, you can call:

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



回答2:


This morning I received an answer to this same question that I posted to the github support team. Not sure how I can attribute the answer correctly but here is their response.

Quote from Ivan Žužak of Github support team

You can get a list of all tags for a repository using this API call:

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

So, for example, making the following cURL request will return the list of tags for the libgit2/libgit2 repository:

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




回答3:


Note: for the releases specifically of a GitHub repo, you now have (since Sept. 25th, 2013), an api to list all the releases:

List releases for a repository

  • Users with push access to the repository will receive all releases (i.e., published releases and draft releases).
  • Users with pull access will receive published releases only.

    GET /repos/:owner/:repo/releases
    

Response

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 a single release

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



回答4:


In v4, graphQL, you can use this query https://developer.github.com/v4/object/tag/

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



回答5:


This will list all your Releases (tags) on Github. Might need to tweek the grep part depending on your tag naming conventions:

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

If cutting-n-pasting the URL from the "clone repo" section, remember to chop the.git off at the end of the address when constructing above URL- HTH- Terrence Houlahan



来源:https://stackoverflow.com/questions/18995854/how-can-i-use-github-api-to-get-all-tags-or-releases-for-a-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!