Skip to content

lyonn19/azure-devops-code-review-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure DevOps Code Review Agent

Overview

This project includes a C# code review agent for Azure DevOps repositories and a Minimal ASP.NET Core API (WebhookApi.cs) that listens for PR comment webhooks. When a comment containing /run-agent is posted on a PR, the webhook triggers the agent to analyze the PR and post automated review comments.

Sequence Diagram

sequenceDiagram
    participant User
    participant AzureDevOps
    participant WebhookAPI as Webhook API
    participant Agent as Code Review Agent

    User->>AzureDevOps: Comments "/run-agent" on PR
    AzureDevOps->>WebhookAPI: Sends webhook event
    WebhookAPI->>Agent: Starts agent process
    Agent->>AzureDevOps: Lists open PRs
    loop For each PR
        Agent->>AzureDevOps: Fetches changed files
        Agent->>Agent: Analyzes code (via analyzers)
        alt Issues found
            Agent->>AzureDevOps: Posts review comments
        else No issues
            Agent->>Console: Logs "No issues found."
        end
    end
Loading

How to Use

1. Set Up the Webhook API

  • Ensure you have the .NET 6+ SDK installed.
  • Run the API:
    dotnet run --project WebhookApi.cs
  • The API will listen for POST requests at /webhook.

2. Configure Azure DevOps Service Hook

  • In your Azure DevOps project:
    • Go to Project Settings > Service Hooks > Create Subscription > Web Hooks.
    • Set the trigger to Pull request commented on.
    • Set the URL to your server's /webhook endpoint (e.g., http://your-server:5000/webhook).

3. Set Your Azure DevOps PAT

  • Store your Azure DevOps Personal Access Token as an environment variable named AZURE_DEVOPS_PAT:
    export AZURE_DEVOPS_PAT=your_pat_here

4. Usage

  • Comment /run-agent on any PR in your configured repository.
  • The agent will analyze the PR and post findings as a comment.

Extending the Agent

  • Add new code analysis rules by implementing the ICodeAnalyzer interface.
  • Register new analyzers in the agent for custom checks.

Security Note: Never expose your PAT publicly. Always use secure environment variables or secret management in production.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published