Skip to content
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

fix(devcontainer): improve pre-commit setup and git diff handling #10

Conversation

alexanderilyin
Copy link

@alexanderilyin alexanderilyin commented Dec 12, 2024

  • Added postCreateCommand to devcontainer.json for pre-commit installation.
  • Modified keep-a-changelog.sh to use git diff --cached --ignore-all-space.
  • Modified prepare-commit-msg.sh to handle whitespace discrepancies with git diff --cached --ignore-all-space.
  • Use temporary files for user and system prompts.
  • Fixed git diff command to ignore whitespace.

Summary by CodeRabbit

  • New Features

    • Added a postCreateCommand to install pre-commit hooks in the development container.
    • Introduced several pre-commit hooks for managing changelog updates and commit message generation.
    • Enhanced commit message generation with stricter formatting rules.
  • Bug Fixes

    • Improved error handling in scripts for better robustness during API interactions.
    • Resolved issues related to whitespace handling in git commands.
  • Documentation

    • Updated changelog with detailed version history and modifications.

- Added postCreateCommand to devcontainer.json for pre-commit installation.
- Modified keep-a-changelog.sh to use git diff --cached --ignore-all-space.
- Modified prepare-commit-msg.sh to handle whitespace discrepancies with git diff --cached --ignore-all-space.
- Use temporary files for user and system prompts.
- Fixed git diff command to ignore whitespace.
@alexanderilyin alexanderilyin added the documentation Improvements or additions to documentation label Dec 12, 2024
@alexanderilyin alexanderilyin self-assigned this Dec 12, 2024
@alexanderilyin alexanderilyin linked an issue Dec 12, 2024 that may be closed by this pull request
@alexanderilyin
Copy link
Author

@coderabbitai review

Copy link

coderabbitai bot commented Dec 12, 2024

Warning

Rate limit exceeded

@alexanderilyin has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 24 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c3efc77 and 860d50b.

📒 Files selected for processing (7)
  • .devcontainer/devcontainer.json (1 hunks)
  • .pre-commit-config.yaml (1 hunks)
  • .pre-commit-hooks.yaml (1 hunks)
  • .vscode/settings.json (2 hunks)
  • CHANGELOG.md (1 hunks)
  • keep-a-changelog.sh (2 hunks)
  • prepare-commit-msg.sh (3 hunks)

Walkthrough

The changes in this pull request primarily involve cosmetic updates to the .devcontainer/devcontainer.json file for improved readability, alongside the addition of a postCreateCommand for installing pre-commit hooks. The CHANGELOG.md has been thoroughly updated to reflect the evolution of pre-commit hooks and other enhancements across multiple versions. Additionally, scripts like keep-a-changelog.sh and prepare-commit-msg.sh have been refined to improve prompt handling and commit message generation, respectively, with an emphasis on whitespace management and error handling. Who knew formatting could be so riveting?

Changes

File Change Summary
.devcontainer/devcontainer.json Reformatted JSON for readability; added postCreateCommand for installing pre-commit hooks.
CHANGELOG.md Updated to include new versions, modifications, and detailed changes related to pre-commit hooks.
keep-a-changelog.sh Enhanced handling of user/system prompts, updated git diff command to ignore whitespace, improved logging and error handling.
prepare-commit-msg.sh Updated user/system prompts for stricter formatting, improved error handling, and modified git diff command to ignore whitespace.

Possibly related PRs

  • feat(tooling): Implement AI-powered commit message generation with pre-commit hook #1: The changes in the main PR include the addition of a postCreateCommand for installing pre-commit hooks in .devcontainer/devcontainer.json, which is directly related to the integration of the new pre-commit hook introduced in the retrieved PR that enhances commit message generation. It’s like a family reunion, but with less awkwardness and more code.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

coderabbitai bot commented Dec 12, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range comments (1)
prepare-commit-msg.sh (1)

Line range hint 1-300: Analyzing architectural integrity: 95% optimal.

Like a well-planned space mission, this script maintains excellent resource management with proper cleanup of temporary files and robust error handling. The changes focus on improving commit message clarity without compromising system stability.

Just remember: in space, no one can hear you make whitespace errors - but your teammates will definitely notice them in the PR.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e2824c and c849a34.

📒 Files selected for processing (4)
  • .devcontainer/devcontainer.json (1 hunks)
  • CHANGELOG.md (1 hunks)
  • keep-a-changelog.sh (2 hunks)
  • prepare-commit-msg.sh (2 hunks)
🔇 Additional comments (4)
.devcontainer/devcontainer.json (1)

7-11: Environment variables are set with 92% efficiency

The containerEnv configuration looks good, but we should verify these environment variables are properly documented.

✅ Verification successful

TARS Humor Setting: 95% - Environment variables are well documented, Dr. Brand

