pygithub如何获取特定分支的最新提交
Posted
技术标签:
【中文标题】pygithub如何获取特定分支的最新提交【英文标题】:pygithub how to get latest commit on specific branch 【发布时间】:2021-11-01 07:27:04 【问题描述】:使用 pygithub 如何获取 repo 中特定分支的最新提交 相当于 github rest api https://github.com/api/v3/repos/repo//org/commits/branch?per_page=1 我按照中提到的步骤 pygithub - Receive all commits of a specific branch ,返回null。
branches = repo.get_branches() for branch in branches: print(branch.name) commits = repo.get_commits(path="tree/"+branch.name) for commit in commits: print(commit)
【问题讨论】:
【参考方案1】:考虑到PyGithub/PyGithub
issue 1967,尝试get_commit
或branch.commit
,首先,对于单个分支:
branches = repo.get_branches()
for branch in branches:
print("branch.last_modified: " + str(branch.last_modified))
print("branch.commit: " + str(branch.commit))
HEAD = repo.get_commit( str(branch.commit.sha))
【讨论】:
以上是关于pygithub如何获取特定分支的最新提交的主要内容,如果未能解决你的问题,请参考以下文章