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.
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
- 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.
- 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
/webhookendpoint (e.g.,http://your-server:5000/webhook).
- Store your Azure DevOps Personal Access Token as an environment variable named
AZURE_DEVOPS_PAT:export AZURE_DEVOPS_PAT=your_pat_here
- Comment
/run-agenton any PR in your configured repository. - The agent will analyze the PR and post findings as a comment.
- Add new code analysis rules by implementing the
ICodeAnalyzerinterface. - 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.