-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgenerate-changelog.sh
More file actions
executable file
·69 lines (58 loc) · 1.94 KB
/
generate-changelog.sh
File metadata and controls
executable file
·69 lines (58 loc) · 1.94 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
#!/usr/bin/env bash
# vim: et tw=0 sw=4 ts=4
REPOROOT=${REPOROOT:=https://github.com/deis/controller}
TYPES=${TYPES:=feat(;Features fix(;Fixes docs(;Documentation chore(;Maintenance}
usage() {
echo "Usage: $0 <from> [to]
The REPOROOT and TYPES variables may be used to customize what links are
generated and what is scraped from the commit logs. Current settings are:
REPOROOT=$REPOROOT
TYPES=$TYPES
"
}
# Print the information scraped from git
retrieve() {
while read -r commit hash message; do
# Extract the subsystem where type(subsystem): message
SUBSYSTEM=$(echo "$message" | cut -d'(' -f2 | cut -d')' -f1 | sed 's/\*/\(all\)/g')
# Extract the message where type(subsystem): message
MESSAGE=$(echo "$message" | awk -F ")" '{ print $2}' | sed 's/://' | cut -f2- -d' ')
# Generate a link to the full legal commit on GitHub
LINK="$REPOROOT/commit/$hash"
# Echo all this in a way that makes the commit hash and message a link
# to the commit in markdown
echo ' -' "[\`$commit\`]($LINK)" "$SUBSYSTEM": "$MESSAGE"
done < <(git --no-pager log --oneline --merges --oneline --format="%h %H %b" --grep="$1" "$FROM".."$TO")
# Scrape the information from git
}
# Wrap feature type and show its relevant commits
subheading() {
echo "#### $1"
echo
retrieve "$2"
echo
}
main() {
# Print usage summary if user didn't specify a beginning
if [ -z "$1" ]; then
usage
exit 1
fi
FROM=$1
TO=${2:-"HEAD"}
printf "### %s -> %s\n\n" "$FROM" "$TO"
# Iterate over the types of messages specified
for LEGALTYPE in $TYPES; do
SHORT=$(echo "$LEGALTYPE" | cut -f1 -d';')
LONG=$(echo "$LEGALTYPE" | cut -f2 -d';')
subheading "$LONG" "$SHORT"
done
}
if [ $SHLVL -eq 2 ]; then
# If this is being run as a command
main "$*"
else
# Otherwise this is being sourced
unset -f main
unset -f usage
fi