DEV Community

Cover image for GitHub PR Analyzer: Automating Code Reviews with Amazon Q Developer
Veríssimo Cassange
Veríssimo Cassange

Posted on

GitHub PR Analyzer: Automating Code Reviews with Amazon Q Developer

This is a submission for the Amazon Q Developer "Quack The Code" Challenge: Crushing the Command Line

What I Built

I created GitHub PR Analyzer 🚀, a powerful command-line tool that automates code review in GitHub repositories. This tool addresses several pain points that developers face when managing pull requests across multiple repositories:

  • Time-consuming manual reviews ⏳: Developers often spend hours reviewing PRs, especially in large repositories with many contributors.
  • Difficulty tracking PRs across multiple repositories 🌐: When working with microservices or distributed systems, tracking PRs across repositories becomes challenging.
  • Lack of standardized reporting 📊: Without a consistent way to document PR reviews, valuable insights get lost.
  • Missing historical data 📜: Finding patterns in past PRs is difficult without proper archiving.

GitHub PR Analyzer solves these problems by:

  1. Automating PR analysis 🤖: Extracts detailed information about PRs (open, closed, or all)
  2. Detecting code issues 🔍: Identifies TODOs, FIXMEs, and files with excessive changes
  3. Generating comprehensive reports 📄: Creates detailed PDF reports with PR statistics and code analysis
  4. Supporting multiple repositories 📚: Analyzes several repositories in a single command
  5. Providing a web interface 🌍: Makes all reports accessible through a user-friendly web interface
  6. Sending email notifications 📧: Alerts team members when new reports are generated

The tool is built with Python 🐍 and integrates with AWS services (S3, Lambda, SNS, CloudWatch) ☁️. I used Pulumi for infrastructure as code (IaC) 🛠️—a practice I adopted and refined during my participation in a previous challenge, the Pulumi Challenge, where I first explored infrastructure automation in depth.

Demo

Web Interface 🌐

The GitHub PR Analyzer provides a web interface to browse and search all generated reports 📊:

Interface Web

PDF Reports 📄

The tool generates detailed PDF reports with PR statistics and code analysis 📈:

PDF Report Example

The image above is just a snapshot extracted from the generated PDF. You can view the full report directly in the PDF file available in the repository.

Email Notifications 📧

When a new report is generated, team members receive email notifications 🚨:

Email Notification

Live Demo 🎮

You can access the web interface here: GitHub PR Analyzer Web Interface 🔗

Code Repository

The complete code is available on GitHub:

GitHub logo vec21 / aws-challenge-automation

This repository contains my submission for the Amazon Q Developer Challenge – Quack the Code (April/May 2025), in the 'Crushing the Command Line' category. Details: https://dev.to/challenges/aws-amazon-q-v2025-04-30

GitHub PR Analyzer 🌟

GitHub PR Analyzer

A command-line tool that automates code review in GitHub repositories, generating detailed PDF reports and making them available through a web interface. 🚀

Features 🎯

  • Pull Request Analysis 📋: Extracts detailed information about PRs (open, closed, or all)
  • Code Analysis 🔍: Detects issues like TODOs, FIXMEs, and files with many changes
  • Date Filtering 🗓️: Allows analyzing PRs created in the last N days
  • Multiple Repository Support 📦: Analyzes multiple repositories in a single report
  • PDF Reports 📄: Generates detailed reports in PDF format
  • Web Interface 🌐: View all reports in a user-friendly web interface
  • Email Notifications 📧: Receive alerts when new reports are generated

Prerequisites ✅

  • Python 3.9+ 🐍
  • AWS account with access to create resources (S3, Lambda, SNS) ☁️
  • GitHub personal access token 🔑
  • Pulumi CLI installed ⚙️

Installation 🛠️

  1. Clone the repository:

    git clone https://github.com/vec21/aws-challenge-automation.git
    cd aws-challenge-automation
    Enter fullscreen mode Exit fullscreen mode
  2. Create and activate a virtual environment:

    python
    Enter fullscreen mode Exit fullscreen mode

How I Used Amazon Q Developer

Amazon Q Developer 🤖

Amazon Q Developer was the secret weapon that helped me build this tool efficiently. I leveraged its specialized commands to accelerate development:

Amazon Q Developer

/dev - Code Development 💻

Amazon Q Developer helped me bootstrap the project by generating the initial CLI structure with GitHub API integration. This saved me hours of boilerplate coding and documentation reading ⏳.

# Generated by Amazon Q Developer
@click.command()
@click.option('--repo', required=True, help='GitHub repository (user/repo) or comma-separated list')
@click.option('--state', default='open', type=click.Choice(['open', 'closed', 'all']), 
              help='State of PRs to analyze')
def review_code(repo, state):
    """Reviews pull requests from a GitHub repository and generates a PDF report.""" 📄
    # Implementation follows...
Enter fullscreen mode Exit fullscreen mode

Amazon Q also helped me implement the Pulumi infrastructure code, setting up S3, Lambda, and SNS services with proper permissions 🛠️:

# Generated by Amazon Q Developer
bucket = aws.s3.BucketV2(
    "automation-bucket",
    bucket="vec21-aws-challenge",
    tags={"Name": "AutomationBucket"}
)

website_config = aws.s3.BucketWebsiteConfigurationV2(
    "website-config",
    bucket=bucket.id,
    index_document={"suffix": "index.html"},
    error_document={"key": "error.html"}
)
Enter fullscreen mode Exit fullscreen mode

/review - Code Optimization 🔍

