forked from mozilla/github-org-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_user
executable file
·49 lines (40 loc) · 1.04 KB
/
block_user
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
#!/usr/bin/env bash
USAGE="usage: ${0##/} login ...
Where:
login GitHub login of user to block
Options:
-h --help This help
--org Org to block from (default mozilla)
Environment:
GH_TOKEN PAT token that is admin of org
"
# defaults
login=
org=mozilla
if [ -n "$DEBUG" ]; then
PS4=':${LINENO}+'
set -x
fi
# boilerplate
warn() { for m; do echo "$m" ; done 1>&2 ; }
die() { warn "$@" ; exit 2 ; }
usage() { warn "$@" "${USAGE:-}"; test $# -eq 0 ; exit $? ; }
while [[ $# -gt 0 ]]; do
case "$1" in
--org) org="$2" ; shift ;;
-h|--help) usage ;;
-*) usage "Unknown option '$1'" ;;
*) break
esac
shift
done
MIN_ARGS=1
MAX_ARGS=$# # as many as there are
[[ $# -lt $MIN_ARGS || $# -lt $MAX_ARGS ]] && usage "Wrong number of args $#"
[[ -z $GH_TOKEN ]] && usage "Missing GitHub PAT token"
for login in "$@"; do
curl -X PUT \
-H "Authorization: token $GH_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/orgs/${org}/blocks/${login}"
done