'Retrieve release ID from Github release tag

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



Solution 1:[1]

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

Hope this helps

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Butler