从Github API查找用户的总贡献
我正试图从github为任何用户提取以下信息从Github API查找用户的总贡献,github,github-api,curl,xmlstarlet,Github,Github Api,Curl,Xmlstarlet,我正试图从github为任何用户提取以下信息 有没有一种方法/api可以直接获取这些信息?您可以使用此函数提取去年的贡献(客户端): 我还编写了一个小节点模块,可以“提取”贡献 也许这会对您有所帮助(即使我已经晚了4年)您可以从https://github.com/users//contributions与toURL参数类似: 您可以使用基本的xml解析器来汇总svg的所有贡献 2016年的一个例子是: curl-s”https://github.com/users/bertrandmar
有没有一种方法/api可以直接获取这些信息?您可以使用此函数提取去年的贡献(客户端): 我还编写了一个小节点模块,可以“提取”贡献
也许这会对您有所帮助(即使我已经晚了4年)您可以从
https://github.com/users//contributions
与to
URL参数类似:
您可以使用基本的xml解析器来汇总svg的所有贡献
2016年的一个例子是:
curl-s”https://github.com/users/bertrandmartel/contributions?to=2016-12-31" | \
xmlstarlet sel-t-v“sum(//svg/g/g/rect/@data count)”
您可以使用:
示例(node.js)
const-got=require('got')
异步函数getEvents(用户名){
常量事件=[]
设page=1
做{
常量url=`https://api.github.com/users/${username}/events?page=${page}`
var{body}=wait-get(url{
json:true
})
页面++
事件。推送(…正文)
}而(!body.length)
返回事件
}
(异步()=>{
const events=await getEvents('handtrix')
console.log('totalevents',Events.length)
console.log('PullRequests',events.filter(event=>event.type==='PullRequestEvent')。长度)
console.log('Forks',events.filter(event=>event.type==='ForkEvent')。长度)
console.log('Issues',events.filter(event=>event.type==='issueEvent')。长度)
console.log('Reviews',events.filter(event=>event.type==='PullRequestReviewEvent')。长度)
})()
示例(javascript)
异步函数getEvents(用户名){
常量事件=[]
设page=1
做{
常量url=`https://api.github.com/users/${username}/events?page=${page}`
var body=wait fetch(url)。然后(res=>res.json())
页面++
事件。推送(…正文)
}而(!body.length)
返回事件
}
(异步()=>{
const events=await getEvents('handtrix')
console.log('totalevents',Events.length)
console.log('PullRequests',events.filter(event=>event.type==='PullRequestEvent')。长度)
console.log('Forks',events.filter(event=>event.type==='ForkEvent')。长度)
console.log('Issues',events.filter(event=>event.type==='issueEvent')。长度)
console.log('Reviews',events.filter(event=>event.type==='PullRequestReviewEvent')。长度)
})()
文档
read:user
卷曲
curl -H "Authorization: bearer token" -X POST -d '{"query":"query {\n user(login: \"MeiK2333\") {\n name\n contributionsCollection {\n contributionCalendar {\n colors\n totalContributions\n weeks {\n contributionDays {\n color\n contributionCount\n date\n weekday\n }\n firstDay\n }\n }\n }\n }\n}"}' https://api.github.com/graphql
JavaScript
异步函数getContributions(令牌、用户名){
常量头={
'Authorization':'bearer${token}`,
}
常数体={
“查询”:“查询”{
用户(登录名:“${username}”){
名称
捐款收集{
捐款{
颜色
捐款总额
周{
捐款日{
颜色
捐款帐户
日期
周工作日
}
第一天
}
}
}
}
}`
}
const response=等待获取('https://api.github.com/graphql“,{method:'POST',body:JSON.stringify(body),headers:headers})
const data=wait response.json()
返回数据
}
常量数据=等待getContributions('token','MeiK2333')
console.log(数据)
我相信您可以在code Climate的Velocity git analytics中看到时间范围内的贡献计数以及其他单个贡献者分析,您可以在此处请求访问:是的,您可以使用新的graphql API轻松做到这一点 查看资源管理器: 在那里,您可以看到贡献集合,它是用户的一个优势。您可以获得重建日历所需的所有信息 我已经包括了一个完整的示例,explorer文档可以进一步指导您 特别是为了回答您的问题,
query.user.contributionCollection.contributionCalendar.totalContributions
这就是你要找的
继续并将以下内容复制/粘贴到资源管理器中,您将看到我去年的贡献历史
query {
user(login: "qhenkart") {
email
createdAt
contributionsCollection(from: "2019-09-28T23:05:23Z", to: "2020-09-28T23:05:23Z") {
contributionCalendar {
totalContributions
weeks {
contributionDays {
weekday
date
contributionCount
color
}
}
months {
name
year
firstDay
totalWeeks
}
}
}
}
}
要加载包含所有贡献的svg,可以在html页面中使用此代码
<img src="http://gchart.rshah.org/username" alt="Name Your Github chart">
要自定义颜色,您可以这样做
<img src="http://ghchart.rshah.org/HEXCOLORCODE/username" alt="Name Your Github chart">
HEXCOLORCODE=17A2B8
使用此方法时请记住,它只返回过去90天的数据。yi:如果您只想知道经过身份验证的用户的总贡献,
{“query”:“query{viewer{contributionCollection{contributionCalendar{totalContrributions}}}}
应该足够了。您能解释一下为什么使用方法POST,它不应该是GET吗?@Maverick这是POST b/c graphQL被用于此请求。请参阅此链接-
<img src="http://ghchart.rshah.org/HEXCOLORCODE/username" alt="Name Your Github chart">