Skip to main content

AI-powered GitHub PR analysis, risk prediction, and automated release notes generation

Project description

PRCodeSnip ๐Ÿš€

PyPI version Python Support License: MIT

AI-powered GitHub PR analysis, risk prediction, and automated release notes generation. Make smarter merge decisions with intelligent pre-merge analysis.

โœจ Features

  • ๐ŸŽฏ Smart Risk Prediction: AI-powered analysis to predict PR risks before merge
  • ๐Ÿ“ Automated Release Notes: Generate professional release notes from PR changes
  • ๐Ÿ” Code Quality Analysis: Comprehensive pre-merge code quality checks
  • ๐ŸŒ Multi-language Support: Interface available in 25+ languages
  • ๐Ÿค– GitHub Integration: Post comments, create status checks, and workflow automation
  • โšก Lightning Fast: Async processing with parallel analysis
  • ๐Ÿ›ก๏ธ Security First: Built-in security scanning and vulnerability detection

๐Ÿš€ Quick Start

Installation

# Install from PyPI
pip install prcodesnip

# Or install in development mode
pip install -e .

First-time Setup (Interactive)

prcodesnip setup

This will guide you through:

  • Setting up GitHub token
  • Configuring OpenAI API key (optional)
  • Setting default repository
  • Choosing language preferences

Basic Usage

# Quick risk analysis
prcodesnip predict-risk --pr 123 --repo owner/repo

# Generate release notes
prcodesnip draft-release --pr 123 --repo owner/repo

# Complete pre-merge analysis
prcodesnip premerge-analyze --pr 123 --post-comment

๐Ÿ“‹ Complete Command Reference

๐Ÿ”ง Setup and Configuration

prcodesnip setup

Interactive setup wizard for first-time users.

prcodesnip setup

What it does:

  • Guides you through GitHub token setup
  • Configures OpenAI API key for AI features
  • Sets default repository and preferences
  • Creates configuration file

prcodesnip config

Manage configuration settings.

# Show current configuration
prcodesnip config --show

# Test your configuration
prcodesnip config --test

# Create sample config file
prcodesnip config --create

# Reset configuration (run setup again)
prcodesnip config --reset

Options:

  • --show: Display current configuration with masked tokens
  • --test: Test GitHub and OpenAI API connections
  • --create: Create a sample configuration file
  • --reset: Reset configuration and run interactive setup

๐ŸŽฏ Risk Analysis Commands

prcodesnip predict-risk

Analyze and predict risks for a PR before merging.

prcodesnip predict-risk --pr 123 --repo owner/repo [OPTIONS]

Required Options:

  • --pr INTEGER: Pull Request number to analyze
  • --repo TEXT: GitHub repository in format owner/repo

Optional Options:

  • --token TEXT: GitHub token (or set GITHUB_TOKEN env var)
  • --detailed: Show detailed risk breakdown by category
  • --debug: Enable debug logging

Example Output:

โœ… Risk Prediction Results
========================================
Overall Risk: โš ๏ธ Moderate (0.65/1.0)
Confidence: 0.85

๐Ÿ“Š Detailed Risk Breakdown:
  ๐Ÿ› Bug Probability: 0.30
  ๐Ÿ”’ Security Risk: 0.15
  โšก Performance Risk: 0.80
  ๐Ÿงฉ Complexity Risk: 0.45

๐Ÿ’ก Recommendations:
  1. Review performance impact of database changes
  2. Add unit tests for new authentication logic
  3. Consider breaking change into smaller PRs

๐Ÿ“ Release Notes Commands

prcodesnip draft-release

Generate draft release notes from PR changes.

prcodesnip draft-release --pr 123 --repo owner/repo [OPTIONS]

Required Options:

  • --pr INTEGER: Pull Request number (or will prompt interactively)

Optional Options:

  • --repo TEXT: GitHub repository (uses default from config if not provided)
  • --token TEXT: GitHub token (or set GITHUB_TOKEN env var)
  • --format [markdown|json|text]: Output format (default: markdown)
  • --output TEXT: Output file path (default: stdout)

Format Examples:

Markdown (default):

## Draft Release Notes
*Generated from PR #123: Add user authentication system*

### โœจ New Features
- Add JWT-based user authentication
- Implement password reset functionality

### ๐Ÿ› Bug Fixes
- Fixed login form validation errors

### ๐Ÿ“ฆ Dependencies
- Updated security packages to latest versions

