2

I am using github api to get a users commits only those commits which are done by that user not the total commit of the repo only the commits which are done by that user. right now i am using this

code

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

I am passing params as author but it is not working and in some repos it is giving an empty array and sometime it is giving me right response.

for example int his repo all the commits are done by me and it should be me an array whcih have data but is giving me an empty array https://api.github.com/repos/imvsr-0609/chatbud/commits?author=imvsr-0609

and on this i am getting the data. https://api.github.com/repos/imvsr-0609/Music-Player/commits?author=imvsr-0609

why this is happening and why in some repos i am getting empty arrays. and let me know if anyone has other idea of fetching commits of repo for a particular user only

stark
  • 75
  • 2
  • 8

1 Answers1

0

There is a difference between:

The first repository uses signed commit, while the second does not.

If you have added a GPG key to your GitHub account, it is possible it impacts the repos/commits API call.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • is there any way I can fetch both of there commits by user – stark Nov 29 '21 at 07:58
  • @stark Not sure actually: the same API calls should work. If not, try the GitHub GraphQL V4 API: https://stackoverflow.com/a/47523826/6309 – VonC Nov 29 '21 at 08:01
  • can you see https://stackoverflow.com/questions/70173070/how-to-get-commit-by-the-author-using-graphql-github-api – stark Nov 30 '21 at 17:03