【问题标题】:pygithub how to get latest commit on specific branchpygithub如何获取特定分支的最新提交
【发布时间】: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)

【问题讨论】:

    标签: commit git-branch pygithub


    【解决方案1】:

    考虑到PyGithub/PyGithub issue 1967,尝试get_commitbranch.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))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 2013-03-28
      • 1970-01-01
      • 1970-01-01
      • 2021-03-10
      • 2021-06-09
      相关资源
      最近更新 更多