Skip to content

Commit 663e72d

Browse files
committedSep 24, 2024··
Fix: Improve commit message generation accuracy
1 parent 8e91b5d commit 663e72d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed
 

‎git-commit-push-script.sh

+11-4
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,26 @@ diff=$(git diff --cached)
1717
diff=$(echo $diff | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/\n/\\n/g')
1818

1919
# Prepare the Gemini API request
20-
gemini_request='{"contents":[{"parts":[{"text": "Write a git commit message title (no more than 72 characters total) for the following git diff: '"$diff"' "}]}]}'
20+
gemini_request='{"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."}]}]}'
2121

2222
# Get commit message from Gemini API
2323
commit_message=$(curl -s \
2424
-H 'Content-Type: application/json' \
2525
-d "$gemini_request" \
2626
-X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${GEMINI_API_KEY}" \
27-
| jq -r '.candidates[0].content.parts[0].text'
28-
)
27+
| jq -r '.candidates[0].content.parts[0].text'
28+
)
2929

30-
# Clean up commit message formatting - remove #, ```
30+
# Clean up commit message formatting - remove #, ```,
3131
commit_message=$(echo $commit_message | sed 's/#//g' | sed 's/```//g' | sed 's/Commit message title://g' | sed 's/Commit message summary://g')
3232

33+
echo $commit_message
34+
35+
if [ -z "$commit_message" ]; then
36+
echo "Error: API request for commit message failed. Please try again."
37+
exit 1
38+
fi
39+
3340
# Prepare and execute commit command
3441
git commit -S -m "$ticket $commit_message"
3542

0 commit comments

Comments
 (0)
Please sign in to comment.