【问题标题】:Github3.py 1.3.0 Get timestamp for commitGithub3.py 1.3.0 获取提交时间戳
【发布时间】:2019-06-28 14:37:47
【问题描述】:

我查看了文档甚至源代码,但似乎无法弄清楚如何使用 github3.py 库获取提交的时间戳。我很确定它在那里,因为它是一个时间戳。

【问题讨论】:

    标签: python github github3.py


    【解决方案1】:

    因此,如果您想获得与存储在 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 对象的一个​​实例,该对象具有authorcommitter 属性,这些属性类似于字典

      "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 这样的实用程序来解析这些时间戳。

    【讨论】:

    • 弃用警告:匿名 API 函数 github3.api.repository 已弃用。请改用GitHub.repository
    猜你喜欢
    • 1970-01-01
    • 2017-08-30
    • 2015-12-27
    • 2019-06-24
    • 2021-12-11
    • 2015-11-22
    • 2015-09-28
    • 2014-05-06
    • 1970-01-01
    相关资源
    最近更新 更多