You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
diff=$(echo $diff| sed 's/\\/\\\\/g'| sed 's/"/\\"/g'| sed 's/\n/\\n/g')
24
-
25
-
# Prepare the Gemini API request
26
-
gemini_request='{
27
-
"contents":[{"parts":[{"text": "Write a git commit message title (no more than 72 characters total) for the following git diff: '"$diff"' Do not include any other text in the repsonse."}]}],
# Request and parse the commit message from Gemini API
36
-
commit_message=$(curl -s \
37
-
-H 'Content-Type: application/json' \
38
-
-d "$gemini_request" \
39
-
-X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${GEMINI_API_KEY}" \
40
-
| jq -r '.candidates[0].content.parts[0].text'
41
-
)
42
-
43
-
# If the commit message is empty, retry the request
44
-
if [ -z"$commit_message" ];then
45
-
commit_message=$(curl -s \
46
-
-H 'Content-Type: application/json' \
47
-
-d "$gemini_request" \
48
-
-X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${GEMINI_API_KEY}" \
49
-
| jq -r '.candidates[0].content.parts[0].text'
50
-
)
51
-
fi
20
+
# Default model (change if desired)
21
+
MODEL="mistral"
52
22
53
-
#Clean up commit message formatting - remove #, ```,
54
-
commit_message=$(echo $commit_message| sed 's/#//g'| sed 's/```//g'| sed 's/Commit message title://g'| sed 's/Commit message summary://g')
23
+
#Prepare the prompt
24
+
PROMPT=$(printf "You are an expert software engineer.\n\nYour job is to generate a short, commit message from the following git diff.\nNo more than 72 characters total.\nOnly return the commit message. Do not include any other text.\n\nGit diff:\n%s""$diff")
55
25
56
-
#Print the commit message
57
-
echo$commit_message
26
+
#Run the model and capture output
27
+
COMMIT_MSG=$(echo "$PROMPT"| ollama run "$MODEL")
58
28
59
-
# If the Gemini retry request fails, exit
60
-
if [ -z"$commit_message" ];then
61
-
echo"Error: API request for commit message failed. Please try again."
29
+
# If the commit message is empty, exit with an error
30
+
if [ -z"$COMMIT_MSG" ];then
31
+
echo"Error: Commit message is empty. Please check the diff and try again."
62
32
exit 1
63
33
fi
64
34
35
+
# Clean up commit message formatting - remove #, ```, period . at the end of response
36
+
commit_message=$(echo $COMMIT_MSG| sed 's/#//g'| sed 's/```//g'| sed 's/Commit message title://g'| sed 's/Commit message summary://g'| sed 's/\.//g')
37
+
38
+
# Echo the commit message
39
+
echo$commit_message
40
+
41
+
# Set the GIT_SSH_PASSPHRASE environment variables
42
+
export COMMIT_MESSAGE="$commit_message"
43
+
export TICKET="$ticket"
44
+
65
45
# Prepare and execute commit command, remove -S to commit without signing
66
46
if [ -z"$ticket" ];then
67
-
git commit -S -m "$commit_message"
47
+
expect <<'EOF'
48
+
spawn git commit -S -m "$env(COMMIT_MESSAGE)"
49
+
expect "Enter passphrase for \"/Users/wscholl/.ssh/id_ed25519\":"
0 commit comments