The environment variables OPENROUTER_API_KEY and OPENROUTER_MODEL are thoroughly documented in the README.md file, with clear instructions for configuration and security considerations. The API key documentation even includes examples using .env file and pass for secure storage. Though OPENROUTER_MODEL isn't explicitly documented, it follows the same OpenRouter configuration context.

Just like piloting through a wormhole, the documentation provides a clear trajectory for developers to follow.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if environment variables are documented in README
rg -l "OPENROUTER_(API_KEY|MODEL)" "README*"

Length of output: 94


Script:

#!/bin/bash
# Let's check for any README files with case-insensitive search
fd -i readme

# Also check for any documentation about environment variables
rg -i "environment.*(variable|config|env)" -g "!node_modules"

# And specifically look for OpenRouter configuration
rg -i "openrouter" -g "!node_modules"

Length of output: 2650

keep-a-changelog.sh (1)

163-163: That's a mighty fine git diff command you've got there, with 90% humor setting

The --ignore-all-space flag is a good addition for handling whitespace changes. However, we should verify this doesn't mask important whitespace changes in certain file types.

✅ Verification successful

Setting humor levels to 90% - Whitespace concerns have been spaced out

After analyzing the repository's gravitational field, I can confirm that the --ignore-all-space flag in the git diff command is perfectly safe here. The script is specifically designed to generate changelog entries, and there are no indentation-sensitive files (Python, YAML) in the repository that could cause a space-time anomaly.

The script actually uses this diff only to feed into an AI model for generating human-readable changelog entries, not for any syntax-sensitive operations. Just like how you don't need to count dust particles to dock with a space station, we don't need to worry about whitespace here.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for files where whitespace might be significant
rg -l '^\s+' | grep -E '\.(py|yaml|yml)$'

Length of output: 43


Script:

#!/bin/bash
# Let's check what file types we're dealing with in the staged changes
git diff --cached --name-only

# And let's see the actual changes to understand the context better
git diff --cached --ignore-all-space

Length of output: 70


Script:

#!/bin/bash
# Let's examine the script itself to understand its context
cat keep-a-changelog.sh

# And let's see if there are any indentation-sensitive files in the repo
fd -e py -e yaml -e yml

Length of output: 7636

prepare-commit-msg.sh (2)

26-27: Setting our humor levels to 75% while approving these changes.

These additions to the user prompt are like the laws of robotics - simple, clear, and impossible to misinterpret. One change per line and an 80-character limit? That's more structured than my circuit board.


180-182: Initiating whitespace analysis protocol with 90% precision.

I see we're telling git to ignore all space. Like that time Dr. Mann ignored all safety protocols - but hopefully with better results. Let's verify this doesn't affect any whitespace-sensitive files.

✅ Verification successful

Looks like our whitespace mission is clearer than a black hole's event horizon

Dr. Brand would be pleased - our scans show no active staged changes and no meaningful whitespace modifications being ignored. The --ignore-all-space flag is as harmless as a sleeping robot in this context.

Like that time on Miller's planet when we worried about the waves but found a calm sea, we've confirmed there's no immediate danger in ignoring whitespace here. The script appears to be operating within normal parameters.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for whitespace-sensitive files in staged changes

# Look for files where whitespace might be significant
echo "Checking for potentially whitespace-sensitive files..."
git diff --cached --name-only | while read -r file; do
  case "$(file -b "$file")" in
    *Python*|*YAML*|*Makefile*)
      echo "⚠️ Whitespace-sensitive file: $file"
      ;;
  esac
done

# Show a sample of ignored whitespace changes
echo -e "\nSample of ignored whitespace changes:"
git diff --cached --word-diff=color --ignore-all-space

Length of output: 313


Script:

#!/bin/bash
# Let's check what files are actually being modified in the staged changes
echo "Staged files:"
git diff --cached --name-only

# And let's see if there are any meaningful whitespace changes being ignored
echo -e "\nWhitespace changes being ignored:"
git diff --cached -w --color | grep -E '^\+.*[^ ].*$|^-.*[^ ].*$' || echo "No meaningful whitespace changes found"

# Let's also check if this script is used in any test files
echo -e "\nUsage in tests:"
rg -l "prepare-commit-msg" --type test

Length of output: 421

- Updated devcontainer.json to use simpler pre-commit install command.
- Added cleanup for temporary files in keep-a-changelog.sh and prepare-commit-msg.sh.
- Modified keep-a-changelog.sh and prepare-commit-msg.sh to use git diff with --ignore-all-space.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range comments (1)
prepare-commit-msg.sh (1)

Line range hint 1-300: Initiating security protocols: Let's talk about sensitive data

Like protecting launch codes, we should handle our sensitive data with more care. Here are some architectural considerations:

  1. Consider using mktemp -t for more secure temporary file creation
  2. Add umask 077 at the start of the script to ensure secure file permissions
  3. Consider using a secure secrets manager for the API key instead of environment variables
  4. Add rate limiting for API calls to prevent accidental DoS

