Skip to content

madhukarkumar/amp-code-review-ci

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 

Repository files navigation

Amp Code Review CI

An automated code review bot that uses Sourcegraph's Amp AI to provide intelligent feedback on pull requests in your GitHub repository.

Features

  • πŸ€– Automated code review on every PR
  • πŸ“ Inline comments with specific file and line references
  • 🎯 Intelligent analysis for security, performance, and code quality issues
  • πŸ”„ Re-runs on PR updates
  • πŸ“Š Structured feedback with priority levels (HIGH, MEDIUM, LOW)

Installation

1. File Placement

Save the code-revie.yml file to your repository at:

.github/workflows/code-revie.yml

2. GitHub Secrets Setup

You need to configure one secret in your GitHub repository:

Required Secret:

  • AMP_API_KEY: Your Sourcegraph Amp API key

How to set up secrets:

  1. Go to your GitHub repository
  2. Click Settings β†’ Secrets and variables β†’ Actions
  3. Click New repository secret
  4. Add the following secret:
Secret Name Description How to get it
AMP_API_KEY Sourcegraph Amp API key Visit ampcode.com to get your API key

Note: The workflow automatically uses GITHUB_TOKEN which is provided by GitHub Actions - no setup required.

3. Repository Permissions

The workflow needs the following permissions (automatically configured in the YAML):

  • contents: read - to checkout code and read files
  • pull-requests: write - to create review comments

How It Works

  1. Trigger: Automatically runs when a PR is opened or updated
  2. Analysis:
    • Fetches the PR diff
    • Generates intelligent code review using Amp AI
    • Analyzes for security, performance, and quality issues
  3. Feedback: Creates inline comments on specific lines with:
    • Issue severity (πŸ”΄ HIGH, 🟑 MEDIUM, 🟒 LOW)
    • Detailed descriptions
    • Actionable suggestions

Testing the Setup

Test 1: Create a Test PR

  1. Create a new branch:

    git checkout -b test-amp-review
  2. Add a simple file with intentional issues:

    // test-file.js
    function badFunction() {
        var password = "hardcoded123"; // Security issue
        console.log(password); // Security issue
        
        // Performance issue - inefficient loop
        for(var i = 0; i < 1000000; i++) {
            document.getElementById("test"); // DOM query in loop
        }
    }
  3. Commit and push:

    git add test-file.js
    git commit -m "Add test file for code review"
    git push origin test-amp-review
  4. Create a pull request on GitHub

Test 2: Verify Workflow Execution

  1. Go to Actions tab in your repository
  2. Look for "Amp Review Bot" workflow
  3. Check that it runs successfully
  4. Verify review comments appear on your PR

Expected Behavior

βœ… Success indicators:

  • Workflow runs without errors
  • PR gets review comments with specific line references
  • Comments include severity levels and suggestions

❌ Common issues:

  • Missing AMP_API_KEY: Workflow fails at "Run AMP review" step
  • No comments: Check that the PR has actual code changes
  • Workflow doesn't trigger: Verify file is at .github/workflows/code-revie.yml

Customization

Modify Review Focus

Edit the prompt in the "Run AMP review" step to focus on specific areas:

echo "Please analyze the following diff for:"
echo "- Missing or insufficient unit tests"        # Testing focus
echo "- Security vulnerabilities"                  # Security focus
echo "- Performance issues"                        # Performance focus
echo "- Code quality problems"                     # Quality focus
echo "- Architecture concerns"                     # Architecture focus
echo "- Best practices violations"                 # Best practices focus

Change Trigger Events

Modify the on section to change when reviews run:

on:
  pull_request:
    types: [opened, synchronize, ready_for_review]  # Add ready_for_review
  # Or add manual trigger:
  workflow_dispatch:

Adjust Review Severity

The bot categorizes issues into three levels:

  • πŸ”΄ HIGH: Critical security/performance issues
  • 🟑 MEDIUM: Code quality and maintainability issues
  • 🟒 LOW: Minor improvements and suggestions

Troubleshooting

Workflow Fails to Start

  • Check file location: .github/workflows/code-revie.yml
  • Verify YAML syntax is valid
  • Ensure you have write access to the repository

No Review Comments

  • Verify AMP_API_KEY is set correctly
  • Check that PR has meaningful code changes
  • Look at workflow logs in Actions tab

Authentication Errors

  • Ensure AMP_API_KEY secret is set
  • Verify the API key is valid and active
  • Check Amp account has sufficient quota

Review Comments on Wrong Lines

  • This can happen with complex diffs
  • The bot tries to find the closest relevant line
  • Consider smaller, focused PRs for better accuracy

Support

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Test your changes with the workflow
  4. Submit a pull request

This workflow uses Sourcegraph's Amp AI for intelligent code analysis. Visit ampcode.com to learn more.

About

Github action using Amp CLI for code review

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published