AI Azure DevOps PR
This extension provides an AI-powered task for Azure DevOps pipelines that integrates with Azure OpenAI to analyze Pull Requests and generate intelligent feedback based on PR diffs and custom prompts.
Features
- Azure OpenAI integration for generating AI-powered responses based on prompts
- Read markdown files as system and user prompts for customizable AI interactions
- Automatic Pull Request diff generation to use as prompt content
- Save AI-generated responses to markdown files
- Post responses as comments directly on Pull Requests
- Easy integration with your existing CI/CD workflows
Requirements
- Azure DevOps Services or Azure DevOps Server 2020 or later
- Azure OpenAI account and API key
- Permissions to comment on Pull Requests (for postToPR functionality)
- Git installed on pipeline agents (for autoDiff functionality)
Installation
From the Marketplace
- Go to the Azure DevOps Marketplace
- Search for "AI Azure DevOps PR"
- Click "Get it free"
- Select the organization where you want to install the extension
Manual Installation
- Download the VSIX file from the project releases
- Navigate to the Extensions section in your Azure DevOps organization (
https://dev.azure.com/{organization}/_settings/extensions
)
- Click "Upload a new extension" and select the VSIX file
- Install the extension in your organization
Usage
Basic Configuration
# azure-pipelines.yml
steps:
- task: AIAzureDevOpsPR@1
displayName: 'Generate content with Azure OpenAI'
inputs:
endpoint: 'https://your-azure-openai-endpoint.cognitiveservices.azure.com/'
modelName: 'gpt-4'
deployment: 'your-deployment-name'
apiKey: '$(AZURE_OPENAI_API_KEY)' # Use a secret variable
systemPromptFile: '$(Build.SourcesDirectory)/prompts/system-prompt.md'
userPromptFile: '$(Build.SourcesDirectory)/prompts/user-prompt.md'
outputFile: '$(Build.ArtifactStagingDirectory)/openai-response.md'
postToPR: false
autoDiff: false
# azure-pipelines.yml
trigger:
- none
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
persistCredentials: true # Important for Git access in autoDiff
- task: AIAzureDevOpsPR@1
displayName: 'Analyze PR with Azure OpenAI'
inputs:
endpoint: 'https://your-azure-openai-endpoint.cognitiveservices.azure.com/'
modelName: 'gpt-4'
deployment: 'deployment-name'
apiKey: '$(AZURE_OPENAI_API_KEY)'
systemPromptFile: '$(Build.SourcesDirectory)/prompts/code-review-prompt.md'
userPromptFile: '$(Build.SourcesDirectory)/prompts/additional-context.md'
outputFile: '$(Build.ArtifactStagingDirectory)/code-review.md'
autoDiff: true # Automatically generate PR diff as prompt
postToPR: true # Post response as comment on PR
IMPORTANT: To use the postToPR
functionality, make sure to enable the "Allow scripts to access OAuth token" option in your pipeline settings.
Sample File Structure
To facilitate setup, you can use this file structure:
repository/
├── .azure-pipelines/
│ └── openai-pr-review.yml # PR review pipeline
├── prompts/
│ ├── system-prompt.md # System prompt for OpenAI
│ └── user-prompt.md # User prompt (optional if using autoDiff)
└── README.md
Parameter |
Required |
Description |
endpoint |
Yes |
Azure OpenAI endpoint URL |
modelName |
Yes |
OpenAI model name (e.g. gpt-4) |
deployment |
Yes |
Azure OpenAI deployment name |
apiKey |
Yes |
API Key for authentication (use secret variables) |
systemPromptFile |
Yes |
Path to markdown file with system prompt |
userPromptFile |
Yes |
Path to markdown file with user prompt |
outputFile |
Yes |
Path where the markdown response will be saved |
autoDiff |
No |
If true , automatically generates PR diff |
postToPR |
No |
If true , posts the response as a comment on the PR |
Using autoDiff
When autoDiff
is set to true
, the task:
- Checks if it's running in the context of a Pull Request
- Executes the diff generation script between the source and target branches of the PR
- Uses the generated diff as the user prompt content, instead of the
userPromptFile
- If the diff can't be generated or not in a PR context, falls back to the
userPromptFile
This functionality is ideal for automated code reviews, change summaries, or generating documentation based on changes made.
To use the postToPR
functionality, make sure to:
- Enable the "Allow scripts to access OAuth token" option in your pipeline settings
- Have sufficient permissions to comment on PRs
- Configure the trigger correctly to run in a PR context
Development
Prerequisites
- Node.js 16 or later
- npm 7 or later
- Visual Studio Code (recommended for development)
- Azure DevOps CLI (optional, for publishing)
Project Structure
azure-devops-task/
├── dist/ # Compiled files (generated)
├── images/ # Extension images
├── scripts/ # Utility scripts
├── src/ # Source code
│ ├── index.ts # Main entry point
│ ├── task.json # Task definition
│ └── scripts/ # Scripts included with the task
├── tests/ # Tests
├── package.json # Project configuration
├── tsconfig.json # TypeScript configuration
└── vss-extension.json # Extension manifest
Available Commands
Development
npm run build
: Compile the TypeScript project
npm run clean
: Remove generated files
npm run prepare-package
: Prepare files for packaging
Packaging
npm run package
: Create VSIX package for distribution
npm run package:dev
: Create VSIX package with development version
Publishing
npm run publish
: Publish extension to the marketplace
npm run publish:dev
: Publish development version (private)
Version Management
npm run increment-version
: Increment project version (patch by default)
npm run increment-version -- major
: Increment major version
npm run increment-version -- minor
: Increment minor version
Development Process
- Clone this repository
- Run
npm install
to install dependencies
- Modify the source code in the
src
folder
- Run
npm run build
to compile and check for errors
- Run
npm run package
to create the VSIX package
- Test the extension in your Azure DevOps environment
Publishing to the Marketplace
To publish the extension to the Azure DevOps Marketplace, you need:
- A publisher account on the Visual Studio Marketplace
- Update the
publisher
field in the vss-extension.json
file with your publisher ID
- Run
npm run increment-version
to update the version
- Run
npm run publish
to package and publish the extension
Local Testing
To test the task locally before publishing:
# Build the project
npm run build
# Copy task.json to the dist folder
cp src/task.json dist/
# Run the test script
node tests/runTest.js
Note: For complete testing with Azure OpenAI, you'll need to provide a valid API key in the test script.
License
ISC
Contributions
Contributions are welcome. Please follow these steps:
- Fork the repository
- Create a branch with your feature name (
git checkout -b feature/new-feature
)
- Make your changes and commit (
git commit -am 'Add new feature'
)
- Push to the branch (
git push origin feature/new-feature
)
- Create a Pull Request