lucifer7
lucifer7

Reputation: 13

Get all the file Contents of a repo at Specific Commit using PyGitHub

I want to get the file contents of all the files in the repo [changed and unchanged] using the Python [PyGitHub API]. But not sure how to achieve it. Simply, to browse the repo at that specific commit id in history.

Is there any other API to get the required data? or can be done with PyGitHub itself.

Note: I'm using Github API v3.

Upvotes: 1

Views: 2308

Answers (1)

VonC
VonC

Reputation: 1323883

Provided you are not downloading a file too large (more than 1MB), as seen in PyGithub/PyGithub/issue 661, the idea is to:

  • request the Repository content at a specific commit
  • get the files returned by the first call

That is:

contents = repository.get_dir_contents(urllib.parse.quote(server_path), ref=sha)

Then:

for content in contents:
   if content.type != 'dir':
     file_content = repository.get_contents(urllib.parse.quote(content.path), ref=sha)
     // or
     file_content = repository.get_git_blob(content.sha)

Upvotes: 1

Related Questions