python - 使用 Github API 获取所有存储库的最后一次提交

标签 python python-3.x git github github-api

我想使用 Python 的 Github API 来获取每个存储库并检查对存储库的最后更改。

import git
from git import Repo
from github import Github

repos = []

g = Github('Dextron12', 'password')
for repo in g.get_user().get_repos():
    repos.append(str(repo))

#check for last commit to repository HERE

这会获取我帐户上的所有存储库,但我希望能够获取其中每个存储库的最后更改,并且我想要这样的结果:

13:46:45

我也不介意是否是 12 小时时间。

最佳答案

根据文档,您可以获得的最大信息是提交的 SHA 和提交日期:

https://pygithub.readthedocs.io/en/latest/examples/Commit.html#

以你的例子:

g = Github("usar", "pass")
for repo in g.get_user().get_repos():
    master = repo.get_branch("master")
    sha_com = master.commit
    commit = repo.get_commit(sha=sha_com)
    print(commit.commit.author.date)

关于python - 使用 Github API 获取所有存储库的最后一次提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57229005/

相关文章:

python - 如何将德摩根定律应用于Python中的 boolean 表达式字符串?

python - 是否可以在 for 循环中使用 lambda 来实现此目的?

git - 两个 Git 存储库共享公共(public)代码

Python - 所有组合包括括号

git - 仍然无法在 3 月 1 日截止日期前解析 Git SSH 凭据

git - 为什么默认情况下我的 Git 预提交 Hook 不可执行?

c++ - 将 OpenGL 代码从 C++ 移植到 Python

Python:如何将从列表中以某个字母开头的元素复制到新列表中或从列表中删除不以字母开头的元素

python - 如何最好地在 tensorflow 中实现矩阵掩码操作?

python - Jupyter笔记本: Tornado pointing to incorrect path