Reputation: 1140
I am trying to create a WordPress widget that displays a user's repository information and number of commits (limited to the last 30 days). I got the repository info very easily, but am struggling with the second part. I'm using PHP in this case, and displaying the info in a WordPress widget.
Basically I need the API to return the number of commits that a user made in a given month across all (public) repositories. Is there any easy endpoint to access this, or will I have to loop through each of the user's repositories active in the last month and pull the number of commits from there?
Upvotes: 2
Views: 591
Reputation: 1329112
Another approach is to list events for a given user
GET /users/:username/events
Example: https://api.github.com/users/VonC/events
{
"id": "3406063602",
"type": "PushEvent",
"actor": {
"id": 79478,
"login": "VonC",
"gravatar_id": "",
"url": "https://api.github.com/users/VonC",
"avatar_url": "https://avatars.githubusercontent.com/u/79478?"
},
"repo": {
"id": 47265668,
"name": "VonC/hello-world-go",
"url": "https://api.github.com/repos/VonC/hello-world-go"
},
"payload": {
"push_id": 889397803,
"size": 2,
"distinct_size": 2,
"ref": "refs/heads/master",
"head": "54dd9bd15fea2476bd76c7bf88bcec370d9dfc61",
"before": "64d3b59911fef0b0c2423c105c38aabf99332e28",
"commits": [
{
"sha": "ee856fa87073cf92e11baa4d36f61394de937085",
...
You will have to filter for PushEvent
, and iterate over the pages of events until getting an event older than a month ago.
Upvotes: 1