从 Github 企业 API 获取日期范围内的问题
Get issues on a date range from Github enterprise API
我想获取在特定日期范围内使用 Github 企业 api 创建的问题列表。我想要做的相当于在问题页面上进行搜索,如下图所示:
我尝试了以下命令:curl -H "Authorization: token myToken" "https://github.mydomain.com/api/v3/repos/owner/repo/issues?state=all&since=2015-09-01" > issues.json
但这并不能满足我的需求,因为根据 Api docs 的参数 since
被描述为:
Only issues updated at or after this time are returned. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
提前致谢!
所以在大量谷歌搜索和阅读 Github API 文档后,我明白了。我需要的是 Github Search API. The first thing i did was figure out what endpoints where available to me on my enterprise API as described in this Whosebug post。所以我使用以下命令来做到这一点:
curl -H "Authorization: token [myToken]" "https://github.mydomain.com/api/v3/"
响应中返回的端点之一是:
"issue_search_url": "https://github.mydomain.com/api/v3/search/issues?q={query}{&page,per_page,sort,order}"
使用该端点,我构建了以下命令来满足我的需求:
curl -H "Authorization: token [myToken]" "https://github.mydomain.com/api/v3/search/issues?page=1&per_page=100&sort=created&order=asc&q=repo:[Owner]/[RepoName]+is:issue+created:>=2015-09-01"
让我们分解参数(? 符号后的任何内容):
page=1&per_page=100
:此请求的默认结果数为每页 30 个。就我而言,我有 664 个结果。所以我需要执行多个请求,指定哪个页面 (page=1
) 以及该请求需要多少结果 (per_page=100
),直到我得到所有这些。在我的例子中,我每次更改页码时都用上面的 url 做了 7 个请求。有关详细信息,请参阅 Github docs on Pagination
&sort=created&order=asc
:按创建日期升序排列(从大到小)。参见 Github Search API and Searching Issues
q=repo:[Owner]/[RepoName]+is:issue+created:>=2015-09-01
:形成一个搜索查询 (q=
),将搜索限制为从 2015 年 9 月 1 日到 (created:>=2015-09-01
) 创建的问题 (is:issue
) ) 在回购 Owner/Name (repo:[Owner]/[RepoName]
)
希望这对其他人有帮助,因为我发现 Github api 文档不是很清楚。
我想获取在特定日期范围内使用 Github 企业 api 创建的问题列表。我想要做的相当于在问题页面上进行搜索,如下图所示:
我尝试了以下命令:curl -H "Authorization: token myToken" "https://github.mydomain.com/api/v3/repos/owner/repo/issues?state=all&since=2015-09-01" > issues.json
但这并不能满足我的需求,因为根据 Api docs 的参数 since
被描述为:
Only issues updated at or after this time are returned. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
提前致谢!
所以在大量谷歌搜索和阅读 Github API 文档后,我明白了。我需要的是 Github Search API. The first thing i did was figure out what endpoints where available to me on my enterprise API as described in this Whosebug post。所以我使用以下命令来做到这一点:
curl -H "Authorization: token [myToken]" "https://github.mydomain.com/api/v3/"
响应中返回的端点之一是:
"issue_search_url": "https://github.mydomain.com/api/v3/search/issues?q={query}{&page,per_page,sort,order}"
使用该端点,我构建了以下命令来满足我的需求:
curl -H "Authorization: token [myToken]" "https://github.mydomain.com/api/v3/search/issues?page=1&per_page=100&sort=created&order=asc&q=repo:[Owner]/[RepoName]+is:issue+created:>=2015-09-01"
让我们分解参数(? 符号后的任何内容):
page=1&per_page=100
:此请求的默认结果数为每页 30 个。就我而言,我有 664 个结果。所以我需要执行多个请求,指定哪个页面 (page=1
) 以及该请求需要多少结果 (per_page=100
),直到我得到所有这些。在我的例子中,我每次更改页码时都用上面的 url 做了 7 个请求。有关详细信息,请参阅 Github docs on Pagination&sort=created&order=asc
:按创建日期升序排列(从大到小)。参见 Github Search API and Searching Issuesq=repo:[Owner]/[RepoName]+is:issue+created:>=2015-09-01
:形成一个搜索查询 (q=
),将搜索限制为从 2015 年 9 月 1 日到 (created:>=2015-09-01
) 创建的问题 (is:issue
) ) 在回购 Owner/Name (repo:[Owner]/[RepoName]
)
希望这对其他人有帮助,因为我发现 Github api 文档不是很清楚。