如何解决在 get_files() 之后访问文件内容的 Github Python API
我希望使用 pygithub 访问在 github 拉取请求中更改的内容文件。我设法使用
获得了文件列表repo = gh.get_repo(repo_url)
pr = repo.get_pull(30)
for file in pr.get_files():
print(file)
但是我不知道如何访问文件的内容。我看到它有一个文件名和 sha。
解决方法
filename
方法将返回每个文件的名称。然后您可以使用 get_contents
方法获取每个文件的内容。
from github import Github
github = Github('user','token')
user = github.get_user()
repository = user.get_repo('YourRepository')
pr = repository.get_pull(30)
filelist = []
for file in pr.get_files():
filelist.append(file.filename)
for each_file in filelist:
print(repository.get_contents(each_file))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。