Pradeep Chandran
Pradeep Chandran

Reputation: 337

How to get git events of repo for specific time period with CURL?

i need to get the git events for specific time period with CURL When i try:-

curl https://api.github.com/repos/username/repo/events

it shows all the events

how can i get after=2019-11-01T00:00:00Z and before=2019-12-01T23:59:59Z time period events using curl

Upvotes: 1

Views: 708

Answers (1)

Saurabh P Bhandari
Saurabh P Bhandari

Reputation: 6742

You can process the JSON data received from the curl request using jq, a command-line JSON processor.

The one-liner command for getting repo events for a specific data range is as follows :

curl https://api.github.com/repos/username/repo/events | jq '. [] | select (.created_at | fromdateiso8601 > 1572566400 and fromdateiso8601 < 1575244799)' | jq -s '.'

The dates 2019-11-01T00:00:00Z and 2019-12-01T23:59:59Z are in ISO-8601 format, so using built-in date handling functionality of jq, ISO-8601 format can be represented in number of seconds since the Unix epoch (1970-01-01T00:00:00Z). Checkout this snippet at jqplay to convert the dates.

Date range is assumed to be this : "2019-11-01T00:00:00Z" < date < "2019-12-01T23:59:59Z"

slurp mode (-s) in jq is used to convert the filtered JSON objects to JSONarray.

Reference for the filtering dates in jq

Upvotes: 3

Related Questions