Search code examples
githubgithub-api

How to get a commit SHA from a release or tag on Github API V3


The release nor tag response don't seem to have information (SHA) about the commit they were made from. How can I get it if I only have a tag/release like v1.2.3?


Solution

  • There's no specific endpoint in GitHub API v3 to get the commit SHA from tag/release name.

    For your use-case, you can use the List tags endpoint to get all the tags for a particular repo, iterate over the response and get the desired tag details with the commit SHA.

    Endpoint: GET /repos/:owner/:repo/tags

    Sample response below:

    [
      {
        "name": "v0.1",
        "commit": {
          "sha": "c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc",
          "url": "https://api.github.com/repos/octocat/Hello-World/commits/c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc"
        },
        "zipball_url": "https://github.com/octocat/Hello-World/zipball/v0.1",
        "tarball_url": "https://github.com/octocat/Hello-World/tarball/v0.1"
      }
    ]