-
Notifications
You must be signed in to change notification settings - Fork 0
/
createNewRepo.sh
executable file
·37 lines (37 loc) · 1.45 KB
/
createNewRepo.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
#!/bin/sh
#-----------------------------------------------------------------
# Shell Script to create a new GitHub Repository
# Author : Eduardo Rocha - ehrocha@gmail.com
#-----------------------------------------------------------------
# https://docs.github.com/en/rest/reference/repos#create-an-organization-repository
#-----------------------------------------------------------------
# Variable Initialization
# Package jq is required for parsing the JSON file
#-----------------------------------------------------------------
#set -x;
urepo=$1;
uname=$(jq -r '.uname' ~/.github/config.json);
utoken=$(jq -r '.utoken' ~/.github/config.json);
upriv=$(jq -r '.upriv' ~/.github/config.json);
#-----------------------------------------------------------------
# Requesting Repository Creation from the API
# and clone the repository locally
#-----------------------------------------------------------------
echo "Creating a new repository named ${urepo} for user ${uname}";
curl -H "Authorization: token ${utoken}" \
-d '{"name":"'${urepo}'","private":"'${upriv}'"}' \
"https://api.github.com/user/repos" \
| grep -e 'ssh_url*' \
| cut -d \" -f 4 \
| xargs -L1 git clone ;
cd ${urepo};
git checkout -b dev;
echo "##Welcome to ${urepo}" > README.md;
git add *;
git commit -a -m "Initial Version";
git checkout -b master;
git merge;
git branch --unset-upstream;
git push --set-upstream origin master;
git push;
echo "Your new repository ${urepo} is ready";