-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease-preflight.sh
executable file
·109 lines (91 loc) · 3.02 KB
/
release-preflight.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
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
IFS=$'\n'
TMP_FILE=/tmp/release-$(date +"%T").log
# Update local origin
echo "Fetching latest from origin..."
git fetch -q
if [[ -z "$TARGET_BRANCH" ]]; then
TARGET_BRANCH="master"
fi
if [[ -z "$SOURCE_BRANCH" ]]; then
SOURCE_BRANCH="develop"
fi
# Write comparison of master and develop to temp file
git log origin/"$TARGET_BRANCH"..origin/"$SOURCE_BRANCH" --oneline --no-merges --pretty=format:"%s" > $TMP_FILE
# Read in domain name if it's not provided in env
if [[ -z $JIRA_DOMAIN ]]; then
echo -n "JIRA domain: "
read JIRA_DOMAIN
printf "\n"
fi
# Read in name and password if they're not provided in env
if ([[ -z "$JIRA_USERNAME" ]] || [[ -z "$JIRA_PASSWORD" ]]) && [[ -z $JIRA_AUTH ]]; then
echo "Enter JIRA credentials"
echo -n "Username: "
read JIRA_USERNAME
echo -n "Password: "
read -s JIRA_PASSWORD
printf "\n"
fi
downloadIssue() {
BRANCH_NAME=$1
ISSUE_KEY=$(echo $BRANCH_NAME | cut -d '/' -f 2)
# Issue call requires auth token or username and password to be passed as environment variables
if [[ -n $JIRA_AUTH ]]; then
curl -s --request GET \
--url "https://$JIRA_DOMAIN.atlassian.net/rest/api/3/issue/$ISSUE_KEY?fields=summary" \
--header "Authorization: Basic $JIRA_AUTH" \
--header "Accept: application/json" | \
perl -nle'print $& while m{"'"summary"'"\s*:\s*"\K([^"]*)}g'
else
curl -s --request GET \
-u "$JIRA_USERNAME:$JIRA_PASSWORD" \
--url "https://$JIRA_DOMAIN.atlassian.net/rest/api/3/issue/$ISSUE_KEY?fields=summary" \
--header "Accept: application/json" | \
perl -nle'print $& while m{"'"summary"'"\s*:\s*"\K([^"]*)}g'
fi
}
cleanUp() {
rm $TMP_FILE
unset IFS
}
OTHER=()
CONVENTIONAL=()
while read -r commit ; do
if echo $commit | grep -q "release/*"; then
continue
elif echo $commit | grep -qE "^[^:]*$"; then
OTHER=("${OTHER[@]}" "$commit")
elif echo $commit | grep -qE "[A-Za-z]{3,11}\/[A-Za-z]{2,4}-[0-9]{1,5}"; then
CONVENTIONAL=("${CONVENTIONAL[@]}" "$(echo $commit | cut -d ':' -f 1)")
else
OTHER=("${OTHER[@]}" "$(echo $commit | cut -d ':' -f 1)")
fi
done < $TMP_FILE
# Remove duplicates and put commits that follow the convention in an array
SORTED_CONVENTIONAL=($(sort -u <<<"${CONVENTIONAL[*]}"))
# Remove duplicates and put everything else in an array
SORTED_OTHER=($(sort -u <<<"${OTHER[*]}"))
# Display if JIRA issues if commits are found with issue IDs
if [ "${#SORTED_CONVENTIONAL[@]}" -ne 0 ]; then
echo "==================== TICKETS ===================="
for i in "${SORTED_CONVENTIONAL[@]}"
do
ISSUE_TITLE=$(downloadIssue $i)
if [[ -n $ISSUE_TITLE ]]; then
echo "$i: $ISSUE_TITLE"
else
echo $i
fi
done
fi
# Display if other commits that are not associated with JIRA issues
if [ "${#SORTED_OTHER[@]}" -ne 0 ]; then
echo "==================== OTHER ======================"
echo "${SORTED_OTHER[*]}"
fi
# Display message if no changes are found
if [ "${#SORTED_CONVENTIONAL[@]}" -eq 0 ] && [ "${#SORTED_OTHER[@]}" -eq 0 ]; then
echo "No changes found."
fi
cleanUp