Skip to content

Commit c635631

Browse files
committed
JIRA-1234 Fix: Handle empty commit messages from Gemini API
1 parent 6ca9a20 commit c635631

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

git-commit-push-script.sh

+15-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ commit_message=$(curl -s \
3434
| jq -r '.candidates[0].content.parts[0].text'
3535
)
3636

37+
# If the commit message is empty, try again
38+
if [ -z "$commit_message" ]; then
39+
commit_message=$(curl -s \
40+
-H 'Content-Type: application/json' \
41+
-d "$gemini_request" \
42+
-X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${GEMINI_API_KEY}" \
43+
| jq -r '.candidates[0].content.parts[0].text'
44+
)
45+
fi
46+
3747
# Clean up commit message formatting - remove #, ```,
3848
commit_message=$(echo $commit_message | sed 's/#//g' | sed 's/```//g' | sed 's/Commit message title://g' | sed 's/Commit message summary://g')
3949

@@ -45,7 +55,11 @@ if [ -z "$commit_message" ]; then
4555
fi
4656

4757
# Prepare and execute commit command
48-
git commit -S -m "$ticket $commit_message"
58+
if [ -z "$ticket" ]; then
59+
git commit -S -m "$commit_message"
60+
else
61+
git commit -S -m "$ticket $commit_message"
62+
fi
4963

5064
# Check if the branch exists on the remote
5165
remote_branch=$(git ls-remote --heads origin $base_branch)

0 commit comments

Comments
 (0)