Get user activity statistics from GitHub API

夙愿已清 提交于 2020-08-05 10:51:19

问题


I've been poking through the GitHub API documentation and I can't seem to find a way to get the data that powers the "Contribution Activity" section and the contribution chart for a user's profile. Is there a way to get this through the API?

I know that there are user/:user/events and /recieved_events endpoints, but these seem to mostly consist of when the user stars repositories. I'm uninterested in the actual information of which repository/what commit/etc, but only interested in getting a time-series (or something like that) of commit/issue/etc. activity data that forms the contribution chart and activity portions of the profile page. Ideally numbers across all Github activity regardless of which repo/repo privacy/etc.

All I'm trying to do is incorporate this into my Github pages website.


回答1:


Most contribution data can be fetched using Github GraphQL API - https://developer.github.com/v4/

I was using this method for doing a widget that shows the last user contributions list. And it works well and offers many of filtering/grouping opportunities

a.e you can get contribs count by day:

{
  user(login: "orn0t") {
    contributionsCollection {
      contributionCalendar {
        totalContributions
        weeks {
          contributionDays {
            contributionCount
            weekday
            date
          }
        }
      }
    }
  }
}

If you're looking for working code examples:

you can view my project on Github - https://github.com/orn0t/gh-contrib-widget.



来源:https://stackoverflow.com/questions/57794864/get-user-activity-statistics-from-github-api

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