-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathorganizations.sh
executable file
·84 lines (70 loc) · 1.88 KB
/
organizations.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
#!/usr/bin/env bash
set -euo pipefail
list_all() {
local ORGS
ORGS=($(jq -r ".organizations[].github_id" < otterdog.json | sort))
printf '%s\n' "${ORGS[@]}"
}
list_all_projects() {
local PROJECTS
PROJECTS=($(jq -r ".organizations[].name" < otterdog.json | sort))
printf '%s\n' "${PROJECTS[@]}"
}
list_with_customization() {
local ORGS
ORGS=($(find -name "*.jsonnet" -exec grep -H "local" {} \; | grep -v "local orgs" | cut -f 1 -d ":" | cut -f 3 -d "/" | uniq | sort))
printf '%s\n' "${ORGS[@]}"
}
list_without_customization() {
local ALL_ORGS CUSTOM_ORGS ORGS
ALL_ORGS=$(jq -r ".organizations[].github_id" < otterdog.json | sort)
CUSTOM_ORGS=$(find -name "*.jsonnet" -exec grep -H "local" {} \; | grep -v "local orgs" | cut -f 1 -d ":" | cut -f 3 -d "/" | uniq | sort)
ORGS=($({ printf '%s\n' "${ALL_ORGS[@]}" "${CUSTOM_ORGS[@]}"; } | sort | uniq -u))
printf '%s\n' "${ORGS[@]}"
}
usage() {
local USAGE
USAGE="
Usage: $(basename "${0}") [OPTIONS]
Options:
-a list all configured organizations
-p list all configured projects
-c list organizations with customizations
-n list organizations without customizations
-h show this help
"
echo "$USAGE"
}
ACTION=""
while getopts "apcn" opt; do
case "${opt}" in
a)
ACTION="list-all"
;;
p)
ACTION="list-all-projects"
;;
c)
ACTION="list-with-customization"
;;
n)
ACTION="list-without-customization"
;;
*)
usage
exit 0
;;
esac
done
if [ -z "$ACTION" ]; then
usage
exit 1
fi
shift $((OPTIND-1))
case $ACTION in
"list-all") list_all ;;
"list-all-projects") list_all_projects ;;
"list-with-customization") list_with_customization ;;
"list-without-customization") list_without_customization ;;
*) exit 1 ;;
esac