3

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!

Sarah
  • 33
  • 2

1 Answers1

1

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'graffatcolmingov+bmorriso@gmail.com'}
>>> commit.commit.author
{u'date': u'2013-09-05T02:23:17Z', u'name': u'Barry Morrison and Ian Cordasco', u'email': u'graffatcolmingov+bmorriso@gmail.com'}
Ian Stapleton Cordasco
  • 26,944
  • 4
  • 67
  • 72
  • thanks for the answer.. the check for None is because (similar to that one commit case), there were some commits where the committer or author were None which is why I had to have this check. However, my question was actually about getting the email address. This is the one field that I find to *always* be None when you do commit.committer.email – Sarah Aug 09 '15 at 11:14
  • Well you can always get it from `commit.commit.committer['email']`. If you don't want to do that then calling `commit.committer.refresh()` should do the trick if the user has a public email address. – Ian Stapleton Cordasco Aug 09 '15 at 13:17
  • Thanks! Both ways work and give me the information I want. – Sarah Aug 11 '15 at 07:57