pythongitgithub3.py

Is there a way to get Tag objects instead of Reference ones when listing tags from a repository?


I'm able to successfully list tags from a repository using github3 using:

repo.iter_refs(subspace='tags')

That results in a generator of github3.git.Reference objects. Is there a way for me use a similar mechanism to get github3.git.Tag objects, instead? Right now I'm forced to convert each Reference object into my own version of Tag.


Solution

  • So the only way to get a github3.git.Tag object back is if you're trying to retrieve a specific annotated tag (which is a tag created in a very specific manner).

    If this is what you're trying to do then your code would look something like

    tags = [repo.tag(r.object.sha) for r in repo.iter_refs(subspace='refs')]
    

    You can get a lightweight tag (which is what most tags on GitHub actually are) by either your current method or by doing repo.iter_tags(). Either will work. The latter will return github3.repos.RepoTag, not a github3.git.Tag though because the API returns much different information for each.