├── LICENSE ├── README.md ├── coderockr-way-github-setup.bash └── coderockr-way-gitlab-setup.bash /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Coderockr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Coderockr Way Github Setup 2 | -------------------------- 3 | Using this script your project will be bootstraped with the basic labels needed to control your issues according with the *Coderockr Way* methodology 4 | 5 | You can take a look here: https://github.com/coderockr/coderockr-way-github-setup/labels 6 | 7 | We now support setting up projects on [GitHub](#github) and [GitLab](#gitlab), click in the links to see more. 8 | 9 | How to use 10 | ---------- 11 | 12 | ### GitHub 13 | 14 | This repository has a script named [`coderockr-way-github-setup.bash`](coderockr-way-github-setup.bash) there are two ways to use it. 15 | 16 | 1) You could just call it direct from GitHub using cURL, and it will ask you the info to updated your repository: 17 | 18 | ```bash 19 | $ bash -c "$(curl -sL https://raw.githubusercontent.com/coderockr/coderockr-way-github-setup/master/coderockr-way-github-setup.bash)" 20 | Type your Github repository name (owner/repo_name): lucassabreu/coderockr-way-github-setup 21 | Type your Github username: lucassabreu 22 | Type your Github password (won't be shown): 23 | ``` 24 | 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): 26 | 27 | Usage: `coderockr-way-github-setup -u githubUser -p githubPassword owner/repo` 28 | 29 | ``` 30 | --user, -u GitHub username 31 | --password, -p GitHub password 32 | --verbose, -v Details process 33 | ``` 34 | 35 | #### Using Github Token 36 | 37 | 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 38 | 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: 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 | 62 | Install 63 | ------- 64 | 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 68 | 69 | ```sh 70 | 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" 71 | chmod a+x /usr/local/bin/coderockr-way-github-setup 72 | ``` 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 | ``` 80 | -------------------------------------------------------------------------------- /coderockr-way-github-setup.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function getHelp { 4 | echo "Setup repository labels 5 | 6 | --help, -h Show this help 7 | --user, -u GitHub username 8 | --password, -p GitHub password 9 | --verbose, -v Details process 10 | 11 | Usage: 12 | $0 -u githubUser -p githubPassword owner/repo\n" 13 | } 14 | 15 | function github_api { 16 | AUTHORIZATION="$GITHUB_USERNAME:$GITHUB_PASSWORD" 17 | COMMAND='-u' 18 | [ ! -z ${GITHUB_TOKEN+x} ] && { 19 | AUTHORIZATION="Authorization: token $GITHUB_TOKEN" 20 | COMMAND='-H' 21 | } 22 | 23 | curl $COMMAND "$AUTHORIZATION" -sL "https://api.github.com/repos/$GITHUB_REPO/$1" -X "$2" -d "$3" 24 | } 25 | 26 | VERBOSE=0 27 | args=("$@") 28 | for i in "$@" 29 | do 30 | if [ ! -z "$counter" ] && [[ "$counter" != "$readed_counter" ]]; then 31 | counter=$[$counter + 1] 32 | continue 33 | fi 34 | 35 | if [[ "$i" = "--help" ]] || [[ "$i" = "-h" ]]; then 36 | printf "$(getHelp)" 37 | exit 0 38 | elif [[ $i == '--user' ]] || [[ $i == '-u' ]]; then 39 | GITHUB_USERNAME=${args[$counter + 1]} 40 | readed_counter=$[$readed_counter + 1] 41 | elif [[ $i == '--password' ]] || [[ $i == '-p' ]]; then 42 | GITHUB_PASSWORD=${args[$counter + 1]} 43 | readed_counter=$[$readed_counter + 1] 44 | elif [[ $i == '--verbose' ]] || [[ $i == '-v' ]]; then 45 | VERBOSE=1 46 | else 47 | GITHUB_REPO=$i 48 | fi 49 | 50 | readed_counter=$[$readed_counter + 1] 51 | counter=$[$counter + 1] 52 | done 53 | 54 | if [ -z "$GITHUB_REPO" ]; then 55 | read -p "Type your Github repository name (owner/repo_name): " GITHUB_REPO 56 | fi 57 | 58 | if [ -z "$GITHUB_USERNAME" ] && [ -z $GITHUB_TOKEN ]; then 59 | read -p "Type your Github username: " GITHUB_USERNAME 60 | fi 61 | 62 | if [ -z "$GITHUB_PASSWORD" ] && [ -z $GITHUB_TOKEN ]; then 63 | read -p "Type your Github password (won't be shown): " -s GITHUB_PASSWORD 64 | echo; 65 | fi 66 | 67 | if [ -z "$GITHUB_USERNAME" ] || [ -z "$GITHUB_REPO" ] && [ -z $GITHUB_TOKEN ]; then 68 | >&2 echo "There are missing parameters !" 69 | >&2 printf "$(getHelp)" 70 | exit 1 71 | fi 72 | 73 | REMOVE_DEFAULT_LABELS='bug 74 | duplicate 75 | enhancement 76 | good%20first%20issue 77 | help%20wanted 78 | invalid 79 | question 80 | wontfix' 81 | 82 | LABELS='Category: Backend,c2e0c6 83 | Category: Business/Meetings,0e8a16 84 | Category: DevOps,fef2c0 85 | Category: Frontend,bfdadc 86 | Category: Infrastructure,f0e68c 87 | Category: Report,40e0d0 88 | Category: Unit test,ededed 89 | Level: Easy,48d1cc 90 | Level: Medium,20b2aa 91 | Level: Hard,008b8b 92 | Priority: High,fef2c0 93 | Priority: Highest,b60205 94 | Priority: Low,d4c5f9 95 | Priority: Lowest,ededed 96 | Priority: Medium,d4c5f9 97 | Stage: Analysis,e6e6e6 98 | Stage: Backlog,ededed 99 | Stage: Cancelled,000000 100 | Stage: In progress,fbca04 101 | Stage: Review,0052cc 102 | Stage: Testing,e616e6 103 | Status: Blocked,d93f0b 104 | Status: Duplicated,c5def5 105 | Status: Impediment,b60205 106 | Status: Needs Fixing,ff8c00 107 | Type: Bug,fc2929 108 | Type: Improvement,84b6eb 109 | Type: New feature,0052cc 110 | Type: Sub-task,ededed' 111 | 112 | if [[ "$VERBOSE" == 1 ]]; then 113 | echo "Removing default labels" 114 | fi 115 | 116 | while read -r label; do 117 | response=$(github_api "labels/$label" DELETE) 118 | if [[ "$response" == *"message"* ]]; then 119 | if [[ ! "$response" == *"Not Found"* ]]; then 120 | echo "Error removing \"$label\": $response" 121 | fi 122 | elif [[ "$VERBOSE" == 1 ]]; then 123 | echo "Label \"$label\" removed" 124 | fi 125 | done <<< "$REMOVE_DEFAULT_LABELS" 126 | 127 | if [[ "$VERBOSE" == 1 ]]; then 128 | echo "Creating new labels" 129 | fi 130 | 131 | while read -r label; do 132 | label_name=$(echo $label | cut -d , -f 1) 133 | label_color=$(echo $label | cut -d , -f 2) 134 | response=$(github_api labels POST "{\"name\": \"$label_name\", \"color\":\"$label_color\"}") 135 | 136 | if [[ "$response" == *"errors"* ]]; then 137 | if [[ ! "$response" == *"already_exists"* ]]; then 138 | >&2 echo "Error on creating: $label_name, response: $response" 139 | fi 140 | elif [[ "$VERBOSE" == 1 ]]; then 141 | echo "Label \"$label_name\" created" 142 | fi 143 | done <<< "$LABELS" 144 | 145 | -------------------------------------------------------------------------------- /coderockr-way-gitlab-setup.bash: -------------------------------------------------------------------------------- 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 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 | 155 | --------------------------------------------------------------------------------