Skip to content

Commit

Permalink
fix: resolve argument list too long error in prepare-commit-msg.sh
Browse files Browse the repository at this point in the history
Fixes an argument list too long error in prepare-commit-msg.sh when making API calls.  The issue was due to passing the entire request body as a single argument to `curl`.  This commit now uses a temporary file to hold the request body, mitigating the error.

*   Replaced direct inclusion of the request body with a temporary file.
*   Added logging for cleanup of temporary files.
  • Loading branch information
alexanderilyin committed Dec 3, 2024
1 parent f83547c commit a9bb7fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- jq: Argument list too long #3
- Cleaned up temporary files after API call.

## [1.7.1] - 2024-12-02

### Fixed

- prepare-commit-msg.sh: line 237: /usr/bin/curl: Argument list too long
10 changes: 8 additions & 2 deletions prepare-commit-msg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,22 @@ REQUEST_BODY=$(jq -n \
}'
)
debug_log "Request body prepared with model: $MODEL" "$REQUEST_BODY"
debug_log "Cleaning up temporary files"
rm -v "$PROMPT_FILE" "$SYSTEM_PROMPT_FILE"

REQUEST_BODY_FILE=$(mktemp)
echo "$REQUEST_BODY" > "$REQUEST_BODY_FILE"
debug_log "Request body saved to $REQUEST_BODY_FILE"

# Make the API request
debug_log "Making API request to OpenRouter"
RESPONSE=$(curl -s -X POST "https://openrouter.ai/api/v1/chat/completions" \
-H "Authorization: Bearer ${OPENROUTER_API_KEY}" \
-H "Content-Type: application/json" \
-d "$REQUEST_BODY")
-d @"$REQUEST_BODY_FILE")
debug_log "API response received" "$RESPONSE"
debug_log "Cleaning up temporary files"
rm -v "$PROMPT_FILE" "$SYSTEM_PROMPT_FILE"
rm -v "$REQUEST_BODY_FILE"

# Check for errors
if [[ "$RESPONSE" == *'"error"'* ]]; then
Expand Down

0 comments on commit a9bb7fc

Please sign in to comment.