从Github企业API获取有关日期范围的问题

问题描述:

我想获取使用Github企业API在特定日期范围内创建的问题列表.我想做的事情等同于在问题页面上进行搜索,如下图所示:

I want to get a list of issues that have been created in a specific date range using the Github enterprise api. What I want to do would be the equivalent of doing a search on the issues page as shown on the image below:

我尝试了以下命令: curl -H"Authorization:token myToken""https://github.mydomain.com/api/v3/repos/owner/repo/issues?state=all&since= 2015-09-01>issues.json ,但这不能满足我的需要,因为根据

I have tried the following command: curl -H "Authorization: token myToken" "https://github.mydomain.com/api/v3/repos/owner/repo/issues?state=all&since=2015-09-01" > issues.json but that does not give me what i need because the parameter since according to the Api docs is described as:

仅返回在此时间或之后更新的问题.这是ISO 8601格式的时间戳:YYYY-MM-DDTHH:MM:SSZ

Only issues updated at or after this time are returned. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ

提前谢谢!

因此,经过大量的Google搜索和阅读Github API文档后,我发现了这一点.我需要的是 Github搜索API .我所做的第一件事是按照

So after lots of googling and reading through the Github API docs I figured it out. What i needed for this was the 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 * post. So I used the following command to do that:

curl -H授权:令牌[myToken]""https://github.mydomain.com/api/v3/"

响应中返回的端点之一是:

One of the endpoints returned in the response was:

"issue_search_url":"https://github.mydomain.com/api/v3/search/issues?q={query}{&page,per_page,sort,order}"

使用该端点,我构造了以下命令,该命令可以提供所需的信息:

Using that endpoint, I constructed the following command that gave me what I needed:

curl -H授权:令牌[myToken]""https://github.mydomain.com/api/v3/search/issues?page=1&per_page=100&sort=created&order=asc& q = repo:[所有者]/[RepoName] + is:issue + created:> = 2015-09-01"

让我们分解参数(?号之后的任何内容):

Let's break down the parameters (anything after the ? sign):

  • page = 1& per_page = 100 :此请求的默认结果数是每页30个.就我而言,我有664个结果.因此,我需要执行多个请求,以指定要访问该请求的页面( page = 1 )和多少个结果( per_page = 100 ),直到获得所有这些信息为止.在我的情况下,每次更改页码时,我都对上述网址做了7个请求.有关更多信息,请参见有关分页的Github文档
  • & sort = created& order = asc :按升序(创建时间最早)从创建日期开始排序.请参见 Github搜索API
  • page=1&per_page=100: The default number of results for this request is 30 per page. In my case I had 664 results. So I needed to do multiple request specifying which page (page=1) and how many results I wanted for that request (per_page=100) until i got all of them. In my case i did 7 request with the above url each time changing the page number. For more info see the Github docs on Pagination
  • &sort=created&order=asc: Sor by the created date in ascending order (oldest first). See Github Search API and Searching Issues
  • q=repo:[Owner]/[RepoName]+is:issue+created:>=2015-09-01: Form a search query (q=) that limits the search to issues (is:issue) created from 2015-09-01 and on (created:>=2015-09-01) in the repo Owner/Name (repo:[Owner]/[RepoName])

希望这对其他人有帮助,因为我发现Github api文档不是很清楚.

Hope this helps others as I have found that the Github api docs are not very clear.