Skip to content

Commit 41ddbab

Browse files
committed
feat(changelog script): Have script produce markdown, add settings
This completely revamps the changelog script. It now generates links to the relevant commits in the format of: - [`sha-1 hash`](link on github) subsystem: commit message Additionally, the types of commits shown in the changelog and the root repository for the link may be set at runtime. Example: $ TYPES='feat(;Features' ./generate-changelog.sh v0.9.0 $ REPOROOT="http://github.com/Xe/deis" ./generate-changelog.sh v0.9.0 This is purely cosmetic and to enable this script to be reused more easily. The script is now documented and sourceable as a library for further reuse. REBASE EDIT: Link generation is deduplicated (commit was rebased) so that the commit message is no longer a link to the commit, only the commit hash is. This also no longer uses a temporary file and uses bash command output redirection as a backwards pip to directly pull the changes from git into a while loop. Thanks again @bacongobbler for the guidance on this latest rebase. Technique found here: http://linuxshellaccount.blogspot.com/2008/08/using-bash-to-feed-command-output-to.html
1 parent 68f8a4a commit 41ddbab

1 file changed

Lines changed: 69 additions & 14 deletions

File tree

contrib/util/generate-changelog.sh

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,85 @@
1-
#!/bin/sh
1+
#!/bin/bash
2+
# vim: et tw=0 sw=4 ts=4
23

34
usage() {
45
echo "Usage: $0 <from> [to]"
6+
echo "The REPOROOT and TYPES variables may be used to customize"
7+
echo "what is scraped from the commit logs. Current settings are:"
8+
echo
9+
echo " REPOROOT = $REPOROOT"
10+
echo " TYPES = $TYPES"
11+
echo
512
}
613

14+
# Print the information scraped from git
715
retrieve() {
8-
git --no-pager log --oneline --no-merges --oneline --format=" - %h %s" --grep="$1" $FROM..$TO
16+
while read commit hash message
17+
do
18+
# Extract the subsystem where type(subsystem): message
19+
SUBSYSTEM=$(echo $message | cut -d'(' -f2 | cut -d')' -f1 | sed 's/\*/\(all\)/g')
20+
# Extract the message where type(subsystem): message
21+
MESSAGE=$(echo $message | awk -F ")" '{ print $2}' | sed 's/://' | cut -f2- -d' ')
22+
# Generate a link to the full legal commit on GitHub
23+
LINK="$REPOROOT/commit/$hash"
24+
# Echo all this in a way that makes the commit hash and message a link
25+
# to the commit in markdown
26+
echo ' -' "[\`$commit\`]($LINK)" "$SUBSYSTEM": "$MESSAGE"
27+
done < <(git --no-pager log --oneline --no-merges --oneline --format="%h %H %s" --grep="$1" "$FROM".."$TO")
28+
# Scrape the information from git
929
}
1030

31+
# Wrap feature type and show its relevant commits
1132
subheading() {
12-
echo "#### $1\n"
33+
echo "#### $1"
34+
echo
1335
retrieve "$2"
1436
echo
1537
}
1638

17-
FROM=$1
18-
TO=${2:-"HEAD"}
39+
main() {
40+
# if REPOROOT is already in the environment, don't overload it and use that
41+
if [ -z "$REPOROOT" ];
42+
then
43+
REPOROOT="http://github.com/deis/deis"
44+
fi
1945

20-
if [ -z $1 ];
21-
then
22-
usage
23-
exit 1
24-
fi
46+
# if TYPES is already in the environment, don't overload it and use that
47+
if [ -z "$TYPES" ];
48+
then
49+
# Based on https://github.com/deis/deis/blob/master/CONTRIBUTING.md
50+
# The format is in the form of $shortname;$longname $shortname;longname.
51+
TYPES="feat(;Features fix(;Fixes docs(;Documentation chore(;Maintenance"
52+
fi
53+
54+
# Print usage summary if user didn't specify a beginning
55+
if [ -z "$1" ];
56+
then
57+
usage
58+
exit 1
59+
fi
2560

26-
echo "### $FROM -> $TO\n"
61+
FROM=$1
62+
TO=${2:-"HEAD"}
2763

28-
subheading "Features" "feat("
29-
subheading "Fixes" "fix("
30-
subheading "Documentation" "docs("
64+
printf "### $FROM -> $TO \n\n"
65+
66+
# Iterate over the types of messages specified
67+
for LEGALTYPE in $TYPES
68+
do
69+
SHORT=$(echo "$LEGALTYPE" | cut -f1 -d';')
70+
LONG=$(echo "$LEGALTYPE" | cut -f2 -d';')
71+
72+
subheading $LONG $SHORT
73+
done
74+
}
75+
76+
if (( $SHLVL == 2 ))
77+
then
78+
# If this is being run as a command
79+
main $*
80+
exit
81+
else
82+
# Otherwise this is being sourced
83+
unset -f main
84+
unset -f usage
85+
fi

0 commit comments

Comments
 (0)