简体   繁体   English

使用 Github Api 获取存储库数量

[英]Fetch number of repositories using Github Api

I need to fetch the number of public repositories of a user using the Github API.我需要使用 Github API 获取用户的公共存储库的数量。 I know that we can get a list of repos using /users/{username}/repos .我知道我们可以使用/users/{username}/repos获得一个 repos 列表。 This query returns a list of repositories.此查询返回存储库列表。 What I want is just the total number of repositories not the entire list.我想要的只是存储库的总数而不是整个列表。 If I try to count the repositories using /users/{username}/repos it works fine for the users that have smaller number of repositories but for users that have a large number of repositories, the API call takes too much time.如果我尝试使用/users/{username}/repos对存储库进行计数,它对于存储库数量较少的用户来说工作正常,但对于拥有大量存储库的用户来说,API 调用需要太多时间。 Is there any way by which I can get just the number of repos and not the entire list?有什么方法可以让我只获得回购的数量而不是整个列表?

The total_count field on the first response represents the total count of repositories matching, the response has your answer already.第一个响应上的total_count字段表示匹配的存储库的总数,响应已经有了你的答案。

Instead of getting the list of repositories, you can get the user object and look at the public_repos field;您可以获取用户 object 并查看public_repos字段,而不是获取存储库列表; for example, using the GitHub CLI:例如,使用 GitHub CLI:

$ gh api users/bewuethr | jq '.public_repos'
21

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM