Github3.py 1.3.0 获取提交的时间戳
Github3.py 1.3.0 Get timestamp for commit
我查看了文档甚至源代码,但似乎无法弄清楚如何使用 github3.py 库获取提交的时间戳。我很确定它在那里,因为它是一个时间戳。
因此,如果您想获得与存储在 GitHub 中的 git 提交相关的时间戳,那么您需要做一些事情:
- 包含提交的存储库
- SHA
- 您定义的时间戳(是创作的日期时间,或提交的日期时间 - 请注意,这些并不总是保证相等)
因此,如果您有存储库,您可以像这样检索它:
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
这样的实用程序来解析这些时间戳。
我查看了文档甚至源代码,但似乎无法弄清楚如何使用 github3.py 库获取提交的时间戳。我很确定它在那里,因为它是一个时间戳。
因此,如果您想获得与存储在 GitHub 中的 git 提交相关的时间戳,那么您需要做一些事情:
- 包含提交的存储库
- SHA
- 您定义的时间戳(是创作的日期时间,或提交的日期时间 - 请注意,这些并不总是保证相等)
因此,如果您有存储库,您可以像这样检索它:
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
这样的实用程序来解析这些时间戳。