从存储库中列出标签时,有没有办法获取 Tag 对象而不是 Reference 对象?

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

我能够使用 github3 使用以下方法成功列出存储库中的标签:

repo.iter_refs(subspace='tags')

这会导致生成 github3.git.Reference objects. Is there a way for me use a similar mechanism to get github3.git.Tag 个对象?现在我被迫将每个 Reference 对象转换为我自己的 Tag.

版本

所以获取 github3.git.Tag 对象的唯一方法是尝试 retrieve a specific annotated tag(这是一个以非常具体的方式创建的标签)。

如果这就是您要执行的操作,那么您的代码应该类似于

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

您可以通过当前的方法或 repo.iter_tags() 获得轻量级标签(GitHub 上的大多数标签实际上是这样的)。两者都会起作用。后者将 return github3.repos.RepoTag,而不是 github3.git.Tag,因为每个 API return 的信息大不相同。