DEV Community

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

Posted on

3 1

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 ๐Ÿ“–.

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

Postmark Image

"Please fix this..."

Focus on creating stellar experiences without email headaches. Postmark's reliable API and detailed analytics make your transactional emails as polished as your product.

Start free