JSON:

{
  "version": "minor",
  "pr_number": 123,
  "title": "Add user authentication system",
  "generated_at": "2025-08-09T12:00:00.000000",
  "changes": {
    "features": ["Add JWT-based user authentication"],
    "bug_fixes": ["Fixed login form validation errors"]
  },
  "confidence_score": 0.85
}

Text:

Version: minor
Confidence: 0.85

## Draft Release Notes
*Generated from PR #123: Add user authentication system*

### New Features
- Add JWT-based user authentication
- Implement password reset functionality

๐Ÿš€ Complete Analysis Commands

prcodesnip premerge-analyze

Complete pre-merge analysis with risk prediction and release notes.

prcodesnip premerge-analyze --pr 123 [OPTIONS]

Optional Options:

  • --pr INTEGER: Pull Request number (will prompt if not provided)
  • --repo TEXT: GitHub repository (uses default from config)
  • --token TEXT: GitHub token (or set GITHUB_TOKEN env var)
  • --commit-sha TEXT: Commit SHA for GitHub status checks
  • --post-comment: Post analysis results as PR comment
  • --create-status: Create GitHub status check
  • --output TEXT: Output file for analysis results (default: premerge-analysis.json)

Example Usage:

# Basic analysis
prcodesnip premerge-analyze --pr 123

# With GitHub integration
prcodesnip premerge-analyze --pr 123 --post-comment --create-status --commit-sha abc123def

# Save to custom file
prcodesnip premerge-analyze --pr 123 --output my-analysis.json

Output Structure:

{
  "timestamp": "2025-08-09T12:00:00.000000",
  "pr_data": {
    "number": 123,
    "title": "Add new feature",
    "repository": "owner/repo"
  },
  "risk_analysis": {
    "risk_assessment": {
      "overall_score": 0.25,
      "risk_level": "low",
      "confidence": 0.90
    },
    "detailed_risks": {
      "bug_probability": 0.10,
      "security_risk": 0.05,
      "performance_risk": 0.30,
      "complexity_risk": 0.15
    },
    "recommendations": [
      "Add unit tests for new functionality",
      "Review performance impact"
    ]
  },
  "draft_release_notes": {
    "version": "minor",
    "release_notes": "## Draft Release Notes...",
    "confidence_score": 0.85
  }
}

prprcodesnip analyze-fast

Fast async analysis with parallel processing.

prprcodesnip analyze-fast --pr 123 --repo owner/repo [OPTIONS]

Options: Same as analyze command but optimized for speed.

Features:

  • Parallel processing of analysis tasks
  • Reduced memory usage
  • Faster API calls
  • Suitable for CI/CD pipelines

๐Ÿค– GitHub Integration Commands

prprcodesnip setup-workflow

Setup CI/CD workflow integration.

prprcodesnip setup-workflow [OPTIONS]

Options:

  • --provider [github-actions|gitlab-ci|jenkins]: CI/CD provider (default: github-actions)
  • --output-dir TEXT: Directory for workflow files (default: .github/workflows)

Generated GitHub Actions Workflow:

  • Triggers on PR open/update
  • Runs complete pre-merge analysis
  • Posts results as PR comments
  • Creates GitHub status checks
  • Uploads analysis artifacts

Setup Instructions After Generation:

  1. Add OPENAI_API_KEY to repository secrets
  2. Ensure GITHUB_TOKEN has write permissions
  3. Commit and push the workflow file
  4. Create a test PR to see it in action

๐ŸŒ Multi-language Commands

prcodesnip language

Multi-language support commands for programming language detection and interface languages.

# Detect programming languages in repository
prcodesnip language detect-languages --repo owner/repo

# Setup development environment for programming language
prcodesnip language setup-environment python

# Set CLI interface language
prcodesnip language set-language es

# List available interface languages
prcodesnip language list-languages

# Show current locale information
prcodesnip language show-locale-info

๐Ÿ–ฅ๏ธ CLI Interface Languages (25+ supported):

  • European: English, Spanish, French, German, Italian, Dutch, Portuguese, Russian, Polish, Czech
  • Asian: Japanese, Korean, Chinese, Hindi, Thai, Vietnamese, Indonesian, Malay
  • Middle Eastern: Arabic, Hebrew, Turkish
  • Nordic: Swedish, Norwegian, Danish, Finnish
  • Other: Romanian, Hungarian, Filipino

