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

Script Setup labels for GitHub repository #1

Merged
merged 2 commits into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
# coderockr-way-github-setup
Basic setup to use the Coderockr Way methodology
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

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

How to use
----------
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:

```bash
$ bash -c "$(curl -sL https://raw.githubusercontent.com/coderockr/coderockr-way-github-setup/master/coderockr-way-github-setup.bash)"
Type your Github repository name (owner/repo_name): lucassabreu/coderockr-way-github-setup
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):

Usage: `coderockr-way-github-setup -u githubUser -p githubPassword owner/repo`

```
--user, -u GitHub username
--password, -p GitHub password
--verbose, -v Details process
```

Install
-------

To install into your machine just run the commands bellow, and then use the command `coderockr-way-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
```
130 changes: 130 additions & 0 deletions coderockr-way-github-setup.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/bash

function getHelp {
echo "Setup repository labels

--help, -h Show this help
--user, -u GitHub username
--password, -p GitHub password
--verbose, -v Details process

Usage:
$0 -u githubUser -p githubPassword owner/repo
"
}

function github_api {
curl -u "$GITHUB_USERNAME:$GITHUB_PASSWORD" -sL "https://api.github.com/repos/$GITHUB_REPO/$1" -X "$2" -d "$3"
}

VERBOSE=0
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 == '--user' ]] || [[ $i == '-u' ]]; then
GITHUB_USERNAME=${args[$counter + 1]}
readed_counter=$[$readed_counter + 1]
elif [[ $i == '--password' ]] || [[ $i == '-p' ]]; then
GITHUB_PASSWORD=${args[$counter + 1]}
readed_counter=$[$readed_counter + 1]
elif [[ $i == '--verbose' ]] || [[ $i == '-v' ]]; then
VERBOSE=1
else
GITHUB_REPO=$i
fi

readed_counter=$[$readed_counter + 1]
counter=$[$counter + 1]
done

if [ -z "$GITHUB_REPO" ]; then
read -p "Type your Github repository name (owner/repo_name): " GITHUB_REPO
fi

if [ -z "$GITHUB_USERNAME" ]; then
read -p "Type your Github username: " GITHUB_USERNAME
fi

if [ -z "$GITHUB_PASSWORD" ]; then
read -p "Type your Github password (won't be shown): " -s GITHUB_PASSWORD
echo;
fi

if [ -z "$GITHUB_USERNAME" ] || [ -z "$GITHUB_REPO" ]; then
>&2 echo "There are missing parameters !"
>&2 printf "$(getHelp)"
exit 1
fi

REMOVE_DEFAULT_LABELS='bug
duplicate
enhancement
help%20wanted
invalid
question
wontfix'

LABELS='Category: Backend,c2e0c6
Category: Business/Meetings,0e8a16
Category: DevOps,fef2c0
Category: Frontend,bfdadc
Category: Unit test,ededed
Priority: High,fef2c0
Priority: Highest,b60205
Priority: Low,d4c5f9
Priority: Lowest,ededed
Priority: Medium,d4c5f9
Stage: Analysis,e6e6e6
Stage: Backlog,ededed
Stage: In progress,fbca04
Stage: Review,0052cc
Stage: Testing,e616e6
Status: Blocked,d93f0b
Status: Duplicated,c5def5
Status: Impediment,b60205
Type: Bug,fc2929
Type: Improvement,84b6eb
Type: New feature,0052cc
Type: Sub-task,ededed'

if [[ "$VERBOSE" == 1 ]]; then
echo "Removing default labels"
fi

while read -r label; do
response=$(github_api "labels/$label" DELETE)
if [[ "$response" == *"message"* ]]; then
if [[ ! "$response" == *"Not Found"* ]]; then
echo "Error removing \"$label\": $response"
fi
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)
response=$(github_api labels POST "{\"name\": \"$label_name\", \"color\":\"$label_color\"}")

if [[ "$response" == *"errors"* ]]; then
if [[ ! "$response" == *"already_exists"* ]]; then
>&2 echo "Error on creating: $label_name, response: $response"
fi
elif [[ "$VERBOSE" == 1 ]]; then
echo "Label \"$label_name\" created"
fi
done <<< "$LABELS"