0

I'm looking to access the content files that were changed in a github pull request using pygithub. I've managed to get a list of the files using

repo = gh.get_repo(repo_url)
pr = repo.get_pull(30)

for file in pr.get_files():
    print(file)

But I don't know how to access the contents of the file. I see it has a filename and sha.

FortuneFaded
  • 1,259
  • 4
  • 20
  • 28

1 Answers1

0

The filename method will return the name of each file. You can then use the get_contents method to get each file's content.

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))
mehtaarn000
  • 176
  • 1
  • 3
  • 11