When I encountered rate limiting issues with the GitHub API, Amazon Q suggested implementing retry mechanisms 🔄:

# Before Amazon Q review
repository = g.get_repo(repo_name)
pulls = repository.get_pulls(state=state)

# After Amazon Q review
try:
    repository = g.get_repo(repo_name)
    pulls = repository.get_pulls(state=state)
except RateLimitExceededException:
    time.sleep(2)  # Wait before retrying
    repository = g.get_repo(repo_name)
    pulls = repository.get_pulls(state=state)
Enter fullscreen mode Exit fullscreen mode

It also identified a critical timezone issue when comparing dates ⏰:

# Before Amazon Q review
since_date = datetime.now() - timedelta(days=days)

# After Amazon Q review
since_date = datetime.now(timezone.utc) - timedelta(days=days)
Enter fullscreen mode Exit fullscreen mode

/test - Test Generation 🧪

Amazon Q generated comprehensive test cases for my code, including fixtures and mocks ✅:

# Generated by Amazon Q Developer
@pytest.fixture
def mock_pull_request():
    mock = MagicMock()
    mock.number = 1
    mock.title = "Test PR"
    mock.user.login = "testuser"
    mock.created_at = datetime.now(timezone.utc)
    # More properties...
    return mock

def test_analyze_pull_request(mock_repository, mock_pull_request):
    result = analyze_pull_request(mock_repository, mock_pull_request)
    assert 'complexity' in result
    assert 'issues' in result
    assert 'languages' in result
Enter fullscreen mode Exit fullscreen mode

/doc - Documentation 📝

Amazon Q helped me create clear documentation, including the architecture diagram and usage examples 📚:

Architecture 🏗️

Architecture Diagram

The architecture diagram was originally generated by Amazon Q in ASCII format, using characters such as -, >, |, and letters to illustrate the system components and their interactions. This ASCII diagram was then converted into a visual image using ChatGPT, based on the same structure, to improve readability and presentation 🎨.

The project uses the following AWS services:

  • S3 ☁️: Storage for PDF reports and web interface hosting
  • Lambda ⚡: Scheduled execution of code analysis
  • SNS 📬: Email notification delivery
  • CloudWatch Events ⏰: Scheduling of periodic executions

Key Insights from Using Amazon Q Developer 🧠

  1. Start with a clear problem statement 🎯: The more specific your request to Amazon Q, the better the generated code.
  2. Iterative development 🔄: Use Amazon Q to generate a basic structure, then refine it with more specific requests.
  3. Leverage specialized commands 🛠️: The /dev, /review, /test, and /doc commands are tailored for different development phases.
  4. Verify and understand the code ✅: Always review and understand the generated code before implementing it.
  5. Use Amazon Q for learning 📖: The explanations provided alongside the code are excellent learning resources.

Future Improvements 🚀

While GitHub PR Analyzer already provides significant value in its current form, I have several exciting enhancements planned for future iterations:

Short-term Improvements 🔜

  1. AI-powered Code Analysis 🧠: Integrate with Amazon Bedrock or Amazon CodeGuru to provide deeper code insights, including:

    • Potential bugs and security vulnerabilities
    • Code quality metrics and suggestions
    • Performance optimization recommendations
  2. Custom Report Templates 📊: Allow users to define their own report templates to focus on metrics that matter most to their teams.

  3. GitHub Actions Integration ⚙️: Create a GitHub Action that automatically generates reports on PR creation, updates, or merges.

  4. Slack/Teams Notifications 💬: Expand notification options beyond email to include popular team communication platforms.

Medium-term Vision 🔭

  1. PR Trend Analysis 📈: Implement historical data analysis to identify patterns and trends in your development process:

    • PR velocity over time
    • Common issues by repository or contributor
    • Code quality trends
  2. Interactive Dashboards 📱: Enhance the web interface with interactive charts and filtering capabilities for better data exploration.

  3. Multi-platform Support 🌐: Extend beyond GitHub to support GitLab, Bitbucket, and other Git hosting services.

  4. CI/CD Pipeline Analysis 🔄: Correlate PR data with CI/CD pipeline metrics to identify bottlenecks in your development workflow.

Long-term Roadmap 🗺️

  1. Collaborative Review Features 👥: Enable teams to collaborate on PR reviews directly within the tool:

    • Comment and discussion threads
    • Review assignments and tracking
    • Approval workflows
  2. Machine Learning Insights 🤖: Train models on your PR history to:

    • Predict PR review time and complexity
    • Recommend optimal reviewers based on code expertise
    • Identify potential merge conflicts before they occur
  3. Enterprise Integration 🏢: Develop enterprise features like:

    • SSO authentication
    • Role-based access control
    • Compliance reporting
    • Custom retention policies
  4. Developer Productivity Metrics ⚡: Provide insights into developer productivity while respecting privacy and focusing on team-level metrics rather than individual performance.

I'm excited to continue evolving this tool based on user feedback and emerging needs in the development community. If you have suggestions for additional features, please share them in the comments or open an issue in the GitHub repository! 🙌

Conclusion 🎉

Building GitHub PR Analyzer with Amazon Q Developer was a game-changer 🚀. What would have taken weeks to develop was completed in days ⏩, with better code quality and more comprehensive documentation 📚. The tool now helps our team save hours each week on code reviews ⏰ while providing valuable insights into our development process 📊.

Amazon Q Developer isn't just a code generator—it's a true development partner 🤝 that helps you think through problems 🧠, implement solutions 🛠️, and learn best practices along the way 📖.

Top comments (0)