From d29ab2420a6669028145e7233be1911c0822a9e7 Mon Sep 17 00:00:00 2001 From: Rodrigo Ferreira Date: Fri, 12 May 2017 11:38:17 -0300 Subject: [PATCH 1/9] Update coderockr-way-github-setup.bash --- coderockr-way-github-setup.bash | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/coderockr-way-github-setup.bash b/coderockr-way-github-setup.bash index 467e8c8..953334e 100755 --- a/coderockr-way-github-setup.bash +++ b/coderockr-way-github-setup.bash @@ -76,7 +76,12 @@ LABELS='Category: Backend,c2e0c6 Category: Business/Meetings,0e8a16 Category: DevOps,fef2c0 Category: Frontend,bfdadc +Category: Infrastructure,f0e68c +Category: Report,40e0d0 Category: Unit test,ededed +Level: Easy,48d1cc +Level: Medium,20b2aa +Level: Hard,008b8b Priority: High,fef2c0 Priority: Highest,b60205 Priority: Low,d4c5f9 @@ -84,12 +89,14 @@ Priority: Lowest,ededed Priority: Medium,d4c5f9 Stage: Analysis,e6e6e6 Stage: Backlog,ededed +Stage: Cancelled,000000 Stage: In progress,fbca04 Stage: Review,0052cc Stage: Testing,e616e6 Status: Blocked,d93f0b Status: Duplicated,c5def5 Status: Impediment,b60205 +Status: Needs,ff8c00 Type: Bug,fc2929 Type: Improvement,84b6eb Type: New feature,0052cc From fbe75b35d3444f233d4f976be0c68703cb582db2 Mon Sep 17 00:00:00 2001 From: Rodrigo Ferreira Date: Fri, 12 May 2017 11:50:06 -0300 Subject: [PATCH 2/9] Update coderockr-way-github-setup.bash --- coderockr-way-github-setup.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coderockr-way-github-setup.bash b/coderockr-way-github-setup.bash index 953334e..162dc52 100755 --- a/coderockr-way-github-setup.bash +++ b/coderockr-way-github-setup.bash @@ -96,7 +96,7 @@ Stage: Testing,e616e6 Status: Blocked,d93f0b Status: Duplicated,c5def5 Status: Impediment,b60205 -Status: Needs,ff8c00 +Status: Needs Fixing,ff8c00 Type: Bug,fc2929 Type: Improvement,84b6eb Type: New feature,0052cc From b74f82abf4b94dfce29fefa4bca3013e6de85ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eucl=C3=A9cio=20Josias?= Date: Thu, 27 Jul 2017 11:08:20 -0300 Subject: [PATCH 3/9] Create labels using github token --- coderockr-way-github-setup.bash | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/coderockr-way-github-setup.bash b/coderockr-way-github-setup.bash index 162dc52..807d34b 100755 --- a/coderockr-way-github-setup.bash +++ b/coderockr-way-github-setup.bash @@ -14,7 +14,14 @@ Usage: } function github_api { - curl -u "$GITHUB_USERNAME:$GITHUB_PASSWORD" -sL "https://api.github.com/repos/$GITHUB_REPO/$1" -X "$2" -d "$3" + AUTHORIZATION="$GITHUB_USER:$GITHUB_PASSWORD" + COMMAND='-u' + [ ! -z ${GITHUB_TOKEN+x} ] && { + AUTHORIZATION="Authorization: token $GITHUB_TOKEN" + COMMAND='-H' + } + + curl $COMMAND "$AUTHORIZATION" -sL "https://api.github.com/repos/$GITHUB_REPO/$1" -X "$2" -d "$3" } VERBOSE=0 @@ -36,9 +43,9 @@ do GITHUB_PASSWORD=${args[$counter + 1]} readed_counter=$[$readed_counter + 1] elif [[ $i == '--verbose' ]] || [[ $i == '-v' ]]; then - VERBOSE=1 + VERBOSE=1 else - GITHUB_REPO=$i + GITHUB_REPO=$i fi readed_counter=$[$readed_counter + 1] @@ -49,16 +56,16 @@ if [ -z "$GITHUB_REPO" ]; then read -p "Type your Github repository name (owner/repo_name): " GITHUB_REPO fi -if [ -z "$GITHUB_USERNAME" ]; then +if [ -z "$GITHUB_USERNAME" ] && [ -z $GITHUB_TOKEN ]; then read -p "Type your Github username: " GITHUB_USERNAME fi -if [ -z "$GITHUB_PASSWORD" ]; then +if [ -z "$GITHUB_PASSWORD" ] && [ -z $GITHUB_TOKEN ]; then read -p "Type your Github password (won't be shown): " -s GITHUB_PASSWORD echo; fi -if [ -z "$GITHUB_USERNAME" ] || [ -z "$GITHUB_REPO" ]; then +if [ -z "$GITHUB_USERNAME" ] || [ -z "$GITHUB_REPO" ] && [ -z $GITHUB_TOKEN ]; then >&2 echo "There are missing parameters !" >&2 printf "$(getHelp)" exit 1 @@ -102,7 +109,7 @@ Type: Improvement,84b6eb Type: New feature,0052cc Type: Sub-task,ededed' -if [[ "$VERBOSE" == 1 ]]; then +if [[ "$VERBOSE" == 1 ]]; then echo "Removing default labels" fi @@ -112,12 +119,12 @@ while read -r label; do if [[ ! "$response" == *"Not Found"* ]]; then echo "Error removing \"$label\": $response" fi - elif [[ "$VERBOSE" == 1 ]]; then + elif [[ "$VERBOSE" == 1 ]]; then echo "Label \"$label\" removed" fi done <<< "$REMOVE_DEFAULT_LABELS" -if [[ "$VERBOSE" == 1 ]]; then +if [[ "$VERBOSE" == 1 ]]; then echo "Creating new labels" fi @@ -130,7 +137,7 @@ while read -r label; do if [[ ! "$response" == *"already_exists"* ]]; then >&2 echo "Error on creating: $label_name, response: $response" fi - elif [[ "$VERBOSE" == 1 ]]; then + elif [[ "$VERBOSE" == 1 ]]; then echo "Label \"$label_name\" created" fi done <<< "$LABELS" From e7b2f96f120f13f8386cc477dff9555344ecc679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eucl=C3=A9cio=20Josias?= Date: Thu, 27 Jul 2017 11:15:38 -0300 Subject: [PATCH 4/9] Fix identation --- coderockr-way-github-setup.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coderockr-way-github-setup.bash b/coderockr-way-github-setup.bash index 807d34b..6aabb30 100755 --- a/coderockr-way-github-setup.bash +++ b/coderockr-way-github-setup.bash @@ -43,9 +43,9 @@ do GITHUB_PASSWORD=${args[$counter + 1]} readed_counter=$[$readed_counter + 1] elif [[ $i == '--verbose' ]] || [[ $i == '-v' ]]; then - VERBOSE=1 + VERBOSE=1 else - GITHUB_REPO=$i + GITHUB_REPO=$i fi readed_counter=$[$readed_counter + 1] From 74e337495b32b4ec1cda76565a3f1a80b5c4dea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eucl=C3=A9cio=20Josias?= Date: Fri, 28 Jul 2017 16:10:33 -0300 Subject: [PATCH 5/9] Describe how to use token in readme --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dcd5932..0df0d56 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,9 @@ Type your Github username: lucassabreu Type your Github password (won't be shown): ``` +## Using Github Token +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 + Or you [install into your machine](#install) and run it directaly setting parameters (or not and it will be asked as shown before): Usage: `coderockr-way-github-setup -u githubUser -p githubPassword owner/repo` @@ -35,4 +38,4 @@ To install into your machine just run the commands bellow, and then use the comm ```sh 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" chmod a+x /usr/local/bin/coderockr-way-github-setup -``` \ No newline at end of file +``` From 514da33c0c3d4458d01d1b4fc1f6274816f5e198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eucl=C3=A9cio=20Josias?= Date: Fri, 28 Jul 2017 16:12:27 -0300 Subject: [PATCH 6/9] readme fix --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0df0d56..04d2a8a 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,6 @@ Type your Github username: lucassabreu Type your Github password (won't be shown): ``` -## Using Github Token -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 - Or you [install into your machine](#install) and run it directaly setting parameters (or not and it will be asked as shown before): Usage: `coderockr-way-github-setup -u githubUser -p githubPassword owner/repo` @@ -30,6 +27,10 @@ Usage: `coderockr-way-github-setup -u githubUser -p githubPassword owner/repo` --verbose, -v Details process ``` +Using Github Token +------------------ +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 + Install ------- From 2977d3cc0d2fa4888dd6927766998675be0effbb Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Tue, 16 Jan 2018 17:03:51 -0200 Subject: [PATCH 7/9] fix GITHUB_USERNAME --- coderockr-way-github-setup.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coderockr-way-github-setup.bash b/coderockr-way-github-setup.bash index 6aabb30..7ba4c5f 100755 --- a/coderockr-way-github-setup.bash +++ b/coderockr-way-github-setup.bash @@ -14,7 +14,7 @@ Usage: } function github_api { - AUTHORIZATION="$GITHUB_USER:$GITHUB_PASSWORD" + AUTHORIZATION="$GITHUB_USERNAME:$GITHUB_PASSWORD" COMMAND='-u' [ ! -z ${GITHUB_TOKEN+x} ] && { AUTHORIZATION="Authorization: token $GITHUB_TOKEN" From fa3b00c906f81dcfb396e89897dc5fc6fb2d64ba Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Tue, 16 Jan 2018 17:04:40 -0200 Subject: [PATCH 8/9] remove new default --- coderockr-way-github-setup.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/coderockr-way-github-setup.bash b/coderockr-way-github-setup.bash index 7ba4c5f..db9acfc 100755 --- a/coderockr-way-github-setup.bash +++ b/coderockr-way-github-setup.bash @@ -74,6 +74,7 @@ fi REMOVE_DEFAULT_LABELS='bug duplicate enhancement +good%20first%20issue help%20wanted invalid question From 8ce524b5d492224496323e3609e2d53ec79d6435 Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Fri, 9 Feb 2018 09:16:17 -0200 Subject: [PATCH 9/9] gitlab setup (#6) * gitlab setup * no priorization * improv help * readme --- README.md | 49 ++++++++-- coderockr-way-github-setup.bash | 3 +- coderockr-way-gitlab-setup.bash | 154 ++++++++++++++++++++++++++++++++ 3 files changed, 198 insertions(+), 8 deletions(-) create mode 100755 coderockr-way-gitlab-setup.bash diff --git a/README.md b/README.md index 04d2a8a..a479c87 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,19 @@ Coderockr Way Github Setup -------------------------- -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 +Using this script your project will be bootstraped with the basic labels needed to control your issues according with the *Coderockr Way* methodology You can take a look here: https://github.com/coderockr/coderockr-way-github-setup/labels +We now support setting up projects on [GitHub](#github) and [GitLab](#gitlab), click in the links to see more. + How to use ---------- + +### GitHub + This repository has a script named [`coderockr-way-github-setup.bash`](coderockr-way-github-setup.bash) there are two ways to use it. -You could just call it direct from GitHub using cURL, and it will ask you the info to updated your repository: + 1) You could just call it direct from GitHub using cURL, and it will ask you the info to updated your repository: ```bash $ 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 Type your Github password (won't be shown): ``` -Or you [install into your machine](#install) and run it directaly setting parameters (or not and it will be asked as shown before): + 2) Or you [install into your machine](#install) and run it directly setting parameters (or not and it will be asked as shown before): Usage: `coderockr-way-github-setup -u githubUser -p githubPassword owner/repo` @@ -27,16 +32,48 @@ Usage: `coderockr-way-github-setup -u githubUser -p githubPassword owner/repo` --verbose, -v Details process ``` -Using Github Token ------------------- +#### Using Github Token + 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 +### GitLab + +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. + + 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: + +```bash +$ bash -c "$(curl -sL https://raw.githubusercontent.com/coderockr/coderockr-way-gitlab-setup/master/coderockr-way-gitlab-setup.bash)" +Type your GitLab repository name (owner/repo_name): coderockr/awesome-project +Type your GitLab Private-token: +``` + + 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) + +Usage: `./coderockr-way-gitlab-setup.bash --token gitlab-private-token [-u http://gitlab.example.com] owner/repo` + +``` + --help, -h Show this help + --token, -t GitLab Private-Token (defaults to $GITLAB_TOKEN) + --url, -u GitLab base URL (defaults to $GITLAB_URL or https://gitlab.com) + --verbose, -v Details process +``` + Install ------- -To install into your machine just run the commands bellow, and then use the command `coderockr-way-github-setup`. +To install into your machine just run the commands bellow, and then use the command `coderockr-way-github-setup` or `coderockr-way-gitlab-setup`. + +#### GitHub Setup ```sh 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" chmod a+x /usr/local/bin/coderockr-way-github-setup ``` + +#### GitLab Setup + +```sh +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" +chmod a+x /usr/local/bin/coderockr-way-gitlab-setup +``` diff --git a/coderockr-way-github-setup.bash b/coderockr-way-github-setup.bash index db9acfc..946e076 100755 --- a/coderockr-way-github-setup.bash +++ b/coderockr-way-github-setup.bash @@ -9,8 +9,7 @@ function getHelp { --verbose, -v Details process Usage: - $0 -u githubUser -p githubPassword owner/repo - " + $0 -u githubUser -p githubPassword owner/repo\n" } function github_api { diff --git a/coderockr-way-gitlab-setup.bash b/coderockr-way-gitlab-setup.bash new file mode 100755 index 0000000..bcdaa81 --- /dev/null +++ b/coderockr-way-gitlab-setup.bash @@ -0,0 +1,154 @@ +#!/bin/bash + +function getHelp { + echo "Setup repository labels + + --help, -h Show this help + --token, -t GitLab Private-Token (defaults to \$GITLAB_TOKEN) + --url, -u GitLab base URL (defaults to \$GITLAB_URL or https://gitlab.com) + --verbose, -v Details process + +To generate a Private-Token see: https://docs.gitlab.com/ee/api/README.html#personal-access-tokens + +Usage: + $0 --token gitlab-private-token [-u http://gitlab.example.com] owner/repo\n" +} + +function gitlab_labels_api { + QUERY= + [[ ! -z "$3" ]] && QUERY="?$(urlencode $3)" + [[ -z "$3" ]] && [[ "$1" = "DELETE" ]] && QUERY="?$(urlencode $2)" + 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" +} + +urlencode() { + # urlencode + old_lc_collate=$LC_COLLATE + LC_COLLATE=C + + local length="${#1}" + for (( i = 0; i < length; i++ )); do + local c="${1:i:1}" + case $c in + [a-zA-Z0-9.~_-]) printf "$c" ;; + *) printf '%%%02X' "'$c" ;; + esac + done + + LC_COLLATE=$old_lc_collate +} + +VERBOSE=0 +[[ -z "$GITLAB_URL" ]] && GITLAB_URL=https://gitlab.com/ +args=("$@") +for i in "$@" +do + if [ ! -z "$counter" ] && [[ "$counter" != "$readed_counter" ]]; then + counter=$[$counter + 1] + continue + fi + + if [[ "$i" = "--help" ]] || [[ "$i" = "-h" ]]; then + printf "$(getHelp)" + exit 0 + elif [[ $i == '--token' ]] || [[ $i == '-t' ]]; then + GITLAB_TOKEN=${args[$counter + 1]} + readed_counter=$[$readed_counter + 1] + elif [[ $i == '--url' ]] || [[ $i == '-u' ]]; then + GITLAB_URL=${args[$counter + 1]} + readed_counter=$[$readed_counter + 1] + elif [[ $i == '--verbose' ]] || [[ $i == '-v' ]]; then + VERBOSE=1 + else + GITLAB_REPO=$i + fi + + readed_counter=$[$readed_counter + 1] + counter=$[$counter + 1] +done + +if [ -z "$GITLAB_REPO" ]; then + read -p "Type your GitLab repository name (owner/repo_name): " GITLAB_REPO +fi + +if [ -z "$GITLAB_TOKEN" ]; then + read -p "Type your GitLab Private-token: " GITLAB_TOKEN +fi + +if [ -z "$GITLAB_TOKEN" ] || [ -z "$GITLAB_REPO" ]; then + >&2 echo "There are missing parameters !" + >&2 printf "$(getHelp)" + exit 1 +fi + +GITLAB_REPO=$(urlencode $GITLAB_REPO) + +REMOVE_DEFAULT_LABELS='bug +confirmed +critical +discussion +documentation +enhancement +suggestion +support' + +LABELS='Category: Backend,c2e0c6, +Category: Business/Meetings,0e8a16, +Category: DevOps,fef2c0, +Category: Frontend,bfdadc, +Category: Infrastructure,f0e68c, +Category: Report,40e0d0, +Category: Unit test,ededed, +Level: Easy,48d1cc, +Level: Medium,20b2aa, +Level: Hard,008b8b, +Priority: Highest,b60205,1 +Priority: High,fef2c0,2 +Priority: Medium,d4c5f9,3 +Priority: Low,d4c5f9,4 +Priority: Lowest,ededed,5 +Stage: Analysis,e6e6e6, +Stage: Backlog,ededed, +Stage: Cancelled,000000, +Stage: In progress,fbca04, +Stage: Review,0052cc, +Stage: Testing,e616e6, +Status: Blocked,d93f0b, +Status: Duplicated,c5def5, +Status: Impediment,b60205, +Status: Needs Fixing,ff8c00, +Type: Bug,fc2929, +Type: Improvement,84b6eb, +Type: New feature,052cc, +Type: Sub-task,ededed,' + +if [[ "$VERBOSE" == 1 ]]; then + echo "Removing default labels" +fi + +while read -r label; do + response=$(gitlab_labels_api DELETE "name=$label") + if [[ "$response" != *"Status: 204"* ]]; then + [[ "$response" != *"Status: 404"* ]] && >&2 echo "Error removing \"$label\": $response" + elif [[ "$VERBOSE" == 1 ]]; then + echo "Label \"$label\" removed" + fi +done <<< "$REMOVE_DEFAULT_LABELS" + +if [[ "$VERBOSE" == 1 ]]; then + echo "Creating new labels" +fi + +while read -r label; do + label_name=$(echo $label | cut -d , -f 1) + label_color=$(echo $label | cut -d , -f 2) + label_priority=$(echo $label | cut -d , -f 3) + response=$(gitlab_labels_api POST "name=$label_name&color=#$label_color&priority=$label_priority") + + if [[ "$response" != *"Status: 201"* ]]; then + [[ "$response" != *"Status: 409"* ]] && >&2 echo "Error on creating: $label_name, response: $response" + elif [[ "$VERBOSE" == 1 ]]; then + echo "Label \"$label_name\" created" + fi +done <<< "$LABELS" +