email - 获取提交者电子邮件

标签 email github-api git-commit github3.py

我正在尝试将项目提交者的电子邮件地址获取到特定文件。创建查询以在符合特定条件的存储库列表中查找代码文件后,我以 code_results(类型为 CodeSearchResult)的形式获得了正确的结果。现在尝试访问提交信息,我执行以下操作

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

问题是尝试通过 commit.committer.email 获取电子邮件总是返回无,即使文档说提交包含提交者的电子邮件。我还尝试了作者而不是提交者,因为文档说作者是包含电子邮件的字典,但我不确定字典键是什么。

谢谢!

最佳答案

许多返回列表的 GitHub 端点仅返回列表中的部分对象。老实说,提交者或作者永远不会是 None 是很奇怪的,但是您可以尝试这样做:

for commit in commits:
    commit = commit.refresh()
    if commit.committer is not None:
        print commit.committer

也就是说,在针对 github3.py 进行测试时,我无法重现此问题。我做了

repository = github3.repository('sigmavirus24', 'github3.py')
for commit in repository.commits(path='setup.py'):
     print(commit.committer)
     print(commit.author)

除了一个提交之外,两个提交总是存在的。那是来自 this commit用户没有 GitHub 帐户的地方。也就是说,然后我可以检查 commit.commit 以获取有关 git commit 对象本身的原始数据。它同时具有 committerauthor 对象,请参阅

>>> 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'}

关于email - 获取提交者电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31860421/

相关文章:

java - 应用程序 :preDexDebug error sending mail using java mail 执行失败

python - 如何发送 utf-8 的电子邮件?

python - Github-api 在使用 python + urllib2 传递 json 数据时给出 404

Git 计数过滤的提交

Git 缺少提交

git - 如何在没有优点和缺点的情况下复制 GitHub 中的提交差异的一部分?

c# - 简单的电子邮件转发服务器

android - 邮件中的图像附件..在android中如何?

ios - GitHub API 未解析

ruby-on-rails - Rails 中的 Github 身份验证 API