【发布时间】:2018-02-07 09:00:28
【问题描述】:
我正在使用 GitHub 企业 API 来获取我的一个存储库中的问题列表。 但是,我需要过滤输出,以便获得自上周以来创建的问题列表。
下面是我到目前为止到达的地方并且工作正常。我需要帮助来过滤自上周以来创建的问题。
#!/bin/sh
tot_page=`curl -k -I https://<my_pat>:x-oauth-basic@github.developer.blah.com/api/v3/repos/droppin/remotedev/issues?state=all\&per_page=10 2>/dev/null | awk -F'[&=<>]' '{for(i=1;i<=NF;i++) if($i ~ /^page$/) {kk=$(i+1)}} END{print kk}'`;
echo "$tot_page"
for ((i=1;i<=tot_page;i++))
do
curl -k https://<my_pat>:x-oauth-basic@github.developer.blah.com/api/v3/repos/droppin/remotedev/issues?state=all\&per_page=2\&page=$i 2>/dev/null |
jq -r '.[] |
"\(.number)" + "\t\t" + "\(.assignee.login)"
+ "\t\t\t" + "\(.state)" + "\t\t"
+ "\(.created_at) | date("'
done
感谢您对此的帮助。谢谢。
根据要求提供示例 JSON 输出。
[
{
"url": "https://api.github.com/repos/stedolan/jq/issues/1558",
"repository_url": "https://api.github.com/repos/stedolan/jq",
"labels_url": "https://api.github.com/repos/stedolan/jq/issues/1558/labels{/name}",
"comments_url": "https://api.github.com/repos/stedolan/jq/issues/1558/comments",
"events_url": "https://api.github.com/repos/stedolan/jq/issues/1558/events",
"html_url": "https://github.com/stedolan/jq/pull/1558",
"id": 282346710,
"number": 1558,
"title": "Fix a try-catch example",
"user": {
"login": "zogwarg",
"id": 6682272,
"avatar_url": "https://avatars3.githubusercontent.com/u/6682272?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/zogwarg",
"html_url": "https://github.com/zogwarg",
"followers_url": "https://api.github.com/users/zogwarg/followers",
"following_url": "https://api.github.com/users/zogwarg/following{/other_user}",
"gists_url": "https://api.github.com/users/zogwarg/gists{/gist_id}",
"starred_url": "https://api.github.com/users/zogwarg/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/zogwarg/subscriptions",
"organizations_url": "https://api.github.com/users/zogwarg/orgs",
"repos_url": "https://api.github.com/users/zogwarg/repos",
"events_url": "https://api.github.com/users/zogwarg/events{/privacy}",
"received_events_url": "https://api.github.com/users/zogwarg/received_events",
"type": "User",
"site_admin": false
},
"labels": [
],
"state": "open",
"locked": false,
"assignee": null,
"assignees": [
],
"milestone": null,
"comments": 0,
"created_at": "2017-12-15T07:56:31Z",
"updated_at": "2017-12-15T07:56:31Z",
"closed_at": null,
"author_association": "NONE",
"pull_request": {
"url": "https://api.github.com/repos/stedolan/jq/pulls/1558",
"html_url": "https://github.com/stedolan/jq/pull/1558",
"diff_url": "https://github.com/stedolan/jq/pull/1558.diff",
"patch_url": "https://github.com/stedolan/jq/pull/1558.patch"
},
"body": "Fixing a bad syntax in a try-catch example\r\n\r\nIt was probably based on the inputs builtin definition,\r\nThe if statement was messed up and the semi-colon actually belongs to the function definition."
},
{
"url": "https://api.github.com/repos/stedolan/jq/issues/1557",
"repository_url": "https://api.github.com/repos/stedolan/jq",
"labels_url": "https://api.github.com/repos/stedolan/jq/issues/1557/labels{/name}",
"comments_url": "https://api.github.com/repos/stedolan/jq/issues/1557/comments",
"events_url": "https://api.github.com/repos/stedolan/jq/issues/1557/events",
"html_url": "https://github.com/stedolan/jq/issues/1557",
"id": 282289185,
"number": 1557,
"title": "Compiling for tvOS",
"user": {
"login": "larryaasen",
"id": 325973,
"avatar_url": "https://avatars1.githubusercontent.com/u/325973?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/larryaasen",
"html_url": "https://github.com/larryaasen",
"followers_url": "https://api.github.com/users/larryaasen/followers",
"following_url": "https://api.github.com/users/larryaasen/following{/other_user}",
"gists_url": "https://api.github.com/users/larryaasen/gists{/gist_id}",
"starred_url": "https://api.github.com/users/larryaasen/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/larryaasen/subscriptions",
"organizations_url": "https://api.github.com/users/larryaasen/orgs",
"repos_url": "https://api.github.com/users/larryaasen/repos",
"events_url": "https://api.github.com/users/larryaasen/events{/privacy}",
"received_events_url": "https://api.github.com/users/larryaasen/received_events",
"type": "User",
"site_admin": false
},
"labels": [
],
"state": "open",
"locked": false,
"assignee": null,
"assignees": [
],
"milestone": null,
"comments": 0,
"created_at": "2017-12-15T01:05:47Z",
"updated_at": "2017-12-15T01:05:47Z",
"closed_at": null,
"author_association": "CONTRIBUTOR",
"body": "I attempted to update the compile-ios.sh file for tvOS to build the library for use in an Apple TV app. I am not able to get it to link. Has anyone been able to compile the library for tvOS?\r\n\r\nHere is the error message:\r\n/opt/local/bin/ranlib: object: .libs/libonig.a(regerror.o) malformed object (unknown load command 1)\r\n\r\nAttached the script file:\r\n[compile-tvos.sh.zip](https://github.com/stedolan/jq/files/1561265/compile-tvos.sh.zip)\r\n"
}
]
【问题讨论】:
-
请提供最小的 JSON 样本。
-
嗨@peak,与几个实体共享示例 JSON..
-
@pprmdas,好的,发布预期结果
-
预期输出应该是 github 问题列表以及上周创建的
assignees。
标签: linux date time github-api jq