2016-11-16 59 views
3

我想知道应该调用哪个方法(以及哪个对象)以及如何调用该方法(必需的参数及其含义)。如何使用PyGithub更新文件?

在此先感谢!

+0

两个地方开始:https://developer.github.com/v3/repos/contents/和https://github.com/PyGithub/ PyGithub/blob/master/github/InputFileContent.py –

回答

3
import github 

g = github.Github(token) 
# or g = github.Github(login, password) 

repo = g.get_user().get_repo("repo_name") 
file = repo.get_file_contents("/your_file.txt") 

# update 
repo.update_file("/your_file.txt", "your_commit_message", "your_new_file_content", file.sha) 

如果使用令牌,那么你至少应该有回购您的令牌范围 做到这一点。 https://developer.github.com/v3/oauth/#scopes

参见:https://developer.github.com/v3/repos/contents/https://github.com/PyGithub/PyGithub

+0

PyGithub文档没有提及这个,所以谢谢! –