-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathgenerate-changelog.sh
More file actions
executable file
·85 lines (74 loc) · 2.35 KB
/
generate-changelog.sh
File metadata and controls
executable file
·85 lines (74 loc) · 2.35 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
#!/usr/bin/env bash
# vim: et tw=0 sw=4 ts=4
usage() {
echo "Usage: $0 <from> [to]"
echo "The REPOROOT and TYPES variables may be used to customize"
echo "what is scraped from the commit logs. Current settings are:"
echo
echo " REPOROOT = $REPOROOT"
echo " TYPES = $TYPES"
echo
}
# Print the information scraped from git
retrieve() {
while read 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() {
# if REPOROOT is already in the environment, don't overload it and use that
if [ -z "$REPOROOT" ];
then
REPOROOT="https://github.com/deis/deis"
fi
# if TYPES is already in the environment, don't overload it and use that
if [ -z "$TYPES" ];
then
# Based on https://github.com/deis/deis/blob/master/CONTRIBUTING.md
# The format is in the form of $shortname;$longname $shortname;longname.
TYPES="feat(;Features fix(;Fixes docs(;Documentation chore(;Maintenance"
fi
# Print usage summary if user didn't specify a beginning
if [ -z "$1" ];
then
usage
exit 1
fi
FROM=$1
TO=${2:-"HEAD"}
printf "### $FROM -> $TO\n\n"
# 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 == 2 ))
then
# If this is being run as a command
main $*
exit
else
# Otherwise this is being sourced
unset -f main
unset -f usage
fi