Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get issues on a date range from Github enterprise 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:

issue search

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:

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

Thanks in advance!

like image 976
Jc Almonte Avatar asked Jun 07 '18 16:06

Jc Almonte


1 Answers

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 stackoverflow post. So I used the following command to do that:

curl -H "Authorization: token [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 "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"

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

  • 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])

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

like image 106
Jc Almonte Avatar answered Sep 19 '22 09:09

Jc Almonte