feat(packages/commit): add interactive mode to revise commit messages
This commit is contained in:
parent
d714cef3c3
commit
23236b19cb
1 changed files with 40 additions and 5 deletions
|
@ -1,9 +1,11 @@
|
|||
{ pkgs, ... }:
|
||||
pkgs.writeShellScriptBin "commit" # bash
|
||||
''
|
||||
PROMPT="Please generate a one-line commit message using."
|
||||
PROMPT="Please generate a one-line commit message using conventional commit syntax, following the context."
|
||||
GUIDELINES="1. Use conventional commit syntax, following the context. "
|
||||
NUM_ANCESTORS=0
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--num-ancestors | -n)
|
||||
|
@ -16,9 +18,42 @@ pkgs.writeShellScriptBin "commit" # bash
|
|||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Get context and diff
|
||||
CONTEXT=$(git --no-pager log -n 10)
|
||||
DIFF=$(git --no-pager diff HEAD~$NUM_ANCESTORS)
|
||||
RESPONSE=$(aichat "$PROMPT\nGuidelines: $GUIDELINES\nContext from git log: $CONTEXT\nDiff from git diff HEAD: $DIFF")
|
||||
#TODO: revise commit message
|
||||
|
||||
# Generate initial response
|
||||
RESPONSE=$(aichat "$PROMPT\nGuidelines: $GUIDELINES\nContext from git log:\n$CONTEXT\nDiff from git diff HEAD:\n$DIFF")
|
||||
|
||||
while true; do
|
||||
echo "Generated Commit Message:"
|
||||
echo "$RESPONSE"
|
||||
echo "Options: [y]es, [r]eroll, [e]dit, [q]uit?"
|
||||
read -r -p "Choose an action: " choice
|
||||
|
||||
case "$choice" in
|
||||
y | yes)
|
||||
git commit -am "$RESPONSE"
|
||||
echo "Committed successfully."
|
||||
exit 0
|
||||
;;
|
||||
r | reroll)
|
||||
RESPONSE=$(aichat "$PROMPT\nGuidelines: $GUIDELINES\nContext from git log:\n$CONTEXT\nDiff from git diff HEAD:\n$DIFF")
|
||||
;;
|
||||
e | edit)
|
||||
echo "$RESPONSE" > /tmp/commit_msg.txt
|
||||
"$EDITOR" /tmp/commit_msg.txt
|
||||
RESPONSE=$(cat /tmp/commit_msg.txt)
|
||||
rm /tmp/commit_msg.txt
|
||||
;;
|
||||
q | quit | "")
|
||||
echo "Aborted."
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo "Invalid choice. Please choose again."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue