-
Notifications
You must be signed in to change notification settings - Fork 7
/
step.sh
executable file
·98 lines (76 loc) · 2.25 KB
/
step.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
set -e
red=$'\e[31m'
green=$'\e[32m'
blue=$'\e[34m'
magenta=$'\e[35m'
cyan=$'\e[36m'
reset=$'\e[0m'
MERGES=$(git log --pretty=format:%s $(git merge-base --octopus $(git log -1 --merges --pretty=format:%P))..$(git log -1 --merges --pretty=format:%H))
SAVEDIFS=$IFS
IFS=$'\n'
MERGES=($MERGES)
IFS=$SAVEDIFS
LAST_COMMIT=$(git log -1 --pretty=format:%B)
TASKS=()
echo "${blue}⚡ ️Last commit:${cyan}"
echo $'\t'"📜 "$LAST_COMMIT
echo "${reset}"
if (( ${#MERGES[*]} > 0 ))
then
echo "${blue}⚡ Last merge commits:${cyan}"
for (( i=0 ; i<${#MERGES[*]} ; ++i ))
do
echo $'\t'"📜 "${MERGES[$i]}
done
echo "${reset}"
if [ "$LAST_COMMIT" = "${MERGES[0]}" ];
then
echo "${green}✅ Merge commit detected. Searching for tasks in merge commits messages...${cyan}"
for (( i=0 ; i<${#MERGES[*]} ; ++i ))
do
echo $'\t'"📜 "${MERGES[$i]}
done
for task in $(echo $MERGES | grep "$project_prefix[0-9]{1,5}" -E -o || true | sort -u -r --version-sort)
do
if [[ ! " ${TASKS[@]} " =~ " ${task} " ]]; then
TASKS+=($task)
fi
done
else
echo "${magenta}☑️ Not a merge commit. Searching for tasks in current commit message...${cyan}"
echo
echo $'\t'"📜 "$LAST_COMMIT "${reset}"
for task in $(echo $LAST_COMMIT | grep "$project_prefix[0-9]{1,5}" -E -o || true | sort -u -r --version-sort)
do
if [[ ! " ${TASKS[@]} " =~ " ${task} " ]]; then
TASKS+=($task)
fi
done
fi
fi
echo "${blue}✉️ Comment:${cyan}"
escaped_jira_comment=$(echo "$jira_comment" | perl -pe 's/\n/\\n/g' | sed 's/.\{2\}$//')
create_comment_data()
{
cat<<EOF
{
"body": "${escaped_jira_comment}"
}
EOF
}
comment_data="$(create_comment_data)"
echo "${blue}⚡ Posting to:"
for (( i=0 ; i<${#TASKS[*]} ; ++i ))
do
echo $'\t'"${magenta}⚙️ "${TASKS[$i]}
res="$(curl --write-out %{response_code} --silent --output /dev/null --user $jira_user:$jira_token --request POST --header "Content-Type: application/json" --data-binary "${comment_data}" --url https://${backlog_default_url}/rest/api/2/issue/${TASKS[$i]}/comment)"
if test "$res" == "201"
then
echo $'\t'$'\t'"${green}✅ Success!${reset}"
else
echo $'\t'$'\t'"${red}❗️ Failed${reset}"
echo $res
fi
done
echo "${reset}"