Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit 8ce524b

Browse files
authored
gitlab setup (#6)
* gitlab setup * no priorization * improv help * readme
1 parent ed659fd commit 8ce524b

File tree

3 files changed

+198
-8
lines changed

3 files changed

+198
-8
lines changed

README.md

+43-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
Coderockr Way Github Setup
22
--------------------------
3-
Using this script the GitHub project will setup it to add the basic labels needed to control your issues according with the *Coderockr Way* methodology
3+
Using this script your project will be bootstraped with the basic labels needed to control your issues according with the *Coderockr Way* methodology
44

55
You can take a look here: https://github.com/coderockr/coderockr-way-github-setup/labels
66

7+
We now support setting up projects on [GitHub](#github) and [GitLab](#gitlab), click in the links to see more.
8+
79
How to use
810
----------
11+
12+
### GitHub
13+
914
This repository has a script named [`coderockr-way-github-setup.bash`](coderockr-way-github-setup.bash) there are two ways to use it.
1015

11-
You could just call it direct from GitHub using cURL, and it will ask you the info to updated your repository:
16+
1) You could just call it direct from GitHub using cURL, and it will ask you the info to updated your repository:
1217

1318
```bash
1419
$ bash -c "$(curl -sL https://raw.githubusercontent.com/coderockr/coderockr-way-github-setup/master/coderockr-way-github-setup.bash)"
@@ -17,7 +22,7 @@ Type your Github username: lucassabreu
1722
Type your Github password (won't be shown):
1823
```
1924
20-
Or you [install into your machine](#install) and run it directaly setting parameters (or not and it will be asked as shown before):
25+
2) Or you [install into your machine](#install) and run it directly setting parameters (or not and it will be asked as shown before):
2126
2227
Usage: `coderockr-way-github-setup -u githubUser -p githubPassword owner/repo`
2328
@@ -27,16 +32,48 @@ Usage: `coderockr-way-github-setup -u githubUser -p githubPassword owner/repo`
2732
--verbose, -v Details process
2833
```
2934
30-
Using Github Token
31-
------------------
35+
#### Using Github Token
36+
3237
If you're using github token you must set the environment variable `GITHUB_TOKEN`, then the script will ignore and won't ask for your username and password
3338
39+
### GitLab
40+
41+
Much like the GitHub script, this repository has a script named [`coderockr-way-gitlab-setup.bash`](coderockr-way-gitlab-setup.bash) and there are two ways to use it.
42+
43+
1) Just run it directly from GitHub using cURL, a GitLab [personal token](https://docs.gitlab.com/ee/api/README.html#personal-access-tokens) and projects name (owner/project) will be asked:
44+
45+
```bash
46+
$ bash -c "$(curl -sL https://raw.githubusercontent.com/coderockr/coderockr-way-gitlab-setup/master/coderockr-way-gitlab-setup.bash)"
47+
Type your GitLab repository name (owner/repo_name): coderockr/awesome-project
48+
Type your GitLab Private-token: <private-token>
49+
```
50+
51+
2) Or, after [installing it](#gitlab-setup), you can run it directly with parameters (or not and they will be asked as if you were running from GitHub)
52+
53+
Usage: `./coderockr-way-gitlab-setup.bash --token gitlab-private-token [-u http://gitlab.example.com] owner/repo`
54+
55+
```
56+
--help, -h Show this help
57+
--token, -t GitLab Private-Token (defaults to $GITLAB_TOKEN)
58+
--url, -u GitLab base URL (defaults to $GITLAB_URL or https://gitlab.com)
59+
--verbose, -v Details process
60+
```
61+
3462
Install
3563
-------
3664
37-
To install into your machine just run the commands bellow, and then use the command `coderockr-way-github-setup`.
65+
To install into your machine just run the commands bellow, and then use the command `coderockr-way-github-setup` or `coderockr-way-gitlab-setup`.
66+
67+
#### GitHub Setup
3868
3969
```sh
4070
curl -sL "https://raw.githubusercontent.com/coderockr/coderockr-way-github-setup/master/coderockr-way-github-setup.bash" -o "/usr/local/bin/coderockr-way-github-setup"
4171
chmod a+x /usr/local/bin/coderockr-way-github-setup
4272
```
73+
74+
#### GitLab Setup
75+
76+
```sh
77+
curl -sL "https://raw.githubusercontent.com/coderockr/coderockr-way-github-setup/master/coderockr-way-gitlab-setup.bash" -o "/usr/local/bin/coderockr-way-gitlab-setup"
78+
chmod a+x /usr/local/bin/coderockr-way-gitlab-setup
79+
```

coderockr-way-github-setup.bash

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ function getHelp {
99
--verbose, -v Details process
1010
1111
Usage:
12-
$0 -u githubUser -p githubPassword owner/repo
13-
"
12+
$0 -u githubUser -p githubPassword owner/repo\n"
1413
}
1514

1615
function github_api {

coderockr-way-gitlab-setup.bash

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#!/bin/bash
2+
3+
function getHelp {
4+
echo "Setup repository labels
5+
6+
--help, -h Show this help
7+
--token, -t GitLab Private-Token (defaults to \$GITLAB_TOKEN)
8+
--url, -u GitLab base URL (defaults to \$GITLAB_URL or https://gitlab.com)
9+
--verbose, -v Details process
10+
11+
To generate a Private-Token see: https://docs.gitlab.com/ee/api/README.html#personal-access-tokens
12+
13+
Usage:
14+
$0 --token gitlab-private-token [-u http://gitlab.example.com] owner/repo\n"
15+
}
16+
17+
function gitlab_labels_api {
18+
QUERY=
19+
[[ ! -z "$3" ]] && QUERY="?$(urlencode $3)"
20+
[[ -z "$3" ]] && [[ "$1" = "DELETE" ]] && QUERY="?$(urlencode $2)"
21+
curl -w "\nStatus: %{http_code}\n" -H "Private-Token: $GITLAB_TOKEN" -sL "$GITLAB_URL/api/v4/projects/$GITLAB_REPO/labels$QUERY" -X "$1" -d "$2"
22+
}
23+
24+
urlencode() {
25+
# urlencode <string>
26+
old_lc_collate=$LC_COLLATE
27+
LC_COLLATE=C
28+
29+
local length="${#1}"
30+
for (( i = 0; i < length; i++ )); do
31+
local c="${1:i:1}"
32+
case $c in
33+
[a-zA-Z0-9.~_-]) printf "$c" ;;
34+
*) printf '%%%02X' "'$c" ;;
35+
esac
36+
done
37+
38+
LC_COLLATE=$old_lc_collate
39+
}
40+
41+
VERBOSE=0
42+
[[ -z "$GITLAB_URL" ]] && GITLAB_URL=https://gitlab.com/
43+
args=("$@")
44+
for i in "$@"
45+
do
46+
if [ ! -z "$counter" ] && [[ "$counter" != "$readed_counter" ]]; then
47+
counter=$[$counter + 1]
48+
continue
49+
fi
50+
51+
if [[ "$i" = "--help" ]] || [[ "$i" = "-h" ]]; then
52+
printf "$(getHelp)"
53+
exit 0
54+
elif [[ $i == '--token' ]] || [[ $i == '-t' ]]; then
55+
GITLAB_TOKEN=${args[$counter + 1]}
56+
readed_counter=$[$readed_counter + 1]
57+
elif [[ $i == '--url' ]] || [[ $i == '-u' ]]; then
58+
GITLAB_URL=${args[$counter + 1]}
59+
readed_counter=$[$readed_counter + 1]
60+
elif [[ $i == '--verbose' ]] || [[ $i == '-v' ]]; then
61+
VERBOSE=1
62+
else
63+
GITLAB_REPO=$i
64+
fi
65+
66+
readed_counter=$[$readed_counter + 1]
67+
counter=$[$counter + 1]
68+
done
69+
70+
if [ -z "$GITLAB_REPO" ]; then
71+
read -p "Type your GitLab repository name (owner/repo_name): " GITLAB_REPO
72+
fi
73+
74+
if [ -z "$GITLAB_TOKEN" ]; then
75+
read -p "Type your GitLab Private-token: " GITLAB_TOKEN
76+
fi
77+
78+
if [ -z "$GITLAB_TOKEN" ] || [ -z "$GITLAB_REPO" ]; then
79+
>&2 echo "There are missing parameters !"
80+
>&2 printf "$(getHelp)"
81+
exit 1
82+
fi
83+
84+
GITLAB_REPO=$(urlencode $GITLAB_REPO)
85+
86+
REMOVE_DEFAULT_LABELS='bug
87+
confirmed
88+
critical
89+
discussion
90+
documentation
91+
enhancement
92+
suggestion
93+
support'
94+
95+
LABELS='Category: Backend,c2e0c6,
96+
Category: Business/Meetings,0e8a16,
97+
Category: DevOps,fef2c0,
98+
Category: Frontend,bfdadc,
99+
Category: Infrastructure,f0e68c,
100+
Category: Report,40e0d0,
101+
Category: Unit test,ededed,
102+
Level: Easy,48d1cc,
103+
Level: Medium,20b2aa,
104+
Level: Hard,008b8b,
105+
Priority: Highest,b60205,1
106+
Priority: High,fef2c0,2
107+
Priority: Medium,d4c5f9,3
108+
Priority: Low,d4c5f9,4
109+
Priority: Lowest,ededed,5
110+
Stage: Analysis,e6e6e6,
111+
Stage: Backlog,ededed,
112+
Stage: Cancelled,000000,
113+
Stage: In progress,fbca04,
114+
Stage: Review,0052cc,
115+
Stage: Testing,e616e6,
116+
Status: Blocked,d93f0b,
117+
Status: Duplicated,c5def5,
118+
Status: Impediment,b60205,
119+
Status: Needs Fixing,ff8c00,
120+
Type: Bug,fc2929,
121+
Type: Improvement,84b6eb,
122+
Type: New feature,052cc,
123+
Type: Sub-task,ededed,'
124+
125+
if [[ "$VERBOSE" == 1 ]]; then
126+
echo "Removing default labels"
127+
fi
128+
129+
while read -r label; do
130+
response=$(gitlab_labels_api DELETE "name=$label")
131+
if [[ "$response" != *"Status: 204"* ]]; then
132+
[[ "$response" != *"Status: 404"* ]] && >&2 echo "Error removing \"$label\": $response"
133+
elif [[ "$VERBOSE" == 1 ]]; then
134+
echo "Label \"$label\" removed"
135+
fi
136+
done <<< "$REMOVE_DEFAULT_LABELS"
137+
138+
if [[ "$VERBOSE" == 1 ]]; then
139+
echo "Creating new labels"
140+
fi
141+
142+
while read -r label; do
143+
label_name=$(echo $label | cut -d , -f 1)
144+
label_color=$(echo $label | cut -d , -f 2)
145+
label_priority=$(echo $label | cut -d , -f 3)
146+
response=$(gitlab_labels_api POST "name=$label_name&color=#$label_color&priority=$label_priority")
147+
148+
if [[ "$response" != *"Status: 201"* ]]; then
149+
[[ "$response" != *"Status: 409"* ]] && >&2 echo "Error on creating: $label_name, response: $response"
150+
elif [[ "$VERBOSE" == 1 ]]; then
151+
echo "Label \"$label_name\" created"
152+
fi
153+
done <<< "$LABELS"
154+

0 commit comments

Comments
 (0)