【问题标题】:Recommended way to list all repos/commits for a given user using github3.py使用 github3.py 列出给定用户的所有 repos/commits 的推荐方法
【发布时间】:2017-03-15 15:44:53
【问题描述】:

我正在构建一个 GitHub 应用程序以从我们的内部存储库中提取提交信息。我正在使用以下代码来迭代所有提交:

gh = login(token=gc.ACCESS_TOKEN)
for repo in gh.iter_repos():
    for commit in repo.iter_commits():
        print(commit.__dict__)
        print(commit.additions)
        print(commit.author)
        print(commit.commit)
        print(commit.committer)
        print(commit.deletions)
        print(commit.files)
        print(commit.total)

添加/删除/总计值都返回为0,并且文件属性始终为[]。当我单击 url 时,我可以看到情况并非如此。我通过curl调用验证了API确实有这些属性的记录。

在文档中阅读更多内容,似乎 iter_commits 已被弃用,取而代之的是 iter_user_commits。这可能是为什么它没有返回有关提交的所有信息的情况吗?但是,当我这样使用此方法时,它不会为我返回任何存储库:

gh = login(token=gc.ACCESS_TOKEN)
user = gh.user()
for repo in gh.iter_user_repos(user):

简而言之,我想知道推荐的方法是获取用户有权访问的所有存储库的所有提交。

【问题讨论】:

    标签: github3.py


    【解决方案1】:

    iter_repos 与登录的 GitHub 实例没有任何问题。

    简而言之,这就是发生的事情(这在 github3.py 的文档中有所描述):当列出来自 GitHub 的 API 的资源时,并非所有属性都实际返回。如果您想要所有信息,则必须为每个提交请求信息。简而言之,您的代码应如下所示:

    gh = login(token=gc.ACCESS_TOKEN)
    for repo in gh.iter_repos():
        for commit in repo.iter_commits():
            commit.refresh()
            print(commit.additions)
            print(commit.deletions)
            # etc.
    

    【讨论】:

    • 啊,错过了refresh 方法。谢谢!
    猜你喜欢
    • 2023-03-21
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    • 1970-01-01
    • 2014-03-28
    • 1970-01-01
    相关资源
    最近更新 更多