我查看了文档甚至源代码,但似乎无法弄清楚如何使用 github3.py 库获取提交的时间戳。我很确定它在那里,因为它是一个时间戳。
问问题
227 次
1 回答
2
因此,如果您想获得与存储在 GitHub 中的 git 提交相关的时间戳,那么您需要做一些事情:
- 包含提交的存储库
- 沙
- 您定义为时间戳的内容(是创作的日期时间,或提交的日期时间 - 请注意,这些并不总是保证相等)
因此,如果您有存储库,您可以像这样检索它:
repo = github3.repository('username', 'repositoryname')
这样,您应该能够git_commit
像这样获取数据:
commit = repo.git_commit('sha1-of-git-commit-i-care-about')
您的commit
值是一个github3.git.Commit
对象的实例,它具有author
和committer
属性是看起来像的字典
"author": {
"date": "2014-11-07T22:01:45Z",
"name": "Scott Chacon",
"email": "schacon@gmail.com"
},
"committer": {
"date": "2014-11-07T22:01:45Z",
"name": "Scott Chacon",
"email": "schacon@gmail.com"
},
所以你可以用以下方式结束它:
commit.author["date"]
我建议使用类似dateutil
解析这些时间戳的实用程序。
于 2019-02-05T19:59:08.490 回答