我正在使用此功能使用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响应缓慢。我有更有效的方法吗?
python大神给出的解决方案
如果您在过去24小时内未提交任何内容,则此操作将无效。但是,根据Github API documentation的说明,如果这样做,它似乎返回得更快并且将请求更少的提交:
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