0
votes

We want to get pull requests OR merge requests from now to a date in the past ("created_at" or "merged_at" date).

Is there any way to get a list of data that "created_at" or "merged_at" from a date (Ex: 2019-02-02) to now? If yes, how it looks like when using curl command?

You can see the JSON structure from the links listed below. Thank you very much.

Ex: "created_at" >= 2019-02-02

curl "https://github.com/api/v3/repos/{repoIdOrName}/pulls?state=closed" -X GET -H "Authorization: token XXXX" -H "Accept: application/vnd.github.sailor-v-preview+json"
curl "https://gitlab.com/api/v4/projects/{repoIdOrName}/merge_requests?target_branch=master" -XGET -H "PRIVATE-TOKEN: XXXX"
2

2 Answers

0
votes

For gitlab, according to the docs you mentioned, you could use created_after parameter. so:

curl "https://gitlab.com/api/v4/projects/{repoIdOrName}/merge_requests?target_branch=master&created_after=2020-02-02" -XGET -H "PRIVATE-TOKEN: XXXX"

should do the trick

0
votes

Unfortunately, the .../<owner>/<repo>/pulls route doesn't currently allow this kind of query. To accomplish this, you need to use the general-purpose .../issues route. In GitHub, a Pull Request is an instance of an Issue.

Adapt and curl the following URL (substitute <owner> and <repo> for your own):

https://api.github.com/search/issues?q=repo:<owner>/<repo>+is:pr+created:>=2020-08-15

A few remarks:

  • I've left out the authentication part; use the strategy that fits your use case.
  • The structure of the result is different: the .../pulls route returns an array, while the .../issues route returns an object with an embedded array in the field items. Also, the returned objects contain less information than what's returned by the .../pulls route. For example, the merged_at field is absent, as is the _links field. However, in each PR object, there is a .pull_request.url field containing an URL that will return all the PR data you would get from the .../pulls URL, in the same format.
  • If you need to filter by the updated_at date field, just put updated instead of created in the above query. closed and merged seem to also work.
  • You can perform sorting of the results by appending something like &sort=created&order=asc to the query URL.
  • Pagination is handled the same way: if your query results contain too many items, the link to the next page is provided in the header (use -I argument with curl), that you can grep with the regex '^link:.*?<([^>]+)>; rel="next".+' to extract the next page's link in the first group.