Github API - retrieve user commits?

后端 未结 5 1151
日久生厌
日久生厌 2021-02-13 11:36

I\'m trying build a method in which I can access a Github user name, and publish either all commits or at least a number of commits from that user.

Is there a call to GE

5条回答
  •  别跟我提以往
    2021-02-13 12:15

    Maybe others are interested in this at later time.

    1. There is no API for retrieving all the commits of one user -> you have to do it yourself.

    2. The way you described it is good, but you missed out that from 2 and 4 you will get all commits, not only of that user.

    Github API allows you to get the list of commits by author filtering https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository

    My suggestion is to do the following:

    1. Retrieve the repositories of that user, parse the JSON response and get the names of the repository in an array.

      • API Link - api.github.com/users/:user/repos
      • Replace :user with your desired user.
    2. For each repository, get the list of commits authored by that user.

      • API Link - api.github.com/repos/:user/{repositoryNameFromArray}/commits?author=:user.
      • Replace :user with your desired user, and {repositoryNameFromArray} should come from your array.

    Here be careful that Github retrieves by default only the last 30 commits. You need to use pagination to get larger chunks, max 100.

    You're done. The rest is up to you and what you want to do with the data.

提交回复
热议问题