-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload-to-github-group
executable file
·59 lines (48 loc) · 1.58 KB
/
upload-to-github-group
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
#!/bin/bash
SCRIPTPATH="$(readlink -f 2>/dev/null || perl -MCwd -e 'print Cwd::abs_path shift' $0)"
SCRIPTDIR="$(dirname "${SCRIPTPATH}")"
if test ! -f "package.json"
then
echo "Error: schema.json file not found."
exit 1
fi
if git remote get-url origin 2>/dev/null | grep -q github.com >/dev/null
then
echo "Error: Repo already linked to Github"
exit 1
fi
APP="osiota-app-$(basename "${PWD}" | sed -e "s/^osiota-app-//g" -e "s/^er-app-//g")"
REPODESC="$("${SCRIPTDIR}/get-json" --file package.json --key description | head -n 1 | sed -e "s/\..*//")"
TOKEN="$(cat ~/.github-token | head -n 1)"
if test "x${TOKEN}" = "x"
then
echo "Error: Token not defined." >&2
echo "Please write Github token to file: ~/.github-token" >&2
exit 1
fi
curl --fail "https://api.github.com/repos/osiota/${APP}" >/dev/null 2>&1
if test "x$?" = "x0"
then
echo "Error: Repo already exists: ${APP}" >&2
exit 1
fi
echo "Create Repo: ${APP}"
echo "Description: ${REPODESC}"
RESULT="$(curl -v --fail -H "Authorization: token ${TOKEN}" https://api.github.com/orgs/osiota/repos -d "{\"name\":\"${APP}\", \"private\": false, \"description\": \"${REPODESC}\", \"has_wiki\": false, \"has_projects\": false}" 2>&1)"
EXITCODE="$?"
if test "x${EXITCODE}" != "x0"
then
echo "Repo not created: ${APP}" >&2
echo "RESULT: ${RESULT}"
echo "Exit code: ${EXITCODE}"
exit 1
fi
git remote | grep -q "origin"
if test "x$?" = "x1"
then
git remote add origin [email protected]:osiota/${APP}.git
git push --set-upstream origin master
else
git remote set-url origin [email protected]:osiota/${APP}.git
git push --set-upstream origin master
fi