-
Notifications
You must be signed in to change notification settings - Fork 13
/
mkrepo.sh
executable file
·42 lines (32 loc) · 949 Bytes
/
mkrepo.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
#!/usr/bin/env bash
#/
#/ Create a new repo on GitHub
#/
#/ Usage: git $KIT_ID mkrepo my_new_repo
#/
set -e
REPO=$1
[ -z "$REPO" ] && echo "Missing repo name" && exit 1
KIT_PATH=$(dirname "$0")
. "$KIT_PATH/enterprise.constants"
. "$KIT_PATH/lib/setup_helpers.sh"
ADS_USER=$(git config --global adsk.github.account)
[ -z "$ADS_USER" ] && error_exit 'Username must not be empty!'
SERVER=$(git config --global adsk.github.server)
[ -z "$SERVER" ] && error_exit 'Server must not be empty!'
TOKEN="$(get_credentials $SERVER $ADS_USER)"
[ -z "$TOKEN" ] && echo "Missing GitHub token" && exit 1
URL="https://$SERVER/api/v3/user/repos"
HEADERS="Authorization: token $TOKEN"
DATA="{\"name\":\"$REPO\"}"
set +e
RESPONSE=$(curl --silent --fail -H "$HEADERS" -d "$DATA" $URL)
STATUS=$?
set -e
if [ "$STATUS" -ne 0 ]
then
echo "Could not create repo '$REPO'"
echo $RESPONSE
exit $STATUS
fi
echo "repo 'https://$SERVER/$ADS_USER/$REPO' created!"