feat(packages): add commit script to automate commit message generation

This commit is contained in:
Mohammad Rafiq 2025-06-12 22:21:30 +08:00
parent e5f942acbe
commit e0887268bd
No known key found for this signature in database
2 changed files with 25 additions and 0 deletions

View file

@ -63,6 +63,7 @@ in
pantheon.rebuild
pantheon.deploy
pantheon.edit
pantheon.commit
inputs.nixspect.packages."x86_64-linux".nixspect
];

View file

@ -0,0 +1,24 @@
{ pkgs, ... }:
pkgs.writeShellScriptBin "commit" # bash
''
PROMPT="Please generate a one-line commit message using."
GUIDELINES="1. Use conventional commit syntax, following the context."
NUM_ANCESTORS=0
while [[ $# -gt 0 ]]; do
case "$1" in
--num-ancestors | -n)
NUM_ANCESTORS="$2"
shift 2
;;
*)
echo "Unrecognised argument: $1. Exiting..."
exit 1
;;
esac
done
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
git commit -am "$RESPONSE"
''