forked from rgl/gitlab-vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_include_gitlab_api.sh
66 lines (53 loc) · 1.65 KB
/
_include_gitlab_api.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
58
59
60
61
62
63
64
65
66
domain=$(hostname --fqdn)
function gitlab-psql {
sudo -sHu gitlab-psql \
/opt/gitlab/embedded/bin/psql \
-h /var/opt/gitlab/postgresql \
-d gitlabhq_production \
"$@"
}
gitlab_private_token=$(gitlab-psql -t -c "select token from personal_access_tokens where user_id=1 and name='vagrant'")
function git {
/opt/gitlab/embedded/bin/git "$@"
}
function gitlab-api {
local method=$1; shift
local path=$1; shift
http \
--check-status \
--ignore-stdin \
$method \
"https://$domain/api/v4$path" \
"Private-Token:$gitlab_private_token" \
"$@"
}
function gitlab-create-project {
local name=$1
gitlab-api POST /projects name=$name visibility=public
}
# creates a new GitLab project from an existing git repository.
# NB GitLab CE does not support mirroring a git repository.
function gitlab-create-project-and-import {
local sourceGitUrl=$1
local destinationProjectName=$2
gitlab-create-project $destinationProjectName
git \
clone --mirror \
$sourceGitUrl \
$destinationProjectName
pushd $destinationProjectName
git \
push --mirror \
git@$domain:root/$destinationProjectName.git
popd
rm -rf $destinationProjectName
}
# generate a new ssh key for the current user account and add it to gitlab.
if [ ! -f ~/.ssh/id_rsa ]; then
ssh-keygen -f ~/.ssh/id_rsa -t rsa -b 2048 -C "$USER@$domain" -N ''
gitlab-api POST /user/keys "title=$USER@$domain" key=@~/.ssh/id_rsa.pub
fi
# trust our own SSH server.
if [ -z "$(ssh-keygen -F $domain 2>/dev/null)" ]; then
ssh-keyscan -H $domain >> ~/.ssh/known_hosts
fi