-
Notifications
You must be signed in to change notification settings - Fork 1
/
gh-org-teams
executable file
·92 lines (85 loc) · 1.8 KB
/
gh-org-teams
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
#!/bin/bash
function help() {
echo "Usage:"
echo " gh org-teams [-o|--ORG <ORG>] [-n|--NAME] [-u|--URL]"
echo
echo "By default the ORG is obtained using the command gh pwd."
echo " For a better experience set these alias:"
echo " set alias pwd to: !gh config get current-org"
echo " set alias cd to: !gh config set current-org "$1" 2>/dev/null"
exit 1
}
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
-o | --ORG)
ORG=$2
shift # past argument
shift # past value
;;
-n | --NAME)
NAME=true
shift # past value
;;
-u | --URL)
URL=true
shift # past value
;;
-nu | --NAME-URL)
NAME=true
URL=true
shift # past value
;;
-* | --*)
help
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
if [ -z "$ORG" ]; then
ORG=$(gh pwd) || help
fi
QUERY='query getInfo($organization: String!) {
organization(login: $organization) {
teams(first: 100) {
totalCount
edges {
node {
name
members(first: 100) {
totalCount
edges {
memberAccessUrl
node {
name
url
email
login
avatarUrl
}
}
}
url
}
}
}
}
}'
TEAMS=$(gh api graphql -F organization="$ORG" -f query="$QUERY")
if [ -n "$NAME" ] && [ -n "$URL" ]
then
echo $TEAMS | jq '.data.organization.teams.edges | map({ name:.node.name, url:.node.url})'
exit 0
fi
if [ -n "$NAME" ]; then
echo $TEAMS | jq '.data.organization.teams.edges | map(.node.name)'
exit 0
fi
if [ -n "$URL" ]; then
echo $TEAMS | jq '.data.organization.teams.edges | map(.node.url)'
exit 0
fi
echo $TEAMS