-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgitlab-remote-v1.1
More file actions
executable file
·65 lines (49 loc) · 1.6 KB
/
Copy pathgitlab-remote-v1.1
File metadata and controls
executable file
·65 lines (49 loc) · 1.6 KB
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
60
61
62
63
64
65
#!/bin/bash
username=$1
repo_name=$2
if [ "$username" = "-h" ]; then
echo "USAGE:"
echo "1 argument - your username in gitlab"
echo "2 argument - name of the repo you want to create"
exit 1
fi
if [ $# -ne 2 ]; then
echo "Not the expected number of arguments. Expected 2."
fi
if [ "$username" = "" ]; then
echo "Could not find username, please provide it."
exit 1
fi
dir_name=`basename $(pwd)`
if [ "$repo_name" = "" ]; then
echo "Repo name (hit enter to use '$dir_name')?"
read repo_name
fi
if [ "$repo_name" = "" ]; then
repo_name=$dir_name
fi
# ask user for password
read -s -p "Enter Password: " password
request=`curl --request POST "https://gitlab.com/api/v3/session?login=$username&password=$password"`
if [ "$request" = '{"message":"401 Unauthorized"}' ]; then
echo "Username or password incorrect."
exit 1
fi
token=`echo $request | cut -d , -f 28 | cut -d : -f 2 | cut -d '"' -f 2`
echo -n "Creating GitLab repository '$repo_name' ..."
curl -H "Content-Type:application/json" https://gitlab.com/api/v3/projects?private_token=$token -d '{"name":"'$repo_name'"}' > /dev/null 2>&1
echo " done."
# 2>$1 means that we want redirect stderr to stdout
echo -n "Pushing local code to remote ..."
git init
echo "gitlab-init-remote.sh" > .gitignore
echo ".gitignore" >> .gitignore
git config --global core.excudefiles ~/.gitignore_global
git add .
git commit -m "first commit"
git remote add origin git@gitlab.com:$username/$repo_name.git > /dev/null 2>&1
git push -u origin master > /dev/null 2>&1
echo " done."
echo ""
echo "The created repo is available at following link:"
echo "https://gitlab.com/$username/$repo_name"