Github API: Get number of contributions on a day by day basis

梦想与她 提交于 2021-02-07 16:39:14

问题


I want to GET from the Github API, the number of contributions per day. I'm making a webapp that compares the number of github contributions to the number of Dota 2 matches I play.

This picture should explain things more clearly.

http://i.stack.imgur.com/cZ1XK.png

I have scoured the Github API and the internet looking for a simple solution and some of the answers I've seen weren't what I was looking for. This Github API get last year of commit activity blurb is the closest I've gotten to finding a solution, but using it would involve making the API call for ALL repos in my account and concatenating the data into one JSON. If there are no solutions to this I would like to know it so I can abandon ship.

Thanks!


回答1:


You can use the svg calendar data with the url :

https://github.com/users/USER/contributions?to=2016-12-25

You can set the to query param to your target day and then parse the svg result to get the last data in the output calendar.

For the web integration part, you can use a proxy like urlreq. An example :

const user = 'bertrandmartel';
const day = "2016-12-25";

fetch('https://urlreq.appspot.com/req?method=GET&url=https%3A%2F%2Fgithub.com%2Fusers%2F' + user + '%2Fcontributions%3Fto%3D' + day)
  .then(function(response) {
    return response.text();
  })
  .then(function(text) {
    xmlDoc = new DOMParser().parseFromString(text, 'text/xml');
    var nodes = xmlDoc.getElementsByTagName('rect');
    var dayContributions = nodes[nodes.length-1].getAttribute('data-count');
    console.log('contributions count for ' + day + ' : ' + dayContributions);
  })
  .catch(function(error) {
    console.log('Request failed', error)
  });


来源:https://stackoverflow.com/questions/28510568/github-api-get-number-of-contributions-on-a-day-by-day-basis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!