-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathg-new-task.sh
56 lines (45 loc) · 2.04 KB
/
g-new-task.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
issue_number=$1
if [ ! $(git rev-parse --is-inside-work-tree) ]; then
exit 1;
fi
repo_path=$(git config --get remote.origin.url | sed -r 's/(.*:)(.*)(\..*)/\2/')
if [[ -z $1 ]] || [[ $1 == '--help' ]] || [[ $1 == '-h' ]]; then
printf " Creates a new branch in your computer and change the stage from Analysis to In progress
Usage:
g-new-task issueID
Ex:
g-new-task 3084\n"
exit 0
fi
if [ -z ${GITHUB_USER+x} ] || [ -z ${GITHUB_PASSWORD+x} ] && [ -z ${GITHUB_TOKEN+x} ]; then
printf "If you want to use this script you have to set the environment variables bellow:
\e[33mGITHUB_TOKEN\e[0m
OR
\e[33mGITHUB_USER
GITHUB_PASSWORD\e[0m\n"
exit 1;
fi
if [ ! -z ${GITHUB_TOKEN+x} ]; then
issue_exists=$(curl -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/$repo_path/issues/$issue_number | grep message)
else
issue_exists=$(curl -s -u $GITHUB_USER:$GITHUB_PASSWORD https://api.github.com/repos/$repo_path/issues/$issue_number | grep message)
fi
if [[ $issue_exists == *"Not Found"* ]]; then
printf "\e[33mNo issue with this ID was found\e[0m\n"
exit 1
fi
if [[ $(git branch | grep $issue_number) ]] || [[ $(git branch -r | grep $issue_number) ]]; then
printf "\e[33mThis branch already exists.\e[0m\n"
exit 1
fi
echo "Creating branch from master..."
git fetch origin
git checkout -b $issue_number origin/master
if [ ! -z ${GITHUB_TOKEN+x} ]; then
curl -s -X DELETE -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/$repo_path/issues/$issue_number/labels/Stage%3A%20Analysis >/dev/null
curl -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/$repo_path/issues/$issue_number/labels -d '["Stage: In Progress"]' >/dev/null
else
curl -s -X DELETE -u $GITHUB_USER:$GITHUB_PASSWORD https://api.github.com/repos/$repo_path/issues/$issue_number/labels/Stage%3A%20Analysis >/dev/null
curl -s -u $GITHUB_USER:$GITHUB_PASSWORD https://api.github.com/repos/$repo_path/issues/$issue_number/labels -d '["Stage: In Progress"]' >/dev/null
fi