1

I developing a web service which uses some Github info. I need to get a list of files which changed with a commit. I found a list of libraries. I tried all 3 Java libraries and github3.py. And all these libraries returns me a commit info with an empy list of affected files(or null for Java libs). The code for getting list of affected files is really easy so I have no idea why it happens.

from github3 import login, repository


repo = repository('sigmavirus24', 'github3.py')
commits = repo.iter_commits()
for commit in commits:
    print len(commit.files) #prints 0

UPD: How I can get a list of files changed by specific commit?

2
  • So what exactly is your question? Commented Sep 13, 2014 at 1:23
  • @MattDMo Sorry. Updated Commented Sep 13, 2014 at 1:25

1 Answer 1

1

When iterating over a resource (in this case commits) the GitHub API often returns a subset of the information that is available for one instance of that resource. Using your code, let's try something

from github3 import repository

commits = repository('sigmavirus24', 'github3.py').iter_commits()
c = next(commits)
print(len(c.files))  # => 0
print(c.refresh())  # => <Repository Commit [0eec5f6]>
print(len(c.files))  # => 1
print(c.files)
# [{u'status': u'modified', u'deletions': 0, ... }]

github3.py provides (on most objects) a refresh method that will fetch that particular instances complete data from the API. This will unfortunately result in more API calls than you might like though. A common pattern for some is to do

r = repository('sigmavirus24', 'github3.py')
cs = r.iter_commits(50)  # Limit it to 50 commits
commits = [c.refresh() for c in cs]

In this case you're making exactly 51 API calls, 1 for the listing of the first 50 commits, and 50 to get all of the data for each commit from the API.

I'm not sure if the Java wrappers provide any similar capability

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.