2016-11-16 66 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文檔沒有提及這個,所以謝謝! –