Now stands as middleware between the git commit command and the default
editor.
This commit is contained in:
parent
455ae71cd3
commit
f863bce0fa
39
aicommit
39
aicommit
@ -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 "Failed to reset conversation."
|
||||
exit 1
|
||||
fi
|
||||
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
|
||||
|
||||
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}" "$@"
|
||||
|
Loading…
Reference in New Issue
Block a user