I am trying to get the email addresses of the committers of a project to specific files. After creating a query that finds the code files in a list of repos matching specific criteria, I get the correct results in the form of code_results (of type CodeSearchResult). Now to try access the commit information, I do the following
for code_result in code_results:
repository = code_result.repository
file_path = code_result.path
commits = repository.commits(path=file_path)
for commit in commits:
if commit.committer is not None:
print commit.committer
The problem is that trying to get the email through commit.committer.email always returns None even though the documentation says that a commit contains the committer's email. I also tried author instead of committer since the documentation says the author is a dict containing the email, but I'm not sure what the dict keys are.
Thanks!
Many of GitHub's endpoints that return listings only return partial objects in the listing. It's odd that committer or author would ever be None, honestly, but you could try doing:
for commit in commits:
commit = commit.refresh()
if commit.committer is not None:
print commit.committer
That said, in testing this against github3.py, I can't reproduce this problem. I did
repository = github3.repository('sigmavirus24', 'github3.py')
for commit in repository.commits(path='setup.py'):
print(commit.committer)
print(commit.author)
And with the exception of one commit, both were always present. That was from this commit where the user didn't have a GitHub account. That said, I can then inspect commit.commit to get the raw data about the git commit object itself. That has both a committer and author object, see
>>> commit.commit.committer
{u'date': u'2013-09-05T02:23:17Z', u'name': u'Barry Morrison and Ian Cordasco', u'email': u'[email protected]'}
>>> commit.commit.author
{u'date': u'2013-09-05T02:23:17Z', u'name': u'Barry Morrison and Ian Cordasco', u'email': u'[email protected]'}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With