有效地从PyGithub获取最新的提交URL

克里斯·雷德福

我正在使用此功能使用PyGithub获取最新的提交URL

from github import Github

def getLastCommitURL():
    encrypted = 'mypassword'
    # naiveDecrypt defined elsewhere
    g = Github('myusername', naiveDecrypt(encrypted))
    org = g.get_organization('mycompany')
    code = org.get_repo('therepo')
    commits = code.get_commits()
    last = commits[0]
    return last.html_url

它可以工作,但似乎让Github对我的IP地址感到不满意,并且对生成的URL响应缓慢。我有更有效的方法吗?

克里斯·雷德福

如果您在过去24小时内未提交任何内容,则此操作将无效。但是,根据Github API文档,如果这样做,它似乎返回得更快,并且请求的提交次数更少

from datetime import datetime, timedelta

def getLastCommitURL():
    encrypted = 'mypassword'
    g = Github('myusername', naiveDecrypt(encrypted))
    org = g.get_organization('mycompany')
    code = org.get_repo('therepo')
    # limit to commits in past 24 hours
    since = datetime.now() - timedelta(days=1)
    commits = code.get_commits(since=since)
    last = commits[0]
    return last.html_url

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章