Skip to content

Commit 1c3f0f1

Browse files
committed
Testing
1 parent 2a6fbcd commit 1c3f0f1

File tree

1 file changed

+99
-62
lines changed

1 file changed

+99
-62
lines changed

git-commit-push-script.sh

Lines changed: 99 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -23,80 +23,117 @@ diff=$(git diff --cached)
2323
diff=$(echo $diff | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/\n/\\n/g')
2424

2525
# 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."}]}],
28-
"safetySettings": [{"category": "HARM_CATEGORY_DANGEROUS_CONTENT","threshold": "BLOCK_NONE"}],
29-
"generationConfig": {
30-
"temperature": 0.2,
31-
"maxOutputTokens": 50
32-
}
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 response."}]}],
28+
# "safetySettings": [{"category": "HARM_CATEGORY_DANGEROUS_CONTENT","threshold": "BLOCK_NONE"}],
29+
# "generationConfig": {
30+
# "temperature": 0.2,
31+
# "maxOutputTokens": 50
32+
# }
33+
# }'
34+
35+
# Prepare the Ollama Gemma3n API request
36+
gemma_request='{
37+
"model": "gemma3n",
38+
"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."
3339
}'
3440

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
42+
commit_message=$(curl http://localhost:11434/api/generate -d "$gemma_request" -H "Content-Type: application/json" | jq -r '.response')
4243

4344
# If the commit message is empty, retry the request
4445
if [ -z "$commit_message" ]; then
4546
commit_message=$(curl -s \
4647
-H 'Content-Type: application/json' \
47-
-d "$gemini_request" \
48-
-X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${GEMINI_API_KEY}" \
49-
| jq -r '.candidates[0].content.parts[0].text'
48+
-d "$gemma_request" \
49+
-X POST "http://localhost:11434/api/generate" \
50+
| jq -r '.response'
5051
)
5152
fi
5253

53-
# Clean up commit message formatting - remove #, ```,
54-
commit_message=$(echo $commit_message | sed 's/#//g' | sed 's/```//g' | sed 's/Commit message title://g' | sed 's/Commit message summary://g')
55-
56-
# Print the commit message
57-
echo $commit_message
58-
59-
# If the Gemini retry request fails, exit
54+
# If the commit message is still empty, exit with an error
6055
if [ -z "$commit_message" ]; then
61-
echo "Error: API request for commit message failed. Please try again."
56+
echo "Error: Ollama API request for commit message failed. Please try again."
6257
exit 1
6358
fi
6459

65-
# Prepare and execute commit command, remove -S to commit without signing
66-
if [ -z "$ticket" ]; then
67-
git commit -S -m "$commit_message"
68-
else
69-
git commit -S -m "$ticket $commit_message"
70-
fi
60+
# # Request and parse the commit message from Gemini API
61+
# commit_message=$(curl -s \
62+
# -H 'Content-Type: application/json' \
63+
# -d "$gemini_request" \
64+
# -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${GEMINI_API_KEY}" \
65+
# | jq -r '.candidates[0].content.parts[0].text'
66+
# )
7167

72-
# Check if the branch exists on the remote
73-
remote_branch=$(git ls-remote --heads origin $base_branch)
74-
75-
# 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\":"
97+
# send "$env(GIT_SSH_PASSPHRASE)\r"
98+
# expect eof
99+
# EOF
100+
# else
101+
# expect <<'EOF'
102+
# spawn git commit -S -m "$env(TICKET) $env(COMMIT_MESSAGE)"
103+
# expect "Enter passphrase for \"/Users/wscholl/.ssh/id_ed25519\":"
104+
# send "$env(GIT_SSH_PASSPHRASE)\r"
105+
# expect eof
106+
# EOF
107+
# fi
108+
109+
# # Check if the branch exists on the remote
110+
# remote_branch=$(git ls-remote --heads origin $base_branch)
111+
112+
# # Function: pull_push_after_failed_push - If push fails, attempt to pull and push again
113+
# pull_push_after_failed_push() {
114+
# echo "Push failed. Attempting to pull and push again."
115+
# git pull
116+
# git push --force
117+
# }
118+
119+
# # Check if the branch exists on the remote
120+
# if [ -z "$remote_branch" ]; then
121+
# # If the branch does not exist on the remote, create it
122+
# echo "Branch '$base_branch' does not exist on remote. Creating it."
123+
# # Push the local branch to the remote, setting the upstream branch
124+
# git push --set-upstream origin $base_branch
125+
126+
# # Check if the push was successful, if previous command is not a failure,
127+
# # execute the function to handle a failed push
128+
# if [ $? -ne 0 ]; then
129+
# pull_push_after_failed_push
130+
# fi
131+
# else # Branch exists on the remote, push changes to the remote branch
132+
# echo "Branch '$base_branch' exists on remote. Pushing changes."
133+
# git push
134+
135+
# # Check if the push wasn't successful, execute the function to handle a failed push
136+
# if [ $? -ne 0 ]; then
137+
# pull_push_after_failed_push
138+
# fi
139+
# fi

0 commit comments

Comments
 (0)