-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprepend-diff-description.sh
More file actions
executable file
·101 lines (83 loc) · 2.85 KB
/
prepend-diff-description.sh
File metadata and controls
executable file
·101 lines (83 loc) · 2.85 KB
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
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
usage () {
cat << EOF
DESCRIPTION:
Updates the given changelog file with a digest of the difference between two OpenAPI spec files.
SYNOPSIS:
$0 -o old_api_spec -n new_api_spec -c change_log [-e email_body_file]
OPTIONS:
-o The YAML file with the old version of the API spec.
-n The YAML file with the new version of the API spec.
-c The ADOC file with the documentation of the API changes.
-e The file into which the HTML code for the changelog notification email is to be pushed.
-h Show this message.
-? Show this message.
EOF
}
while getopts "o: n: c: e: h ?" option ; do
case $option in
o) OLD_API_SPEC_FILE="${OPTARG}"
;;
n) NEW_API_SPEC_FILE="${OPTARG}"
;;
c) CHANGE_LOG_FILE="${OPTARG}"
;;
e) EMAIL_BODY_FILE="${OPTARG}"
;;
h ) usage
exit 0;;
? ) usage
exit 0;;
esac
done
if [[ -z ${OLD_API_SPEC_FILE} ]]; then
echo "ERROR: parameter '-o' not set" >&2
usage
exit 1
fi
if [[ -z ${NEW_API_SPEC_FILE} ]]; then
echo "ERROR: parameter '-n' not set" >&2
usage
exit 1
fi
if [[ -z ${CHANGE_LOG_FILE} ]]; then
echo "ERROR: parameter '-c' not set" >&2
usage
exit 1
fi
################################################################################
# Build change log snippet
################################################################################
CURRENT_DATE=$(date '+%Y-%m-%d')
API_DIFF=$("${SCRIPT_DIR}/diff.sh" "${OLD_API_SPEC_FILE}" "${NEW_API_SPEC_FILE}")
CHANGE_LOG=$(cat <<EOF
## ${CURRENT_DATE}
${API_DIFF}
EOF
)
################################################################################
# Prepare change log email
################################################################################
CHANGE_LOG_EMAIL_BODY=$(cat <<EOF
<pre>
${CHANGE_LOG}
</pre>
<a href="https://docs.beyondshop.cloud/">API Documentation</a> * <a href="https://github.com/ePages-de/beyond-api-changelog/blob/master/beyond-api-changelog.md">Complete changelog</a>
EOF
)
if [[ ! -s ${EMAIL_BODY_FILE} ]]; then
echo "${CHANGE_LOG_EMAIL_BODY}" > "${EMAIL_BODY_FILE}"
fi
################################################################################
# Insert change log
################################################################################
if [[ $API_DIFF == *"* "* ]]; then
echo "Adding API diff into changelog file."
ESCAPED_CHANGE_LOG=$(echo -e "${CHANGE_LOG}" | sed -e 's/[\/&|]/\\&/g')
CHANGE_LOG_PLACEHOLDER="###CHANGE_LOG_HERE###"
sed -i "/# Beyond API Changelog/ a ${CHANGE_LOG_PLACEHOLDER}" "${CHANGE_LOG_FILE}"
perl -pi -e "s/${CHANGE_LOG_PLACEHOLDER}/${ESCAPED_CHANGE_LOG}/g" "${CHANGE_LOG_FILE}"
else
echo "No changes in the API."
fi