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
Copy file name to clipboardExpand all lines: git-commit-push-script.sh
+11-4
Original file line number
Diff line number
Diff line change
@@ -17,19 +17,26 @@ diff=$(git diff --cached)
17
17
diff=$(echo $diff| sed 's/\\/\\\\/g'| sed 's/"/\\"/g'| sed 's/\n/\\n/g')
18
18
19
19
# 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."}]}]}'
21
21
22
22
# Get commit message from Gemini API
23
23
commit_message=$(curl -s \
24
24
-H 'Content-Type: application/json' \
25
25
-d "$gemini_request" \
26
26
-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
+
)
29
29
30
-
# Clean up commit message formatting - remove #, ```
30
+
# Clean up commit message formatting - remove #, ```,
31
31
commit_message=$(echo $commit_message| sed 's/#//g'| sed 's/```//g'| sed 's/Commit message title://g'| sed 's/Commit message summary://g')
32
32
33
+
echo$commit_message
34
+
35
+
if [ -z"$commit_message" ];then
36
+
echo"Error: API request for commit message failed. Please try again."
0 commit comments