Compare commits

..

2 Commits

2 changed files with 21 additions and 30 deletions

View File

@ -1,15 +1,19 @@
## use AI to draft commit messages ## use AI to draft commit messages
clone this repo and then link the scripts into your path. aicommit injects a commit message draft written by RayAI before loading your default editor for review.
requires: jq requires: jq
> aicommit_groq is broken. Don't use.
### use ### use
Instead of
Change your
```bash ```bash
git commit -m "your message here"` export GIT_EDITOR="<path/to/>aicommit"
``` ```
```bash ```bash
aicommit git commit
``` ```

View File

@ -3,7 +3,8 @@ set -e
ARGS=("${@-}") ARGS=("${@-}")
TMP_FILE="/tmp/aicommit" TMP_FILE="/tmp/aicommit_tmp"
system=$( system=$(
cat - <<EOF cat - <<EOF
@ -14,21 +15,6 @@ Give detail for every change in the diff.
EOF EOF
) )
pushd "$(pwd)" >/dev/null
hasFlag() {
local flags=("$@")
for var in "${ARGS[@]}"; do
for flag in "${flags[@]}"; do
if [[ ${flag} == "${var}" ]]; then
echo 'true'
return
fi
done
done
echo 'false'
}
if ! diff=$(git diff --cached); then if ! diff=$(git diff --cached); then
echo "Failed to get diff." echo "Failed to get diff."
exit 1 exit 1
@ -41,13 +27,12 @@ message=$(
".message = $(jq -R -s '@json' <<<"${message_cat}")" ".message = $(jq -R -s '@json' <<<"${message_cat}")"
) )
# trunk-ignore(shellcheck/SC2091) echo ""
# trunk-ignore(shellcheck/SC2310) echo "Please wait for AI reponse..."
if $(hasFlag -r --reset); then
if ! curl -s -X POST https://infer.x64.world/reset-conversation >/dev/null; then if ! curl -s -X POST https://infer.x64.world/reset-conversation >/dev/null; then
echo "Failed to reset conversation." echo "Failed to reset conversation."
exit 1 exit 1
fi
fi fi
curl -s "https://infer.x64.world/chat" \ curl -s "https://infer.x64.world/chat" \
@ -55,12 +40,14 @@ curl -s "https://infer.x64.world/chat" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "${message}" | jq -r '.content | gsub("\""; "")' >"${TMP_FILE}" -d "${message}" | jq -r '.content | gsub("\""; "")' >"${TMP_FILE}"
# trunk-ignore(shellcheck/SC2181)
if [[ 0 -ne $? ]]; then if [[ 0 -ne $? ]]; then
echo "Failed to get response." echo "Failed to get response."
exit 1 exit 1
fi fi
git commit -e -m "$(cat "${TMP_FILE}")" && rm "${TMP_FILE}" cat ".git/COMMIT_EDITMSG" >>"${TMP_FILE}"
cat "${TMP_FILE}" >".git/COMMIT_EDITMSG"
popd >/dev/null rm "${TMP_FILE}"
"${EDITOR}" "$@"