Skip to content

Commit 41479e6

Browse files
authored
Merged to main
2 parents 663e72d + c635631 commit 41479e6

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

git-commit-push-script.sh

+24-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ 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"' Do not include any other text in the repsonse."}]}]}'
20+
gemini_request='{
21+
"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."}]}],
22+
"safetySettings": [{"category": "HARM_CATEGORY_DANGEROUS_CONTENT","threshold": "BLOCK_NONE"}],
23+
"generationConfig": {
24+
"temperature": 0.2,
25+
"maxOutputTokens": 50
26+
}
27+
}'
2128

2229
# Get commit message from Gemini API
2330
commit_message=$(curl -s \
@@ -27,6 +34,16 @@ commit_message=$(curl -s \
2734
| jq -r '.candidates[0].content.parts[0].text'
2835
)
2936

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+
3047
# Clean up commit message formatting - remove #, ```,
3148
commit_message=$(echo $commit_message | sed 's/#//g' | sed 's/```//g' | sed 's/Commit message title://g' | sed 's/Commit message summary://g')
3249

@@ -38,7 +55,11 @@ if [ -z "$commit_message" ]; then
3855
fi
3956

4057
# Prepare and execute commit command
41-
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
4263

4364
# Check if the branch exists on the remote
4465
remote_branch=$(git ls-remote --heads origin $base_branch)
@@ -47,7 +68,7 @@ remote_branch=$(git ls-remote --heads origin $base_branch)
4768
pull_push_after_failed_push() {
4869
echo "Push failed. Attempting to pull and push again."
4970
git pull
50-
git push
71+
git push --force
5172
}
5273

5374
# Check if the branch exists on the remote

0 commit comments

Comments
 (0)