๐Ÿ’ป Programming Languages Supported (60+ languages):

Mainstream Languages:

  • Python, JavaScript, TypeScript, Go, Java, C#, Rust, C++, C
  • PHP, Ruby, Swift, Kotlin, Scala

Functional Languages:

  • Haskell, OCaml, Erlang, Elixir, F#, Clojure

JVM Languages:

  • Java, Kotlin, Scala, Groovy, Clojure

Systems Programming:

  • Rust, C, C++, Assembly, Zig

Web Technologies:

  • HTML, CSS, JavaScript, TypeScript

Mobile Development:

  • Swift (iOS), Kotlin (Android), Dart (Flutter), Objective-C

Scientific Computing:

  • Python, R, MATLAB, Julia

Scripting Languages:

  • Python, JavaScript, Bash, PowerShell, Perl, Lua, Fish

Emerging Languages:

  • Crystal, Nim, V, Zig

Blockchain:

  • Solidity, Vyper

Game Development:

  • GDScript (Godot), ActionScript

Hardware Description:

  • Verilog, VHDL, SystemVerilog

Configuration & Markup:

  • YAML, TOML, JSON, XML, Markdown

Infrastructure:

  • Dockerfile, Terraform, Makefile

And many more! See the complete list in the language detector.


๐Ÿ” Data and Analysis Commands

prcodesnip analyze

Legacy full analysis command (use premerge-analyze for new projects).

prcodesnip analyze --pr 123 --repo owner/repo [OPTIONS]

Options:

  • --pr INTEGER: Pull Request number (required)
  • --repo TEXT: GitHub repository
  • --token TEXT: GitHub token
  • --openai-key TEXT: OpenAI API key
  • --output TEXT: Output file (default: release-notes.md)

prcodesnip fetch

Fetch raw PR data from GitHub (useful for debugging).

prcodesnip fetch --pr 123 --repo owner/repo [OPTIONS]

Options:

  • --pr INTEGER: Pull Request number (required)
  • --repo TEXT: GitHub repository
  • --token TEXT: GitHub token

Output: Raw JSON data with PR title, body, diff, and metadata.


๐Ÿ“š Help and Information Commands

prcodesnip quickstart

Show quick start guide for new users.

prcodesnip quickstart

Displays:

  • First-time setup instructions
  • Basic usage examples
  • Configuration tips
  • GitHub integration guide

๐Ÿ”ง Configuration Options

Environment Variables

# Required for GitHub integration
export GITHUB_TOKEN="ghp_your_token_here"

# Optional for AI-powered release notes
export OPENAI_API_KEY="sk-your_key_here"

# Optional language setting
export PRCODESNIP_LANGUAGE="es"

Configuration File

PRCodeSnip looks for configuration in these locations (in order):

  1. ./.prcodesnip.json (current directory)
  2. ~/.prcodesnip/config.json (user home)
  3. Environment variables

Sample Configuration:

{
  "github": {
    "token": "env:GITHUB_TOKEN",
    "default_repo": "owner/repo"
  },
  "openai": {
    "api_key": "env:OPENAI_API_KEY",
    "model": "gpt-4o-mini"
  },
  "quality": {
    "tools": ["pytest", "pylint", "bandit", "coverage"],
    "timeout": 300
  },
  "output": {
    "default_format": "markdown",
    "default_file": "release-notes.md"
  },
  "language": "en"
}

๐Ÿ“– Usage Examples

๐ŸŽฏ Risk Analysis Examples

# Basic risk analysis
prcodesnip predict-risk --pr 42 --repo microsoft/vscode

# Detailed risk breakdown
prcodesnip predict-risk --pr 42 --repo owner/repo --detailed

# With debug information
prcodesnip predict-risk --pr 42 --repo owner/repo --detailed --debug

๐Ÿ“ Release Notes Examples

# Generate markdown release notes
prcodesnip draft-release --pr 42 --repo owner/repo

# Generate JSON format
prcodesnip draft-release --pr 42 --repo owner/repo --format json

# Save to file
prcodesnip draft-release --pr 42 --repo owner/repo --output changelog.md

# Interactive mode (prompts for PR and repo)
prcodesnip draft-release

๐Ÿš€ Complete Analysis Examples

# Basic analysis
prcodesnip premerge-analyze --pr 42

# With GitHub integration
prcodesnip premerge-analyze --pr 42 --post-comment --create-status

