如何使用GitHub API获取GitHub问题的数量?

19

你好,我正在尝试使用Angular和Github Rest API获取存储库的问题数量,但问题在于我只得到了30个问题,即使该存储库中存在更多的问题。 请帮我想出解决办法。 我使用以下REST Api来获取问题。

https://api.github.com/repos/vmg/redcarpet/issues?state=all
1个回答

15

更新的响应

如果您只想知道问题的数量,我认为最接近的方法是使用获取存储库终端:

GET /repos/:owner/:repo

此终端的JSON响应包括两个相关键:

  • has_issues,其值为truefalse,以及
  • open_issues_count,它应该给出打开的问题数量。

我不确定是否有任何方法可以获得包括未打开的问题在内的问题数量。

原始响应

您需要进行分页

Requests that return multiple items will be paginated to 30 items by default. You can specify further pages with the ?page parameter. For some resources, you can also set a custom page size up to 100 with the ?per_page parameter. Note that for technical reasons not all endpoints respect the ?per_page parameter, see events for example.

$ curl 'https://api.github.com/user/repos?page=2&per_page=100'

3
请注意,GitHub搜索API每次搜索限制为1000个结果(https://developer.github.com/v3/search/#search-issues)。实际上,它会返回结果的最后一页,因此如果每页有30个结果,则会得到1020个结果。你可以通过发出多个搜索查询来获取更多结果。 - yoyo
9
我想补充一点,对于任何遇到这个问题的人来说,open_issues_count将为您提供Issues + PRs的计数,因为GitHub将PR视为问题。 - Rohan Lekhwani

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接