Automated system that monitors Jira tickets with "nutest_cortex" label, uses AI (Cursor Premium) to analyze test failures, fixes issues in the nutest-py3-tests repository, and automatically creates Gerrit code reviews.
- π€ AI-Powered Fix Generation: Uses Cursor Premium to automatically generate test fixes
- π Learning System: Learns from code review feedback and human fixes to improve over time
- π Iterative Fixes: Responds to CR comments with improved fixes
- π Comprehensive Commit Messages: Auto-generates detailed commit messages with fix summaries
- π CR Monitoring: Continuously monitors Gerrit CRs for comments, votes, and updates
- π― Branch Mapping: Automatically maps Jira fixversions to Git branches
The system consists of:
- Jira Webhook Listener - Monitors for tickets with "nutest_cortex" label
- Ticket Parser - Extracts ticket details, logs from description and attachments
- AI Fix Engine - Uses Cursor Premium to analyze failures and generate fixes
- Git Automation - Clones repo, applies fixes, commits, and pushes to Gerrit
- Branch Mapper - Maps Jira fixversion to Git branch using JSON config
- Status Reporter - Updates Jira ticket with progress and CR link
- Gerrit CR Monitor - Monitors CR comments and review votes (+1, +2, -1)
- Feedback Learning System - Learns from comments, reviews, and human fixes
- Iterative Fix Engine - Responds to CR comments with improved fixes
- Python 3.9+
- Git
- Cursor CLI installed (for AI fix generation)
- Docker and Docker Compose (for Jira container, optional)
- Access to:
- Jira instance (or use Docker container)
- Gerrit server
- nutest-py3-tests repository
git clone <repository_url>
cd nutest_cortexpython3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtCopy .env.example to .env and fill in your credentials:
cp .env.example .envEdit .env with your values:
# Optional - will auto-detect if not set
CURSOR_CLI_PATH=/usr/local/bin/cursor
CURSOR_AGENT_PATH=/usr/local/bin/cursor-agent
# Required
GERRIT_USERNAME=your_username
GERRIT_PASSWORD=your_password
JIRA_API_TOKEN=your_jira_token
CURSOR_API_KEY=your_cursor_api_key
# Optional - defaults to /tmp/nutest_cortex
WORKSPACE_DIR=/tmp/nutest_cortex
LEARNING_DB_PATH=data/learning_db.sqliteEdit config/branch_mapping.json to map your fixversions to branches:
{
"1.0.0": "master",
"1.1.0": "release/1.1",
"2.0.0": "release/2.0"
}Edit config/config.yaml with your Jira and Gerrit URLs.
python main.pyThe system will:
- Validate startup requirements (Cursor CLI, Git, etc.)
- Start the webhook server on port 8000
- Begin monitoring for Jira tickets with "nutest_cortex" label
- Start monitoring active Gerrit CRs
If using the Docker Compose setup for Jira:
cd docker
docker-compose up -dThis will start:
- PostgreSQL database for Jira
- Jira Software instance on http://localhost:8080
Configure Jira webhook to point to:
http://your-vm-ip:8000/webhook/jira
Webhook should trigger on:
- Issue created
- Issue updated
- Ticket Detection: System receives webhook when ticket with "nutest_cortex" label is created/updated
- Ticket Parsing: Extracts test logs, error messages, and test file paths
- AI Fix Generation: Uses Cursor Premium to analyze failure and generate fix
- Fix Application: Clones repo, applies fix, generates commit message
- CR Creation: Pushes fix to Gerrit and creates code review
- Monitoring: Continuously monitors CR for comments and votes
- Learning: Stores feedback and learns patterns for future fixes
- Iterative Improvement: Responds to comments with improved fixes
The system learns from:
- CR Comments: Extracts actionable feedback
- Review Votes: Tracks +1, +2, -1 patterns
- Human Patches: Compares AI fixes vs human fixes when someone else fixes the CR
- Jira Comments: Extracts feedback from ticket comments
- CR Outcomes: Tracks which fixes get merged vs abandoned
Learned patterns are stored in SQLite database and used to improve future fixes.
Edit config/branch_mapping.json to map Jira fixversions to Git branches.
In config/config.yaml:
monitoring:
poll_interval: 30 # seconds between polling Gerrit
enable_learning: true
max_iterative_fixes: 3 # max patch sets per CRlearning:
db_path: "data/learning_db.sqlite"
enable_human_patch_learning: true
enable_comment_learning: true
enable_jira_comment_learning: truenutest_cortex/
βββ src/
β βββ __init__.py
β βββ jira_webhook.py # Webhook listener
β βββ ticket_parser.py # Parse ticket details
β βββ ai_fixer.py # AI fix generation
β βββ git_automation.py # Git operations
β βββ branch_mapper.py # Branch mapping
β βββ status_reporter.py # Jira status updates
β βββ gerrit_monitor.py # CR monitoring
β βββ feedback_learner.py # Learning system
β βββ fix_summarizer.py # Commit message generation
β βββ logging_config.py # Logging setup
βββ data/
β βββ learning_db.sqlite # Learning database
βββ config/
β βββ branch_mapping.json # Fixversion mappings
β βββ config.yaml # Configuration
βββ docker/
β βββ docker-compose.yml # Jira setup
βββ requirements.txt
βββ main.py # Entry point
βββ README.md
The system auto-detects Cursor CLI. If not found:
- Install Cursor CLI on your VM
- Set
CURSOR_CLI_PATHandCURSOR_AGENT_PATHin.env
Ensure Gerrit credentials are correct in .env:
GERRIT_USERNAMEGERRIT_PASSWORD
- Check Jira webhook configuration
- Verify webhook URL is accessible from Jira
- Check firewall settings
- Review logs for errors
# Add test files and run
pytest tests/Logs are written to:
- Console (stdout)
logs/nutest_cortex.log(rotating, 10MB max, 5 backups)
Log level can be configured in main.py or via environment variable.
[Your License Here]
[Contributing Guidelines]