# Production workflow
prcodesnip premerge-analyze \
  --pr 42 \
  --repo owner/repo \
  --commit-sha abc123def \
  --post-comment \
  --create-status \
  --output production-analysis.json

๐ŸŒ Multi-language Examples

# === PROGRAMMING LANGUAGE DETECTION ===
# Detect programming languages used in repository
prcodesnip language detect-languages --repo microsoft/vscode

# Setup development environment for specific programming language
prcodesnip language setup-environment python --project-path ./my-python-project

# === CLI INTERFACE LANGUAGES ===
# Set Spanish interface for CLI
prcodesnip language set-language es

# Analyze with Spanish interface
prcodesnip predict-risk --pr 42 --repo owner/repo --language es

# Show current locale and number formatting
prcodesnip language show-locale-info

# List all available interface languages
prcodesnip language list-languages

๐Ÿ” Language Support Explanation

๐Ÿ–ฅ๏ธ CLI Interface Languages:

  • Changes the language of CodeSnip's interface (menus, messages, help text)
  • Affects number formatting, currency display, date formats
  • 25+ languages supported (Spanish, French, German, Japanese, etc.)
  • Use: prcodesnip language set-language es

๐Ÿ’ป Programming Language Detection:

  • Detects which programming languages are used in your repository
  • Analyzes code files, configuration files, and project structure
  • 60+ programming languages supported (Python, JavaScript, Go, Rust, etc.)
  • Automatically installs appropriate development tools and linters
  • Use: prcodesnip language detect-languages --repo owner/repo

Example Output for Programming Language Detection:

๐ŸŽฏ Primary Language: python
๐Ÿ“Š Detected Languages: python, javascript, dockerfile, yaml
โš™๏ธ Installing tools for python, javascript...
โœ… Tools installed: pytest, pylint, eslint, prettier, hadolint

๐Ÿ”’ Security and Privacy

  • Token Security: Tokens are never logged or stored in plain text
  • API Calls: Only necessary data is sent to external APIs
  • Local Processing: Most analysis happens locally
  • Configurable: All external integrations are optional

โšก Performance Tips

  1. Use Fast Mode: analyze-fast for CI/CD pipelines
  2. Set Timeouts: Configure appropriate timeouts in config
  3. Cache Results: Results are cached for repeated analyses
  4. Parallel Processing: Multiple PRs can be analyzed simultaneously

๐Ÿ› ๏ธ Development and Testing

Local Development

# Clone repository
git clone https://github.com/your-org/prcodesnip
cd prcodesnip

# Setup development environment
python -m venv venv
source venv/bin/activate  # Linux/Mac
# or venv\Scripts\activate  # Windows

# Install in development mode
pip install -e .[dev]

# Run tests
pytest

# Run with coverage
coverage run -m pytest
coverage report

Note: The venv/ folder is automatically created and should not be committed to version control. It's included in .gitignore.

Testing Your Changes

# Test with real PR
prcodesnip draft-release --pr 4 --repo your-username/your-repo

# Test risk prediction
prcodesnip predict-risk --pr 4 --repo your-username/your-repo --detailed

# Test full analysis
prcodesnip premerge-analyze --pr 4 --output test-analysis.json

๐Ÿค Contributing

Contributions welcome! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ“ž Support and Community


Made with โค๏ธ by the PRCodeSnip team. Happy coding! ๐Ÿš€

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prcodesnip-1.0.0.tar.gz (98.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prcodesnip-1.0.0-py3-none-any.whl (137.7 kB view details)

Uploaded Python 3

File details

Details for the file prcodesnip-1.0.0.tar.gz.

File metadata

  • Download URL: prcodesnip-1.0.0.tar.gz
  • Upload date:
  • Size: 98.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for prcodesnip-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8c47be5f51491c5cf66338eaa7865d8ac77cd4f7a285fd3750bf58244cf0f7f9
MD5 d942e11937284ff8b1a6a35dc5844035
BLAKE2b-256 a6c3dd0033270859c52923047a6e75fb3013246699661183c059097075c0ff82

See more details on using hashes here.

File details

Details for the file prcodesnip-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: prcodesnip-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 137.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for prcodesnip-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69b824633e208e411d783e9620b4471658dc187cda87ba825cf25a75faa3a1b7
MD5 c8160fa6eb6d9430e3e2880b7fd4a729
BLAKE2b-256 68db36b42594d985b80104477cb25e4a1c5a856787553dc6aef5255be9ebb23c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page