Last active
August 18, 2023 21:14
-
-
Save gfranxman/e9d4a523397535c6dd82d1445c246b8d to your computer and use it in GitHub Desktop.
Git hook that uses llm to prepare commit messages as release notes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# https://gist.github.com/gfranxman/e9d4a523397535c6dd82d1445c246b8d/edit | |
# 2023-08-18 | |
COMMIT_MSG_FILE=$1 | |
COMMIT_SOURCE=$2 | |
SHA1=$3 | |
REL_NOTES_RAW=`git diff --staged | llm -s "release notes" 2>/dev/null` | |
REL_NOTES_RAW=$(echo "$REL_NOTES_RAW" | sed 's/^#/* /') | |
REL_NOTES_ESCAPED=$(echo "$REL_NOTES_RAW" | awk '{print $0 "\\n"}') | |
REL_NOTES=$(echo "$REL_NOTES" | sed 's/^/# /') | |
# if you want the rel notes as comments | |
#awk -v r="$REL_NOTES" 'NR==1 {print r} {print}' "$COMMIT_MSG_FILE" > tmpfile && mv tmpfile "$COMMIT_MSG_FILE" | |
# or ready to go: | |
awk -v r="$REL_NOTES_RAW" 'NR==1 {print r} {print}' "$COMMIT_MSG_FILE" > tmpfile && mv tmpfile "$COMMIT_MSG_FILE" | |
/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment