Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Api获取github中项目的总数和最新提交_Github_Github Api - Fatal编程技术网

如何使用Api获取github中项目的总数和最新提交

如何使用Api获取github中项目的总数和最新提交,github,github-api,Github,Github Api,实际上,我有两个想法来计算提交的总数 一个想法是使用api,比如:https://api.github.com/repos/mojombo/grit/commits,这种方式可以获得所有提交,我们可以对其进行计数以获得提交的总数和持续日期。但主要的问题是,有太多的提交,这将是缓慢的 另一个想法是,因为我已经使用apihttps://api.github.com/repos/mojombo/grit/contributors,贡献者的总数与我在中看到的相同,从这个api调用中,我还得到每个贡献者的

实际上,我有两个想法来计算提交的总数

一个想法是使用api,比如:
https://api.github.com/repos/mojombo/grit/commits
,这种方式可以获得所有提交,我们可以对其进行计数以获得提交的总数和持续日期。但主要的问题是,有太多的提交,这将是缓慢的

另一个想法是,因为我已经使用api
https://api.github.com/repos/mojombo/grit/contributors
,贡献者的总数与我在中看到的相同,从这个api调用中,我还得到每个贡献者的贡献,然后我将所有贡献者的贡献相加,它应该与网站具有相同的价值,但不幸的是,它与513不同。代码如下,我可以知道为什么会有差异吗

import json, requests
all_contributors = list()
page_count = 1
total_contributions=0
while True:
    contributors = requests.get("https://api.github.com/repos/mojombo/grit/contributors?page=%d"%page_count)
    if contributors != None and contributors.status_code == 200 and len(contributors.json()) > 0:
        all_contributors = all_contributors + contributors.json()
    else:
        break
    page_count = page_count + 1
total_contributor=len(all_contributors)
for contr in all_contributors:
    total_contributions=total_contributions+contr['contributions']
print("--------total contributor-----------%d" %total_contributor) //print 43
print("--------total commits-----------%d" %total_contributions) //print 497

谢谢

我觉得你错过了一些匿名提交。要包含匿名贡献者,您可以将代码更改为-
contributors=requests.get(“https://api.github.com/repos/mojombo/grit/contributors?anon=1&page=%d%page\u count)

我已经知道如何获取最新提交:)