Skip to content

Commit b74f82a

Browse files
author
Euclécio Josias
committed
Create labels using github token
1 parent 96a48eb commit b74f82a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

coderockr-way-github-setup.bash

+17-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ Usage:
1414
}
1515

1616
function github_api {
17-
curl -u "$GITHUB_USERNAME:$GITHUB_PASSWORD" -sL "https://api.github.com/repos/$GITHUB_REPO/$1" -X "$2" -d "$3"
17+
AUTHORIZATION="$GITHUB_USER:$GITHUB_PASSWORD"
18+
COMMAND='-u'
19+
[ ! -z ${GITHUB_TOKEN+x} ] && {
20+
AUTHORIZATION="Authorization: token $GITHUB_TOKEN"
21+
COMMAND='-H'
22+
}
23+
24+
curl $COMMAND "$AUTHORIZATION" -sL "https://api.github.com/repos/$GITHUB_REPO/$1" -X "$2" -d "$3"
1825
}
1926

2027
VERBOSE=0
@@ -36,9 +43,9 @@ do
3643
GITHUB_PASSWORD=${args[$counter + 1]}
3744
readed_counter=$[$readed_counter + 1]
3845
elif [[ $i == '--verbose' ]] || [[ $i == '-v' ]]; then
39-
VERBOSE=1
46+
VERBOSE=1
4047
else
41-
GITHUB_REPO=$i
48+
GITHUB_REPO=$i
4249
fi
4350

4451
readed_counter=$[$readed_counter + 1]
@@ -49,16 +56,16 @@ if [ -z "$GITHUB_REPO" ]; then
4956
read -p "Type your Github repository name (owner/repo_name): " GITHUB_REPO
5057
fi
5158

52-
if [ -z "$GITHUB_USERNAME" ]; then
59+
if [ -z "$GITHUB_USERNAME" ] && [ -z $GITHUB_TOKEN ]; then
5360
read -p "Type your Github username: " GITHUB_USERNAME
5461
fi
5562

56-
if [ -z "$GITHUB_PASSWORD" ]; then
63+
if [ -z "$GITHUB_PASSWORD" ] && [ -z $GITHUB_TOKEN ]; then
5764
read -p "Type your Github password (won't be shown): " -s GITHUB_PASSWORD
5865
echo;
5966
fi
6067

61-
if [ -z "$GITHUB_USERNAME" ] || [ -z "$GITHUB_REPO" ]; then
68+
if [ -z "$GITHUB_USERNAME" ] || [ -z "$GITHUB_REPO" ] && [ -z $GITHUB_TOKEN ]; then
6269
>&2 echo "There are missing parameters !"
6370
>&2 printf "$(getHelp)"
6471
exit 1
@@ -102,7 +109,7 @@ Type: Improvement,84b6eb
102109
Type: New feature,0052cc
103110
Type: Sub-task,ededed'
104111

105-
if [[ "$VERBOSE" == 1 ]]; then
112+
if [[ "$VERBOSE" == 1 ]]; then
106113
echo "Removing default labels"
107114
fi
108115

@@ -112,12 +119,12 @@ while read -r label; do
112119
if [[ ! "$response" == *"Not Found"* ]]; then
113120
echo "Error removing \"$label\": $response"
114121
fi
115-
elif [[ "$VERBOSE" == 1 ]]; then
122+
elif [[ "$VERBOSE" == 1 ]]; then
116123
echo "Label \"$label\" removed"
117124
fi
118125
done <<< "$REMOVE_DEFAULT_LABELS"
119126

120-
if [[ "$VERBOSE" == 1 ]]; then
127+
if [[ "$VERBOSE" == 1 ]]; then
121128
echo "Creating new labels"
122129
fi
123130

@@ -130,7 +137,7 @@ while read -r label; do
130137
if [[ ! "$response" == *"already_exists"* ]]; then
131138
>&2 echo "Error on creating: $label_name, response: $response"
132139
fi
133-
elif [[ "$VERBOSE" == 1 ]]; then
140+
elif [[ "$VERBOSE" == 1 ]]; then
134141
echo "Label \"$label_name\" created"
135142
fi
136143
done <<< "$LABELS"

0 commit comments

Comments
 (0)