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
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
> aicommit_groq is broken. Don't use.
### use
Instead of
Change your
```bash
git commit -m "your message here"`
export GIT_EDITOR="<path/to/>aicommit"
```
```bash
aicommit
git commit
```

View File

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