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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33374778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 16:25:45  来源:igfitidea点击:

How can I get the number of GitHub issues using the GitHub API?

javascriptangularjsgithubgithub-api

提问by Sanju Uthaiah Bollera

Hi I am trying to get the number of issues of a repo using angular and Github Rest API, But the problem is that I get only 30 issues even though more issues are there in that repo. Please help me with the idea. I use the below REST Api to get the issues.

嗨,我正在尝试使用 angular 和 Github Rest API 获取存储库的问题数量,但问题是即使该存储库中存在更多问题,我也只得到 30 个问题。请帮我解决这个问题。我使用下面的 REST Api 来解决问题。

https://api.github.com/repos/vmg/redcarpet/issues?state=all

回答by Chris

Updated response

更新回复

If you just want the number ofissues I think the closest you'll get is with the get repoendpoint:

如果您只想要问题的数量,我认为最接近的是get repo端点:

GET /repos/:owner/:repo

获取 /repos/:owner/:repo

The JSON response from this endpoint includes two relevant keys:

来自该端点的 JSON 响应包括两个相关的键:

  • has_issues, which will be trueor false, and
  • open_issues_count, which should give you the number of open issues.
  • has_issues,这将是truefalse,并且
  • open_issues_count,这应该给你开放问题的数量。

I'm not sure of any way to get the number of issues including ones that aren't open.

我不确定有什么方法可以获取问题的数量,包括未打开的问题。

Original response

原始回复

You'll need to paginate:

你需要分页

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

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

默认情况下,返回多个项目的请求将分页为 30 个项目。您可以使用?page参数指定更多页面。对于某些资源,您还可以使用?per_page参数设置最大 100 的自定义页面大小。请注意,出于技术原因,并非所有端点都遵守该?per_page参数,例如,请参阅事件

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