npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pr-reviewer

v1.25.0

Published

CLI tool for automated PR reviews using LLM

Downloads

44

Readme

PR Review Tool

npm version License

A CLI tool for automated code review and PR description generation using LLM (Language Learning Model). This tool analyzes Git diffs, structures the changes, and leverages AI to provide insightful code reviews and PR descriptions.

Features

  • 🔍 Automated code review generation
  • 📝 PR description generation with diagrams and topics
  • 🎯 Multiple review modes (brief, detailed, description)
  • 📊 Structured diff analysis
  • 🚀 Command-line interface with rich options
  • 📋 Comprehensive logging system
  • 🛡️ Robust error handling

Prerequisites

  • Node.js (v14 or higher)
  • npm (v6 or higher)
  • Git installed and configured
  • OpenAI API key

OpenAI API Key Configuration

Set up your OpenAI API key as an environment variable:

# Linux/macOS
export OPEN_API_KEY=your_openai_api_key

# Windows (Command Prompt)
set OPEN_API_KEY=your_openai_api_key

# Windows (PowerShell)
$env:OPEN_API_KEY="your_openai_api_key"

Installation

  1. Install the required dependencies:
npm install commander winston
  1. Install the tool globally:
npm install -g .

Usage

Basic Command Structure

pr-reviewer [options]

Options

Options:
  -V, --version                    output version number
  -b, --branch <branch>           branch name to review (required)
  -m, --mode <mode>               review mode (review/description) (default: "review")
  -t, --target-branch <branch>    target branch to compare against (default: "development")
  -v, --verbose                   enable verbose logging
  -o, --output <output>           output folder (default: "tmp")
  -h, --help                      display help for command

Examples

# Basic review of a feature branch
pr-reviewer -b feature/new-feature

# Generate detailed description comparing against main branch
pr-reviewer -b feature/new-feature -m description -t main

# Review with verbose logging
pr-reviewer -b feature/new-feature -v

# Show help
pr-reviewer --help

Review Modes

  1. review (default)

    • Performs a detailed code review
    • Identifies potential issues
    • Suggests improvements
    • Reviews code style and best practices
  2. description

    • Generates comprehensive PR description
    • Creates diagrams where applicable
    • Lists key changes and impacts
    • Provides technical context
  3. brief

    • Quick summary of changes
    • High-level impact analysis
    • Key points for reviewers

Output

The tool generates several output files:

  • combined.log: Complete execution log
  • error.log: Error-specific logging
  • Temporary diff files (automatically cleaned up)
  • LLM review output (saved to specified location)

How It Works

  1. Initialization

    • Parses command-line arguments
    • Validates input parameters
    • Sets up logging system
  2. Git Operations

    • Fetches latest changes
    • Checks out specified branch
    • Generates diff against target branch
  3. Diff Processing

    • Parses Git diff output
    • Structures changes by file
    • Identifies additions and removals
  4. LLM Integration

    • Sends structured changes to LLM
    • Processes LLM response
    • Generates formatted output
  5. Cleanup

    • Removes temporary files
    • Logs operation completion
    • Handles any errors

Error Handling

The tool includes comprehensive error handling for:

  • Git operation failures
  • File system issues
  • LLM communication problems
  • Invalid input parameters

Errors are:

  • Logged to error.log
  • Displayed in console with context
  • Handled gracefully with proper cleanup

Development

Project Structure

pr-reviewer/
├── src/
│   ├── GitOperations.js
│   ├── DiffParser.js
│   ├── PRReviewer.js
│   ├── LLMAdapter.js
│   └── send_to_llm.js
├── logs/
│   ├── combined.log
│   └── error.log
└── package.json

Adding New Features

  1. Follow the existing class structure
  2. Implement error handling
  3. Add appropriate logging
  4. Update tests if applicable

Troubleshooting

Common issues and solutions:

  1. Git access errors

    • Ensure Git is properly configured
    • Check repository permissions
  2. API key issues

    • Verify OPEN_API_KEY is set
    • Check key validity
  3. Parsing errors

    • Ensure branch exists
    • Check for valid diff output

Customizing Prompts

The tool uses customizable prompts for different review modes. These prompts can be modified by editing the MODE_FOR_PROMPT.js file in the project root.

Prompt Structure

// prompts.js
module.exports = {
  PROMPTS: {
    review: `[Your custom review prompt]`,
    brief: `[Your custom brief prompt]`,
    description: `[Your custom description prompt]`,
  },
};

Available Modes

  1. review: Used for detailed code reviews
  2. brief: Used for quick summaries
  3. description: Used for PR descriptions

Customizing Prompts

To modify the prompts:

  1. Locate MODE_FOR_PROMPT.js in the project root
  2. Edit the desired prompt in the PROMPTS object
  3. Save the file - changes will take effect immediately

Example Customization

// prompts.js
module.exports = {
  PROMPTS: {
    review: `
      As a senior developer, review this code focusing on:
      - Performance implications
      - Security concerns
      - Best practices
      - Potential edge cases
      Please be constructive and specific.
    `,
    brief: `
      Provide a 2-3 sentence summary of the changes.
      Include:
      - Main purpose 🎯
      - Key technical changes 🔧
      - Impact on users 👥
    `,
    description: `
      Create a comprehensive PR description with:
      1. Overview of changes
      2. Technical implementation details
      3. Testing considerations
      4. Visual diagrams where applicable
    `,
  },
};

Best Practices for Custom Prompts

  1. Be Specific: Clearly define what you want the LLM to focus on
  2. Format Consistently: Use clear formatting for better readability
  3. Include Guidelines: Add specific instructions for output format
  4. Keep it Focused: Each prompt should have a single clear purpose
  5. Test Changes: Verify new prompts generate desired outputs

Adding New Modes

To add a new review mode:

  1. Add your new prompt to the PROMPTS object:

    module.exports = {
      PROMPTS: {
        // Existing prompts...
        newMode: `Your new prompt here`,
      },
    };
  2. Use the new mode:

    pr-reviewer -b feature/branch -m newMode

License

MIT License - see LICENSE.md for details

Support

For bugs and feature requests, please create an issue in the repository.


Note: This tool is in active development. Please report any issues or suggestions for improvement.

Pushing to NPM

# Increment version
npm version patch|minor|major

# Publish
npm publish