-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathquery_issues.sh
More file actions
executable file
·224 lines (186 loc) · 6.11 KB
/
Copy pathquery_issues.sh
File metadata and controls
executable file
·224 lines (186 loc) · 6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/bash
# Script to query and search through locally cached GitHub issues
# Provides various search and filtering options
set -e
DATA_DIR="issues_data"
LATEST_FILE="${DATA_DIR}/latest_issues.json"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
show_help() {
echo "Usage: $0 [COMMAND] [OPTIONS]"
echo ""
echo "Commands:"
echo " stats Show issue statistics"
echo " search <term> Search issues by title and body"
echo " number <num> Find specific issue by number"
echo " state <state> Filter by state (open/closed)"
echo " author <user> Filter by author"
echo " recent [N] Show N most recent issues (default: 10)"
echo " labels List all unique labels"
echo " label <label> Filter by specific label"
echo " help Show this help"
echo ""
echo "Examples:"
echo " $0 stats"
echo " $0 search 'web component'"
echo " $0 number 123"
echo " $0 state open"
echo " $0 recent 20"
echo " $0 author btopro"
echo " $0 label bug"
}
check_data() {
if [[ ! -f "${LATEST_FILE}" ]]; then
echo -e "${RED}❌ No issue data found!${NC}"
echo -e "${YELLOW}💡 Run ./fetch_issues.sh first to download issues${NC}"
exit 1
fi
}
show_stats() {
check_data
echo -e "${CYAN}📊 GitHub Issues Statistics${NC}"
echo ""
local total=$(jq 'length' "${LATEST_FILE}")
local open=$(jq '[.[] | select(.state == "OPEN")] | length' "${LATEST_FILE}")
local closed=$(jq '[.[] | select(.state == "CLOSED")] | length' "${LATEST_FILE}")
echo -e "${GREEN}Total Issues: ${total}${NC}"
echo -e "${BLUE}Open Issues: ${open}${NC}"
echo -e "${PURPLE}Closed Issues: ${closed}${NC}"
echo ""
echo -e "${YELLOW}📈 Top 10 Authors:${NC}"
jq -r '[.[] | .author.login] | group_by(.) | map({author: .[0], count: length}) | sort_by(.count) | reverse | .[0:10] | .[] | " \(.author): \(.count)"' "${LATEST_FILE}"
echo ""
echo -e "${YELLOW}🏷️ Top 10 Labels:${NC}"
jq -r '[.[] | .labels[]?.name // empty] | group_by(.) | map({label: .[0], count: length}) | sort_by(.count) | reverse | .[0:10] | .[] | " \(.label): \(.count)"' "${LATEST_FILE}"
}
search_issues() {
check_data
local term="$1"
if [[ -z "$term" ]]; then
echo -e "${RED}❌ Search term required${NC}"
exit 1
fi
echo -e "${CYAN}🔍 Searching for: '${term}'${NC}"
echo ""
jq -r --arg term "$term" '
[.[] | select((.title | ascii_downcase | contains($term | ascii_downcase)) or (.body // "" | ascii_downcase | contains($term | ascii_downcase)))] |
sort_by(.number) | reverse |
.[] |
"Issue #\(.number) (\(.state)): \(.title)\n Author: \(.author.login) | Created: \(.createdAt | split("T")[0])\n URL: \(.url)\n"
' "${LATEST_FILE}"
}
find_issue_by_number() {
check_data
local number="$1"
if [[ -z "$number" ]]; then
echo -e "${RED}❌ Issue number required${NC}"
exit 1
fi
jq -r --arg num "$number" '
.[] | select(.number == ($num | tonumber)) |
"# Issue #\(.number): \(.title)\n\n**State:** \(.state)\n**Author:** \(.author.login)\n**Created:** \(.createdAt)\n**Updated:** \(.updatedAt)\n**URL:** \(.url)\n\n## Labels\n\(if .labels | length > 0 then [.labels[].name] | join(", ") else "None" end)\n\n## Description\n\(.body // "No description")\n"
' "${LATEST_FILE}"
}
filter_by_state() {
check_data
local state="$1"
if [[ -z "$state" ]]; then
echo -e "${RED}❌ State required (open/closed)${NC}"
exit 1
fi
echo -e "${CYAN}📋 Issues with state: ${state}${NC}"
echo ""
jq -r --arg state "$(echo $state | tr '[:lower:]' '[:upper:]')" '
[.[] | select(.state == $state)] |
sort_by(.number) | reverse |
.[0:20] |
.[] |
"Issue #\(.number): \(.title)\n Author: \(.author.login) | Created: \(.createdAt | split("T")[0])\n"
' "${LATEST_FILE}"
}
filter_by_author() {
check_data
local author="$1"
if [[ -z "$author" ]]; then
echo -e "${RED}❌ Author required${NC}"
exit 1
fi
echo -e "${CYAN}👤 Issues by author: ${author}${NC}"
echo ""
jq -r --arg author "$author" '
[.[] | select(.author.login == $author)] |
sort_by(.number) | reverse |
.[] |
"Issue #\(.number) (\(.state)): \(.title)\n Created: \(.createdAt | split("T")[0])\n"
' "${LATEST_FILE}"
}
show_recent() {
check_data
local count="${1:-10}"
echo -e "${CYAN}📅 ${count} Most Recent Issues${NC}"
echo ""
jq -r --arg count "$count" '
sort_by(.createdAt) | reverse |
.[0:($count | tonumber)] |
.[] |
"Issue #\(.number) (\(.state)): \(.title)\n Author: \(.author.login) | Created: \(.createdAt | split("T")[0])\n URL: \(.url)\n"
' "${LATEST_FILE}"
}
list_labels() {
check_data
echo -e "${CYAN}🏷️ All Unique Labels${NC}"
echo ""
jq -r '[.[] | .labels[]?.name // empty] | unique | .[]' "${LATEST_FILE}" | sort
}
filter_by_label() {
check_data
local label="$1"
if [[ -z "$label" ]]; then
echo -e "${RED}❌ Label required${NC}"
exit 1
fi
echo -e "${CYAN}🏷️ Issues with label: ${label}${NC}"
echo ""
jq -r --arg label "$label" '
[.[] | select(.labels[]?.name == $label)] |
sort_by(.number) | reverse |
.[] |
"Issue #\(.number) (\(.state)): \(.title)\n Author: \(.author.login) | Created: \(.createdAt | split("T")[0])\n"
' "${LATEST_FILE}"
}
# Main command parsing
case "${1:-help}" in
"stats")
show_stats
;;
"search")
search_issues "$2"
;;
"number")
find_issue_by_number "$2"
;;
"state")
filter_by_state "$2"
;;
"author")
filter_by_author "$2"
;;
"recent")
show_recent "$2"
;;
"labels")
list_labels
;;
"label")
filter_by_label "$2"
;;
"help"|*)
show_help
;;
esac