Skip to content

Commit af6bc3d

Browse files
committed
Merge pull request #41 from mboersma/add-changelog
feat(_scripts): add CHANGELOG.md generator script
2 parents 4fda8e8 + 5604e59 commit af6bc3d

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

_scripts/generate-changelog.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bash
2+
# vim: et tw=0 sw=4 ts=4
3+
4+
REPOROOT=${REPOROOT:=https://github.com/deis/workflow-cli}
5+
TYPES=${TYPES:=feat(;Features fix(;Fixes docs(;Documentation chore(;Maintenance}
6+
7+
usage() {
8+
echo "Usage: $0 <from> [to]
9+
10+
The REPOROOT and TYPES variables may be used to customize what links are
11+
generated and what is scraped from the commit logs. Current settings are:
12+
13+
REPOROOT=$REPOROOT
14+
TYPES=$TYPES
15+
"
16+
}
17+
18+
# Print the information scraped from git
19+
retrieve() {
20+
while read -r commit hash message; do
21+
# Extract the subsystem where type(subsystem): message
22+
SUBSYSTEM=$(echo "$message" | cut -d'(' -f2 | cut -d')' -f1 | sed 's/\*/\(all\)/g')
23+
# Extract the message where type(subsystem): message
24+
MESSAGE=$(echo "$message" | awk -F ")" '{ print $2}' | sed 's/://' | cut -f2- -d' ')
25+
# Generate a link to the full legal commit on GitHub
26+
LINK="$REPOROOT/commit/$hash"
27+
# Echo all this in a way that makes the commit hash and message a link
28+
# to the commit in markdown
29+
echo ' -' "[\`$commit\`]($LINK)" "$SUBSYSTEM": "$MESSAGE"
30+
done < <(git --no-pager log --oneline --merges --oneline --format="%h %H %b" --grep="$1" "$FROM".."$TO")
31+
# Scrape the information from git
32+
}
33+
34+
# Wrap feature type and show its relevant commits
35+
subheading() {
36+
echo "#### $1"
37+
echo
38+
retrieve "$2"
39+
echo
40+
}
41+
42+
main() {
43+
# Print usage summary if user didn't specify a beginning
44+
if [ -z "$1" ]; then
45+
usage
46+
exit 1
47+
fi
48+
49+
FROM=$1
50+
TO=${2:-"HEAD"}
51+
52+
printf "### %s -> %s\n\n" "$FROM" "$TO"
53+
54+
# Iterate over the types of messages specified
55+
for LEGALTYPE in $TYPES; do
56+
SHORT=$(echo "$LEGALTYPE" | cut -f1 -d';')
57+
LONG=$(echo "$LEGALTYPE" | cut -f2 -d';')
58+
subheading "$LONG" "$SHORT"
59+
done
60+
}
61+
62+
if [ $SHLVL -eq 2 ]; then
63+
# If this is being run as a command
64+
main "$@"
65+
else
66+
# Otherwise this is being sourced
67+
unset -f main
68+
unset -f usage
69+
fi

0 commit comments

Comments
 (0)