-
Notifications
You must be signed in to change notification settings - Fork 6
/
onboarding.sh
executable file
·57 lines (45 loc) · 1.66 KB
/
onboarding.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
#!/bin/sh -e
# ------------------------------------------------------------------------------------------------------
# onboarding - Maptime onboarding tool
#
# Bash script to assist in the Maptime onboarding process on Github.
# Before running, user must have a Github personal access token
# saved in an environment variable named GH_TOKEN
# Requires jq for json parsing. See: http://stedolan.github.io/jq/download/
abort()
{
echo >&2 '
***************
*** ABORTED ***
***************
'
echo "An error occurred. Exiting..." >&2
exit 1
}
trap 'abort' 0
set -e
echo "Repo name. Enter the Maptime chapter repo name (e.g. portland). Make sure it doesn't conflict with existing repos and is all lowercase:"
read chapter
echo "Admin team. Enter the abbreviations for country and/or state/province (e.g. us-ny for USA, New York): "
read team
echo "Enter the admin GitHub username: "
read admin
curl -H "Content-Type: application/json" \
-u ${GH_TOKEN}:x-oauth-basic https://api.github.com/orgs/maptime/repos \
-X POST -d "{\"name\":\"$chapter\",\"description\":\"Repo for Maptime $chapter\"}"
tempdir=$(mktemp -dt "starter.XXXXXXXXXX")
git clone [email protected]:maptime/starter.git $tempdir
cd $tempdir
git remote add local [email protected]:maptime/${chapter}.git
git push local gh-pages
id=$(curl -H "Content-Type: application/json" \
-u ${GH_TOKEN}:x-oauth-basic https://api.github.com/orgs/maptime/teams \
-d "{\"name\":\"${team}\",\"permission\":\"push\",\"repo_names\":[\"maptime/${chapter}\"]}" \
| jq -r '.id')
curl -u ${GH_TOKEN}:x-oauth-basic -X PUT https://api.github.com/teams/${id}/memberships/${admin}
trap : 0
echo >&2 '
************
*** DONE ***
************
'