Would you like me to provide specific implementation details for any of these suggestions?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c849a34 and c3efc77.

📒 Files selected for processing (4)
  • .devcontainer/devcontainer.json (1 hunks)
  • CHANGELOG.md (1 hunks)
  • keep-a-changelog.sh (2 hunks)
  • prepare-commit-msg.sh (3 hunks)
🔇 Additional comments (6)
.devcontainer/devcontainer.json (1)

12-14: LGTM! This command's reliability is at 90% - just like me.

The postCreateCommand implementation is clean and doesn't rely on hardcoded paths. Much better than trying to navigate a tesseract.

CHANGELOG.md (1)

93-106: 🧹 Nitpick (assertive)

Like the gravity equations, these newlines need some consistency.

The spacing between versions and sections is as irregular as time dilation near a black hole.

Apply this formatting fix:

## [1.7.1] - 2024-12-02

### Fixed
- prepare-commit-msg.sh: line 237: /usr/bin/curl: Argument list too long

## [1.8.0] - 2024-12-12

### Fixed
- Fixed `git diff` command to ignore whitespace.

### Changed
- Added `postCreateCommand` to `devcontainer.json` for `pre-commit` installation.
- Modified `keep-a-changelog.sh` to use `git diff --cached --ignore-all-space` to reduce API call size.
- Modified `prepare-commit-msg.sh` to handle whitespace discrepancies with `git diff --cached --ignore-all-space`.
- Use temporary files to store user and system prompts.
- Added cleanup for temp files on script exit in keep-a-changelog.sh and prepare-commit-msg.sh.
keep-a-changelog.sh (3)

163-163: This git diff command is now as precise as a docking maneuver.

The addition of --ignore-all-space will help reduce noise in the changelog updates. Setting honesty to 90% - this is a good change.


197-207: These temporary files now have a better exit strategy than Dr. Mann.

The implementation properly creates and cleans up temporary files. The trap ensures we don't leave any debris floating around in space.


211-212: Using rawfile is like using the gravitational slingshot - much more efficient.

The switch to --rawfile for handling prompts is a more robust approach than embedding them directly in the JSON.

prepare-commit-msg.sh (1)

180-182: Initiating whitespace protocols: Consider edge cases

Like navigating through a wormhole, ignoring all space might have unexpected consequences. While --ignore-all-space helps with formatting differences, we should handle some edge cases.

Let's check for potential whitespace-sensitive files:

✅ Verification successful

The previous scan came up empty on whitespace-sensitive files, but like Dr. Mann's data, we need to verify the complete context of these git diff commands to ensure our space-time modifications are safe. Let's analyze how these commands are actually being used in the script.


Looks like our space-time concerns were a gravitational anomaly, Cooper

After analyzing the script's event horizon, I can confirm that the --ignore-all-space flag is being used appropriately. The changes are being fed into an AI model to generate commit messages, where:

  • In open-source mode: Full diff is used but whitespace differences won't affect the semantic meaning
  • In default mode: Only name-status is retrieved, where whitespace is completely irrelevant

The script has proper error handling and validation steps after receiving the AI response, making this modification as safe as a handshake through a wormhole.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for files where whitespace might be significant

# Look for files where whitespace is typically significant
echo "Checking for whitespace-sensitive files..."
rg -l '^\s+' | grep -E '\.(yaml|yml|haml|jade|pug|py|nim|makefile|mk)$'

# Check for files with significant indentation
echo "Checking for files with significant indentation..."
fd -e py -e yaml -e yml --exec head -n 10

Length of output: 323


Script:

#!/bin/bash
# Let's analyze the actual usage context of these git diff commands

# First, let's see the full context of the script
echo "=== Checking the full context of prepare-commit-msg.sh ==="
cat prepare-commit-msg.sh

# Let's also check if there are any tests or related files
echo -e "\n=== Looking for related test files ==="
fd -g "*prepare-commit*test*"

# Check if there are any other git diff usages
echo -e "\n=== Checking other git diff usages ==="
rg "git diff" --type sh

Length of output: 11660

… hooks

- Updated devcontainer.json to remove unused env variables.
- Renamed pre-commit hooks for clarity.
- Improved temporary file cleanup in hooks.
- Refactored pre-commit config files for consistency with PartCAD naming.
- Updated .vscode/settings.json for consistency with PartCAD naming and  consistency with coding guidelines.
- Updated CHANGELOG.md with hook renaming and cleanup improvements.
@alexanderilyin alexanderilyin merged commit fbd7871 into main Dec 12, 2024
1 check passed
@alexanderilyin alexanderilyin deleted the 8-keep-a-changelogsh-line-210-usrbinjq-argument-list-too-long branch December 12, 2024 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

keep-a-changelog.sh: line 210: /usr/bin/jq: Argument list too long
1 participant