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
+99-62Lines changed: 99 additions & 62 deletions
Original file line number
Diff line number
Diff line change
@@ -23,80 +23,117 @@ diff=$(git diff --cached)
23
23
diff=$(echo $diff| sed 's/\\/\\\\/g'| sed 's/"/\\"/g'| sed 's/\n/\\n/g')
24
24
25
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."}]}],
# "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 response."}]}],
"prompt": "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 response."
33
39
}'
34
40
35
-
# 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
-
)
41
+
# Request a commit message from Ollama Gemma3n local API
# Function: pull_push_after_failed_push - If push fails, attempt to pull and push again
76
-
pull_push_after_failed_push() {
77
-
echo"Push failed. Attempting to pull and push again."
78
-
git pull
79
-
git push --force
80
-
}
81
-
82
-
# Check if the branch exists on the remote
83
-
if [ -z"$remote_branch" ];then
84
-
# If the branch does not exist on the remote, create it
85
-
echo"Branch '$base_branch' does not exist on remote. Creating it."
86
-
# Push the local branch to the remote, setting the upstream branch
87
-
git push --set-upstream origin $base_branch
88
-
89
-
# Check if the push was successful, if previous command is not a failure,
90
-
# execute the function to handle a failed push
91
-
if [ $?-ne 0 ];then
92
-
pull_push_after_failed_push
93
-
fi
94
-
else# Branch exists on the remote, push changes to the remote branch
95
-
echo"Branch '$base_branch' exists on remote. Pushing changes."
96
-
git push
97
-
98
-
# Check if the push wasn't successful, execute the function to handle a failed push
99
-
if [ $?-ne 0 ];then
100
-
pull_push_after_failed_push
101
-
fi
102
-
fi
68
+
# If the commit message is empty, retry the request
69
+
# if [ -z "$commit_message" ]; then
70
+
# commit_message=$(curl -s \
71
+
# -H 'Content-Type: application/json' \
72
+
# -d "$gemini_request" \
73
+
# -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${GEMINI_API_KEY}" \
74
+
# | jq -r '.candidates[0].content.parts[0].text'
75
+
# )
76
+
# fi
77
+
78
+
# Clean up commit message formatting - remove #, ```, period . at the end of response
79
+
commit_message=$(echo $commit_message| sed 's/#//g'| sed 's/```//g'| sed 's/Commit message title://g'| sed 's/Commit message summary://g'| sed 's/\.//g')
80
+
81
+
# Print the commit message
82
+
echo$commit_message
83
+
84
+
# # If the Gemini retry request fails, exit
85
+
# if [ -z "$commit_message" ]; then
86
+
# echo "Error: API request for commit message failed. Please try again."
87
+
# exit 1
88
+
# fi
89
+
90
+
# export COMMIT_MESSAGE="$commit_message"
91
+
# export TICKET="$ticket"
92
+
# # Prepare and execute commit command, remove -S to commit without signing
93
+
# if [ -z "$ticket" ]; then
94
+
# expect <<'EOF'
95
+
# spawn git commit -S -m "$env(COMMIT_MESSAGE)"
96
+
# expect "Enter passphrase for \"/Users/wscholl/.ssh/id_ed25519\":"
0 commit comments