【问题标题】:in GitHub api how to get commit done by a particular user in a repo在 GitHub api 中如何让特定用户在 repo 中完成提交
【发布时间】:2022-01-06 01:57:48
【问题描述】:

我正在使用 github api 来获取用户仅提交由该用户完成的提交,而不是 repo 的总提交,仅提交由该用户完成的提交。 现在我正在使用这个

代码

def total_commit_user_func(repo_name, username):
    commit_by_user = 0
    try:
        url = "https://api.github.com/repos/"+username+"/"+repo_name+"/commits"
        page_no = 1
        while (True):
            response = requests.get(url, headers=headers, params={
                                    "author": username, "per_page": 100})
            response = response.json()
            commit_by_user = len(response)+commit_by_user
            commit_by_user_fetched = len(response)
            if (commit_by_user_fetched == 100):
                page_no = page_no + 1
                url = url + '?page=' + str(page_no)
            else:
                break

        return commit_by_user
    except:
        print("ERROR while getting commits by user")
        return commit_by_user

我以作者的身份传递参数,但它不起作用,并且在某些存储库中它给出了一个空数组,有时它给了我正确的响应。

例如,在他的仓库中,所有提交都是由我完成的,它应该是我一个有数据但给我一个空数组的数组 https://api.github.com/repos/imvsr-0609/chatbud/commits?author=imvsr-0609

我正在获取数据。 https://api.github.com/repos/imvsr-0609/Music-Player/commits?author=imvsr-0609

为什么会发生这种情况以及为什么在某些存储库中我得到空数组。 如果有人有其他想法只为特定用户获取 repo 提交,请告诉我

【问题讨论】:

    标签: python github github-api


    【解决方案1】:

    两者之间有区别:

    第一个存储库使用签名提交,而第二个没有。

    如果您添加了GPG key to your GitHub account,它可能会影响repos/commits API call

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-27
    • 2014-05-23
    • 2020-01-08
    • 2016-08-27
    • 2015-03-02
    • 1970-01-01
    • 1970-01-01
    • 2012-08-01
    相关资源
    最近更新 更多