Retrieve release ID from Github release tag

Viewed 198

I'm gathering some Github releases using requests for Python 3. The Github API mentions that to get a specific release, you need its ID. Is there a way to only use the tag to do so, or in the worst case to use it to retrieve the ID?

Here's my code so far:

    def getGithub(self, url=ulgit.RELEASES_URL):
        """Get Github information"""

        headers = {"Authorization": f"token {ulgit.TOKEN}"}
        session = requests.Session()
        response = session.get(url, headers=headers)
        content = response.text
        data = json.loads(content)

        return data

    def getVersionsGithub(self):
        """Get available versions releases on Github"""

        list_releases = []
        for i in self.getGithub():
            list_releases.append(i["tag_name"])
    
    def getSpecificRelease(self):
        #TODO

1 Answers

You can use GitHub's GraphQL API to get a release by the tag name.

As a (random) example:

{
  repository(owner: "pytorch", name: "pytorch") {
    release(tagName: "v1.11.0") {
      databaseId
      createdAt
    }
  }
}

You can try it out in the browser here

Or from the command line:

curl https://api.github.com/graphql -X POST -H "Authorization: bearer token" -d '
 {
  "query": "query { repository ( owner: \"pytorch\", name: \"pytorch\" ) { release ( tagName: \"v1.11.0\" ) { databaseId createdAt }} }"
 }
'

Hope this helps

Related