File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,29 @@ base_branch=$(git rev-parse --abbrev-ref HEAD)
1010# Extract ticket number from current directory
1111ticket=$( echo $base_branch | grep -o -E ' ([A-Za-z]+-[0-9]{3,}|[A-Za-z]+-[0-9]{3,})' )
1212
13- # Prompt for commit message
14- read -p " Enter commit message: " message
15- echo " Commit message: $ticket $message "
13+ echo " Ticket: $ticket "
14+
15+ # Get the git diff
16+ diff=$( git diff --cached)
17+
18+ # Stringify the diff
19+ diff=$( echo $diff | sed ' s/\\/\\\\/g' | sed ' s/"/\\"/g' | sed ' s/\n/\\n/g' )
20+
21+ # Prepare the Gemini API request
22+ gemini_request=' {"contents":[{"parts":[{"text": "Write a git commit message (72 character maximum) for the following git diff: ' " $diff " ' "}]}]}'
23+
24+ # Get commit message from Gemini API
25+ commit_message=$( curl \
26+ -H ' Content-Type: application/json' \
27+ -d " $gemini_request " \
28+ -X POST " https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${GEMINI_API_KEY} " \
29+ | jq -r ' .candidates[0].content.parts[0].text'
30+ )
31+
32+ echo " $commit_message "
1633
1734# Prepare and execute commit command
18- git commit -S -m " $ticket $message "
35+ git commit -S -m " $ticket $commit_message "
1936
2037# Check if the branch exists on the remote
2138remote_branch=$( git ls-remote --heads origin $base_branch )
You can’t perform that action at this time.
0 commit comments