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

这一生的挚爱 提交于 2019-12-12 04:17:28

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/34051151/is-there-a-way-to-get-tag-objects-instead-of-reference-ones-when-listing-tags-fr

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