Skip to content

Commit 3de0378

Browse files
committed
chore: update 2 file(s)
1 parent d5eaff5 commit 3de0378

2 files changed

Lines changed: 81 additions & 8 deletions

File tree

Makefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,17 +274,19 @@ codegen-check:
274274
fi
275275

276276
commit: lint test
277-
$(info Generating commit message...)
278-
export COMMIT_MESSAGE="$(shell kiro-cli chat --no-interactive --trust-all-tools "Understand pending local git change and changes to be committed, then infer a commit message. Return this commit message only on a single line." | grep ">" | tail -n 1 | sed 's/\x1b\[[0-9;]*m//g')" && \
279-
git add . && \
280-
git commit -am "$${COMMIT_MESSAGE}" && \
277+
@echo "Generating commit message via Bedrock..."
278+
@git add . && \
279+
COMMIT_MESSAGE=$$(bash scripts/generate_commit_message.sh) && \
280+
echo "Commit message: $$COMMIT_MESSAGE" && \
281+
git commit -m "$$COMMIT_MESSAGE" && \
281282
git push
282283

283284
fastcommit: fastlint
284-
$(info Generating commit message...)
285-
export COMMIT_MESSAGE="$(shell kiro-cli chat --no-interactive --trust-all-tools "Understand pending local git change and changes to be committed, then infer a commit message. Return this commit message only on a single line." | grep ">" | tail -n 1 | sed 's/\x1b\[[0-9;]*m//g')" && \
286-
git add . && \
287-
git commit -am "$${COMMIT_MESSAGE}" && \
285+
@echo "Generating commit message via Bedrock..."
286+
@git add . && \
287+
COMMIT_MESSAGE=$$(bash scripts/generate_commit_message.sh) && \
288+
echo "Commit message: $$COMMIT_MESSAGE" && \
289+
git commit -m "$$COMMIT_MESSAGE" && \
288290
git push
289291

290292
# Build and serve the documentation site locally

scripts/generate_commit_message.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
# Generate a commit message using AWS Bedrock (no kiro-cli dependency)
3+
#
4+
# Usage:
5+
# bash scripts/generate_commit_message.sh
6+
#
7+
# Environment variables:
8+
# COMMIT_MODEL_ID - Bedrock model to use (default: amazon.nova-lite-v1:0)
9+
# Examples:
10+
# amazon.nova-lite-v1:0
11+
# anthropic.claude-3-haiku-20240307-v1:0
12+
# AWS_REGION - AWS region for Bedrock (uses default if not set)
13+
14+
set -euo pipefail
15+
16+
MODEL_ID="${COMMIT_MODEL_ID:-amazon.nova-lite-v1:0}"
17+
18+
# Get the diff - prefer staged changes, fall back to unstaged
19+
DIFF_STAT=$(git diff --cached --stat 2>/dev/null)
20+
DIFF_CONTENT=$(git diff --cached 2>/dev/null)
21+
22+
if [ -z "$DIFF_STAT" ]; then
23+
DIFF_STAT=$(git diff --stat 2>/dev/null)
24+
DIFF_CONTENT=$(git diff 2>/dev/null)
25+
fi
26+
27+
# If still empty, try diff against HEAD
28+
if [ -z "$DIFF_STAT" ]; then
29+
DIFF_STAT=$(git diff HEAD --stat 2>/dev/null || echo "no diff available")
30+
DIFF_CONTENT=$(git diff HEAD 2>/dev/null || echo "")
31+
fi
32+
33+
# Truncate diff content to ~4000 chars to stay within token limits
34+
DIFF_TRUNCATED=$(echo "$DIFF_CONTENT" | head -c 4000)
35+
36+
# Build the prompt
37+
PROMPT="Based on the following git diff, generate a single-line commit message following conventional commit format (e.g., feat:, fix:, docs:, refactor:, chore:, test:).
38+
Return ONLY the commit message on a single line. No quotes, no explanation, no prefix like 'Commit message:'.
39+
40+
Files changed:
41+
${DIFF_STAT}
42+
43+
Diff:
44+
${DIFF_TRUNCATED}"
45+
46+
# Escape the prompt for JSON using jq
47+
ESCAPED_PROMPT=$(echo "$PROMPT" | jq -Rs .)
48+
49+
# Build the messages JSON
50+
MESSAGES="[{\"role\":\"user\",\"content\":[{\"text\":${ESCAPED_PROMPT}}]}]"
51+
52+
# Call Bedrock converse API
53+
COMMIT_MSG=$(aws bedrock-runtime converse \
54+
--model-id "$MODEL_ID" \
55+
--messages "$MESSAGES" \
56+
--inference-config '{"maxTokens":100,"temperature":0.3}' \
57+
--query 'output.message.content[0].text' \
58+
--output text 2>&1) || true
59+
60+
# Fallback if Bedrock call fails or returns empty
61+
if [ -z "$COMMIT_MSG" ] || [ "$COMMIT_MSG" = "None" ] || echo "$COMMIT_MSG" | grep -qi "error"; then
62+
# Generate a basic fallback message from the diff stat
63+
FILE_COUNT=$(echo "$DIFF_STAT" | grep -c "file" || echo "0")
64+
echo "chore: update ${FILE_COUNT} file(s)"
65+
exit 0
66+
fi
67+
68+
# Clean up - remove surrounding quotes if present, trim whitespace
69+
COMMIT_MSG=$(echo "$COMMIT_MSG" | sed 's/^["'"'"']//;s/["'"'"']$//' | xargs)
70+
71+
echo "$COMMIT_MSG"

0 commit comments

Comments
 (0)