-
Notifications
You must be signed in to change notification settings - Fork 0
/
GitHubIssueStatus.sh
executable file
·86 lines (78 loc) · 2.41 KB
/
GitHubIssueStatus.sh
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
#!/usr/bin/env bash
#
# Create a list of prs matching a search string based on a list of repositories
# PreReqs:
# github cli, jq, sort installed
# GH_TOKEN set in env
#
# TODO(kernelsam): Read token from lastpass
#
############################################################
# help
############################################################
help()
{
# Display Help
echo
echo "Syntax: GitHubIssueSearch.sh [-h|t]"
echo "options:"
echo "h Print this Help."
echo "f Fields to search. Comma separated list. Ex. \"number,headRepository"\"
echo "l Maximum number of repositories to list"
echo "o github org"
echo "s Filter by state: {open|closed|merged|all}"
echo
}
############################################################
# read args
############################################################
while [ -n "$1" ]; do
case "$1" in
--help|-h)
shift
echo "You entered number as: $1"
;;
--fields|-f)
shift
fields=$1
;;
--limit|-l)
shift
limit=$1
;;
--org|-o)
shift
org=$1
;;
--state|-s)
shift
state=$1
;;
*)
help
exit 1
;;
esac
shift
done
############################################################
# main
# list gh repos to file and sort
############################################################
./GitHubRepoList.sh -o "${org}" -l "${limit}" -f "name"
# update fields to be passed to jq in the format
# .<value1>,.<value2>,...,.<valuen>
if grep -q "," <<< "${fields}"; then
jqfields=$(echo "${fields}" | awk -F "," '{ for(i=1; i<NF; i++) printf ".%s,", $i }')
jqfields=$jqfields$(echo ".${fields}" | awk -F, '{ print "."$NF }')
else
# single field should have no trailing comma
jqfields=".${fields}"
fi
while IFS= read -r line; do
repo=$(echo "${line}" | tr -d '"')
echo "[INFO] gh issue list -R https://github.com/${org}/${repo} --state \"${state}\" --json \"${fields}\" --jq \" .[]| [${jqfields}]\" >> issues.csv"
echo "[INFO] ${org}/${repo}"
echo "${org}/${repo}" >> issues.csv
gh issue list -R https://github.com/"${org}"/"${repo}" --state "${state}" --json "${fields}" --jq " .[]| [${jqfields}]" >> issues.csv
done < repolist.csv