如何使用 CURL 获取特定时间段的回购事件 git?

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

我需要使用 CURL 获取特定时间段的 git 事件 当我尝试时:-

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

显示所有事件

如何使用 curl 获取 after=2019-11-01T00:00:00Z 和 before=2019-12-01T23:59:59Z 时间段事件

您可以使用命令行 JSON 处理器 jq 处理从 curl 请求接收到的 JSON 数据。

获取特定数据范围的repo事件的一行命令如下:

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

日期2019-11-01T00:00:00Z2019-12-01T23:59:59ZISO-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中进行日期转换。

日期范围假定为:"2019-11-01T00:00:00Z" < date < "2019-12-01T23:59:59Z"

(-s) in jq用于将过滤后的JSON对象转换为JSON数组。

Reference for the filtering dates in jq