gpt4 book ai didi

linux - github 问题 api 和 jq 过滤器和 grep

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:36:13 26 4
gpt4 key购买 nike

我正在使用 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"
}
]

最佳答案

无耻的 self 宣传。你可以用 jf 巧妙地做到这一点

pip install jf
curl "https://api.github.com/repos/alhoo/jf/issues" | jf 'filter(age(x.created_at) < age("1 week"))'

关于linux - github 问题 api 和 jq 过滤器和 grep,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48659631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com