diff --git a/CHANGELOG.md b/CHANGELOG.md index 948f1c1..1bc1906 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,3 +121,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added transforms for improved results. - Modified `keep-a-changelog.sh` and `prepare-commit-msg.sh` for better results. + +## [1.8.3] - 2024-12-12 + +- Added filtering for `.stl` and `.step` files in `git diff` to avoid 5xx errors in API requests. +- Improved error handling and logging (potential debugging improvements). +- Added `--fail` option to curl requests. +- Added examples of API costs. diff --git a/README.md b/README.md index 8bbd546..6738360 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,8 @@ amount of information shared. - Costs approximately $0.00001 per commit - Large diffs may incur higher costs +![Costs](./images/costs.png) + ## Uninstallation - [`pre-commit uninstall`](https://pre-commit.com/#pre-commit-uninstall) diff --git a/images/costs.png b/images/costs.png new file mode 100644 index 0000000..5f6c894 Binary files /dev/null and b/images/costs.png differ diff --git a/keep-a-changelog.sh b/keep-a-changelog.sh index b2f29b7..884da77 100755 --- a/keep-a-changelog.sh +++ b/keep-a-changelog.sh @@ -132,6 +132,11 @@ EOF esac done +# # Enable debug mode if DEBUG is set to true +# if [ "$DEBUG" = true ]; then +# set -x +# fi + # Debug function debug_log() { if [ "$DEBUG" = true ]; then @@ -160,19 +165,18 @@ if [ -n "$(git diff --cached --name-only -- "${CHANGELOG_FILENAME}")" ]; then fi # Get git changes -CHANGES=$(git diff --cached --ignore-all-space) +CHANGES=$(git diff --cached --ignore-all-space -- ':!*.stl' ':!*.step') CURRENT_CHANGELOG="" if [ -f "${CHANGELOG_FILENAME}" ]; then CURRENT_CHANGELOG=$(cat "${CHANGELOG_FILENAME}") fi -# # Maximum size of changes to send to API (in bytes) -# MAX_CHANGES_SIZE=10000 -# -# if [ "${#CHANGES}" -gt "$MAX_CHANGES_SIZE" ]; then -# CHANGES=$(echo "$CHANGES" | head -c "$MAX_CHANGES_SIZE") -# CHANGES+=$'\n... (truncated due to size)' -# fi +# Maximum size of changes to send to API (in bytes) +MAX_CHANGES_SIZE=10000 +if [ "${#CHANGES}" -gt "$MAX_CHANGES_SIZE" ]; then + CHANGES=$(echo "$CHANGES" | head -c "$MAX_CHANGES_SIZE") + CHANGES+=$'\n... (truncated due to size)' +fi # shellcheck disable=SC2059 USER_PROMPT=$(printf "$USER_PROMPT" "$CHANGES") @@ -244,6 +248,7 @@ debug_log "Request body saved to $REQUEST_BODY_FILE" # Make the API request debug_log "Making API request to OpenRouter" if ! RESPONSE=$(curl -s -X POST "https://openrouter.ai/api/v1/chat/completions" \ + --fail \ -H "Authorization: Bearer ${OPENROUTER_API_KEY}" \ -H "Content-Type: application/json" \ -d @"$REQUEST_BODY_FILE"); then @@ -254,6 +259,10 @@ debug_log "API response received" "$RESPONSE" debug_log "Cleaning up temporary files" rm -v "$REQUEST_BODY_FILE" 2>/dev/null || true +# TODO: Check if the response is valid JSON, if not print the response and exit +# echo "API response:" +# echo $RESPONSE +# echo "API response end" # Check for errors if [[ "$RESPONSE" == *'"error"'* ]]; then error_message=$(echo "$RESPONSE" | jq -r '.error.message // .error // "Unknown error"') diff --git a/prepare-commit-msg.sh b/prepare-commit-msg.sh index 4c75cec..5738ec9 100755 --- a/prepare-commit-msg.sh +++ b/prepare-commit-msg.sh @@ -177,9 +177,9 @@ fi # Get git changes if [ "$OPEN_SOURCE" = true ]; then - CHANGES=$(git diff --cached --ignore-all-space) + CHANGES=$(git diff --cached --ignore-all-space -- ':!*.stl' ':!*.step') else - CHANGES=$(git diff --cached --ignore-all-space --name-status) + CHANGES=$(git diff --cached --ignore-all-space --name-status -- ':!*.stl' ':!*.step') fi