-
Notifications
You must be signed in to change notification settings - Fork 2
Implement Claude commit messages #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| # Rename this file to .env and fill in the values | ||
| CLIENT_ID= | ||
| CLIENT_ID= | ||
| ANTHROPIC_API_KEY= |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| npx --no -- commitlint --edit $1 |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,102 @@ | ||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # .husky/prepare-commit-msg | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Load environment variables from .env file if it exists | ||||||||||||||||||||||||||||||||||||
| if [ -f .env ]; then | ||||||||||||||||||||||||||||||||||||
| export $(grep -v '^#' .env | xargs) | ||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
Comment on lines
+10
to
+16
|
||||||||||||||||||||||||||||||||||||
| # Load environment variables from .env file if it exists | |
| if [ -f .env ]; then | |
| set -a | |
| source .env | |
| set +a | |
| fi | |
| # Environment variables should be managed securely (e.g., with direnv). | |
| # Do NOT source .env files directly in git hooks to avoid leaking secrets. | |
| # See project documentation for recommended environment management. |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a comment explaining why --no-color is used in the git diff command. While it's clear to experienced developers that this prevents ANSI color codes from being included in the API request, documenting this helps with maintainability.
| # Get the staged diff | |
| # Get the staged diff | |
| # Use --no-color to prevent ANSI color codes from being included in the diff output, | |
| # which ensures clean input for API requests and downstream processing. |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The MAX_CHARS value of 8000 is a magic number without explanation. Given that Claude API has specific token limits (and the request sets max_tokens to 512 for the response), it would be helpful to document why 8000 characters was chosen and how it relates to the model's input token limits.
Consider adding a comment:
# Truncate very large diffs to avoid token limits
# Claude models typically support ~200k tokens input; 8000 chars ≈ 2000 tokens
MAX_CHARS=8000| # Truncate very large diffs to avoid token limits | |
| # Truncate very large diffs to avoid token limits | |
| # Claude models typically support ~200k tokens input; 8000 chars ≈ 2000 tokens |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded MAX_CHARS value of 8000 could be made more maintainable by defining it as a configurable constant at the top of the script or documenting why this specific value was chosen. This would make it easier to adjust based on actual token limits and API constraints.
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The diff truncation logic uses bash-specific string length syntax ${#DIFF} which may not work in all POSIX-compliant shells, even though the shebang specifies bash. Additionally, the truncation is done on character count rather than byte count, which could lead to issues with the API's token limit calculation.
While the shebang correctly specifies #!/bin/bash, consider documenting this dependency or using more portable POSIX syntax if cross-shell compatibility is desired. Alternatively, consider truncating based on line count or using a more sophisticated tokenization approach that respects code boundaries.
| MAX_CHARS=8000 | |
| if [ ${#DIFF} -gt $MAX_CHARS ]; then | |
| DIFF="${DIFF:0:$MAX_CHARS}... [truncated]" | |
| # Note: This script requires Bash (see shebang above). To avoid issues with multi-byte characters and API token limits, | |
| # we truncate the diff by byte count using head -c, which is POSIX-compliant and more predictable. | |
| MAX_BYTES=8000 | |
| if [ "$(printf "%s" "$DIFF" | wc -c)" -gt "$MAX_BYTES" ]; then | |
| DIFF="$(printf "%s" "$DIFF" | head -c "$MAX_BYTES")... [truncated]" |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string truncation using bash substring expansion doesn't account for potentially cutting in the middle of a multi-byte UTF-8 character, which could corrupt the diff content sent to the API. While this may work in many cases, consider using a more robust truncation method or at least documenting this limitation.
| # Truncate very large diffs to avoid token limits | |
| MAX_CHARS=8000 | |
| if [ ${#DIFF} -gt $MAX_CHARS ]; then | |
| DIFF="${DIFF:0:$MAX_CHARS}... [truncated]" | |
| # Truncate very large diffs to avoid token limits, ensuring we do not split multi-byte UTF-8 characters. | |
| MAX_CHARS=8000 | |
| if [ $(printf "%s" "$DIFF" | wc -c) -gt $MAX_CHARS ]; then | |
| # Use head -c to truncate by bytes, then iconv -c to remove incomplete UTF-8 sequences. | |
| DIFF="$(printf "%s" "$DIFF" | head -c $MAX_CHARS | iconv -c -f utf-8 -t utf-8)... [truncated]" |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The curl command lacks timeout settings, which could cause the git commit process to hang indefinitely if the API is slow or unresponsive. Consider adding a timeout using the --max-time flag (e.g., --max-time 30) to ensure the hook doesn't block the commit process for too long.
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is redundant because MESSAGE is already checked for emptiness at line 107, and the script exits if MESSAGE is empty. This if statement will always evaluate to true at this point. Consider removing this redundant check or restructuring the logic if there's a case where MESSAGE could become empty between lines 107 and 117.
| if [ -n "$MESSAGE" ]; then | |
| # Write generated message, keep any existing content below | |
| echo "$MESSAGE" > "$COMMIT_MSG_FILE.tmp" | |
| echo "" >> "$COMMIT_MSG_FILE.tmp" | |
| echo "# --- Generated by Claude (Commitizen format) ---" >> "$COMMIT_MSG_FILE.tmp" | |
| echo "# Types: feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert" >> "$COMMIT_MSG_FILE.tmp" | |
| cat "$COMMIT_MSG_FILE" >> "$COMMIT_MSG_FILE.tmp" | |
| mv "$COMMIT_MSG_FILE.tmp" "$COMMIT_MSG_FILE" | |
| fi | |
| # Write generated message, keep any existing content below | |
| echo "$MESSAGE" > "$COMMIT_MSG_FILE.tmp" | |
| echo "" >> "$COMMIT_MSG_FILE.tmp" | |
| echo "# --- Generated by Claude (Commitizen format) ---" >> "$COMMIT_MSG_FILE.tmp" | |
| echo "# Types: feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert" >> "$COMMIT_MSG_FILE.tmp" | |
| cat "$COMMIT_MSG_FILE" >> "$COMMIT_MSG_FILE.tmp" | |
| mv "$COMMIT_MSG_FILE.tmp" "$COMMIT_MSG_FILE" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export default { extends: ['@commitlint/config-conventional'] }; |
Uh oh!
There was an error while loading. Please reload this page.