Compare commits

5 Commits

Author SHA1 Message Date
43b79b2914 Delete test file: remove This is a test. line from test.txt 2024-08-08 02:26:00 -07:00
baed3d5d17 Update README.md with new instructions on using aicommit
Replace outdated information about `aicommit_groq`
Clarify prerequisites for using Aicommit
Add setup and usage section to README.md
Document bypassing AI-generated commit messages using the `-m` flag
2024-08-08 02:22:20 -07:00
e3704b4e6e update README to reflect new feature and remove deprecated usage of aicommit_groq 2024-08-08 02:15:21 -07:00
141b53b4ba Added AI-driven commit message drafting with aicommit, injecting draft messages before editor review. Fixed README to reflect usage and requirements. 2024-08-08 01:38:37 -07:00
f863bce0fa Now stands as middleware between the git commit command and the default
editor.
2024-08-08 01:30:10 -07:00
2 changed files with 32 additions and 35 deletions

View File

@ -1,15 +1,25 @@
## use AI to draft commit messages
# **Use AI to Draft Commit Messages with Aicommit**
clone this repo and then link the scripts into your path.
Aicommit integrates with RayAI to generate a draft commit message, which is then loaded into your default editor for review and editing.
requires: jq
## **Prerequisites**
### use
Instead of
To use Aicommit, you need to have the following tools installed:
- `curl`
- `jq`
**Note**: Aicommit-groq is currently broken and should not be used.
## **Setup and Usage**
1. **Clone the repository**: Clone the Aicommit repository to your local machine.
2. **Configure your Git editor**: Add the following line to your `~/.bashrc` file, replacing `<path/to/>` with the actual path to the Aicommit executable:
```bash
git commit -m "your message here"`
```
```bash
aicommit
export GIT_EDITOR="<path/to/>aicommit"
```
3. **Use Git as normal**: Once configured, you can use Git as you normally would. When you run `git commit`, Aicommit will generate a draft commit message using RayAI, which will then be loaded into your default editor for review and editing.
**Bypassing AI-generated messages**: If you prefer to write your own commit message, you can use the `-m` flag with `git commit`, like this: `git commit -m "your message here"`. This will bypass the AI-generated message and allow you to write your own message directly.

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 "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}" "$@"