Setting the file. One moment.
Query Issues · GitHub Issue Query · github/gh-aw · Skills Docs
ContentsBack to the top of the page
Raw file
query-issues.sh
Shell · 115 lines · 4 KB
# This prevents overwhelming responses. Use --jq '.' to get all data.
16
17 set -e
18
19 # Default values
20 REPO = ""
21 STATE = "open"
22 LIMIT = 30
23 JQ_FILTER = ""
24
25 # Parse arguments
26 while [[ $# -gt 0 ]]; do
27 case $1 in
28 --repo )
29 REPO = " $2 "
30 shift 2
31 ;;
32 --state )
33 STATE = " $2 "
34 shift 2
35 ;;
36 --limit )
37 LIMIT = " $2 "
38 shift 2
39 ;;
40 --jq )
41 JQ_FILTER = " $2 "
42 shift 2
43 ;;
44 *)
45 echo "Unknown option: $1 " >&2
46 exit 1
47 ;;
48 esac
49 done
50
51 # JSON fields to fetch
52 JSON_FIELDS = "number,title,state,author,createdAt,updatedAt,closedAt,body,labels,assignees,comments,milestone,url,projectItems"
53
54 # Build and execute gh command with proper quoting
55 if [[ -n " $REPO " ]]; then
56 OUTPUT = $( gh issue list --state " $STATE " --limit " $LIMIT " --json " $JSON_FIELDS " --repo " $REPO " )
57 else
58 OUTPUT = $( gh issue list --state " $STATE " --limit " $LIMIT " --json " $JSON_FIELDS " )
59 fi
60
61 # Apply jq filter if specified
62 if [[ -n " $JQ_FILTER " ]]; then
63 echo " $OUTPUT " | jq " $JQ_FILTER "
64 else
65 # Return schema and size instead of full data
66 ITEM_COUNT = $( jq 'length' <<< " $OUTPUT " )
67 DATA_SIZE = ${ # OUTPUT}
68
69 # Validate values are numeric
70 if ! [[ " $ITEM_COUNT " =~ ^[0-9]+$ ]]; then
71 ITEM_COUNT = 0
72 fi
73 if ! [[ " $DATA_SIZE " =~ ^[0-9]+$ ]]; then
74 DATA_SIZE = 0
75 fi
76
77 cat << EOF
78 {
79 "message": "No --jq filter provided. Use --jq to filter and retrieve data.",
80 "item_count": $ITEM_COUNT ,
81 "data_size_bytes": $DATA_SIZE ,
82 "schema": {
83 "type": "array",
84 "description": "Array of issue objects",
85 "item_fields": {
86 "number": "integer - Issue number",
87 "title": "string - Issue title",
88 "state": "string - Issue state (OPEN, CLOSED)",
89 "author": "object - Author info with login field",
90 "createdAt": "string - ISO timestamp of creation",
91 "updatedAt": "string - ISO timestamp of last update",
92 "closedAt": "string|null - ISO timestamp of close",
93 "body": "string - Issue body content",
94 "labels": "array - Array of label objects with name field",
95 "assignees": "array - Array of assignee objects with login field",
96 "comments": "object - Comments info with totalCount field",
97 "milestone": "object|null - Milestone info with title field",
98 "url": "string - Issue URL",
99 "projectItems": "object - Project assignments with totalCount and nodes array containing project info"
100 }
101 },
102 "suggested_queries": [
103 {"description": "Get all data", "query": "."},
104 {"description": "Get issue numbers and titles", "query": ".[] | {number, title}"},
105 {"description": "Get open issues only", "query": ".[] | select(.state == \" OPEN \" )"},
106 {"description": "Get issues by author", "query": ".[] | select(.author.login == \" USERNAME \" )"},
107 {"description": "Get issues with label", "query": ".[] | select(.labels | map(.name) | index( \" bug \" ))"},
108 {"description": "Get issues with many comments", "query": ".[] | select(.comments.totalCount > 5) | {number, title, comments: .comments.totalCount}"},
109 {"description": "Get issues with labels", "query": ".[] | {number, title, labels: [.labels[].name]}"},
110 {"description": "Get issues with project assignments", "query": ".[] | {number, title, projects: [.projectItems.nodes[]? | .project?.url]}"},
111 {"description": "Count by state", "query": "group_by(.state) | map({state: .[0].state, count: length})"}
112 ]
113 }
114 EOF
115 fi