summaryrefslogtreecommitdiff
path: root/bin/auto-changelog
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2017-01-03 23:02:19 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2017-01-03 23:02:19 -0500
commit5e257d407b4abf2be61c656dfb1d383396df35b1 (patch)
tree7d8914d78aeb741c7d0ae787eb4acbcce93f5f38 /bin/auto-changelog
parentba05c5fb2ccf4b5e90c97adc17e784a77248d9f1 (diff)
ChangeLog
Diffstat (limited to 'bin/auto-changelog')
-rwxr-xr-xbin/auto-changelog46
1 files changed, 46 insertions, 0 deletions
diff --git a/bin/auto-changelog b/bin/auto-changelog
new file mode 100755
index 0000000..dcf33a2
--- /dev/null
+++ b/bin/auto-changelog
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+set -e
+
+list-files() {
+ git show --pretty="" --name-only HEAD
+}
+
+list-articles() {
+ list-files | grep -E '^src/.*[.](md|org)$' | grep -v -e '/index[.]md$' -e '/ChangeLog[.]md$'
+}
+
+should-insert() {
+ test -n "$(list-articles)"
+}
+
+generate-entry() {
+ git log -n1 --stat --date='format:%Y-%m-%d' --format=$'## %ad %an <%ae>\n\n%B' | cat -s
+}
+
+html_escape() {
+ sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' -e 's/^ \S/ &/'
+}
+
+insert() {
+ {
+ printf '%s\n' \
+ 'ChangeLog' \
+ '=========' \
+ ''
+
+ generate-entry | html_escape
+ echo
+ cat src/ChangeLog.md | sed '1,3d'
+ } | bin/write-atomic src/ChangeLog.md
+}
+
+main() {
+ cd "$(dirname -- "$0")/.."
+ if should-insert; then
+ insert
+ git add src/ChangeLog.md
+ git commit -m 'Auto-insert entry to ChangeLog'
+ fi
+}
+
+main "$@"