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

Create labels using github token #4

Merged
merged 4 commits into from
Aug 16, 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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,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
-------

Expand All @@ -35,4 +39,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
```
```
27 changes: 17 additions & 10 deletions coderockr-way-github-setup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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"
Expand Down