An AI-powered pre-commit hook for Node.js projects that analyzes your code changes, suggests improvements, and helps maintain code quality.
- 🔍 AI-powered code analysis using Groq AI
- 🧪 Automatic test generation
- 📊 Web dashboard for visualizing results
- 🔄 Git integration
- ⚙️ Configurable rules and thresholds
- 🛡️ Security vulnerability detection
- Node.js 14 or higher
- npm or yarn
- Git
npm install --save-dev node-ai-precommit-tester
# or
yarn add --dev node-ai-precommit-tester-
Install Husky if you haven't already:
npx husky-init && npm install -
Add the pre-commit hook:
npx husky add .husky/pre-commit "npx node-ai-precommit"
GROQ_API_KEY: Your Groq API key (required for AI features)AI_PRECOMMIT_DEBUG: Set to 'true' for debug output
This tool integrates seamlessly with Jenkins CI/CD pipelines. The pipeline will:
- Run the build process
- Generate AI-powered unit tests for committed files
- Run linting and formatting
- Execute the test suite
-
Environment Variables: Set up the
GROQ_API_KEYenvironment variable in your Jenkins pipeline:environment { GROQ_API_KEY = credentials('groq-api-key-id') // Use Jenkins credentials } -
Pipeline Configuration: The
Jenkinsfileincluded in this repository demonstrates the integration:pipeline { stages { stage('Build') { steps { sh 'npm install' } } stage('Generate AI Tests') { steps { // Automatically generates tests for committed JS/TS files script { /* AI test generation logic */ } } } stage('Lint and Format') { steps { sh 'npm run lint && npm run format' } } stage('Test') { steps { sh 'npm test' } } } } -
Webhook Setup (Optional): Configure Git webhooks to trigger the pipeline on commits.
# Stage your changes
git add .
# Run the pre-commit hook
npx node-ai-precommit
# Or commit as usual (will trigger the hook)
git commit -m "Your commit message"Usage: node-ai-precommit [options]
Options:
-V, --version output the version number
--no-ai Skip AI analysis
--no-tests Skip test generation
--no-dashboard Disable web dashboard
-h, --help display help for commandThe web dashboard provides a visual representation of the analysis results:
- Risk score visualization
- Code quality metrics
- Test coverage
- Security vulnerabilities
- Suggested improvements
Access it at http://localhost:3000 when the pre-commit hook runs.
-
Clone the repository
-
Install dependencies:
npm install
-
Build the project:
npm run build
-
Link for local development:
npm link
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
MIT © [Your Name]