GPT Pull Request review Task for Azure Pipelines
The GPT Pull Request Review Task for Azure Pipelines is designed to use the GPT model from OpenAI to review Pull Requests and provide feedback as comments in the Pull Request.
Setup
Before using this task, ensure that the build service has permissions to contribute to Pull Requests in your repository, and allow the task to access the system token.
Give permission to the build service agent
To allow the build service agent to contribute to pull requests, navigate to Project Settings > Repositories, select your repository, and grant "Project Collection Build Service" permissions for "Contribute," and "Contribute to Pull Requests." Save your changes to apply the permissions.
Yaml pipelines
Add a checkout section with persistCredentials set to true.
steps:
- checkout: self
persistCredentials: true
Azure Open AI service
To create OpenAI resource and model deployment through devops pipeline arm template and sample .yml file given below.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"openAiResourceName": {
"type": "string",
"metadata": {
"description": "Name of the Azure OpenAI resource."
}
},
"location": {
"type": "string",
"metadata": {
"description": "Location for the resource."
}
},
"skuName": {
"type": "string",
"allowedValues": [
"S0"
],
"metadata": {
"description": "SKU name for the OpenAI resource."
}
},
"deploymentName": {
"type": "string",
"metadata": {
"description": "Name of the deployment for the OpenAI resource."
}
},
"modelName": {
"type": "string",
"defaultValue": "gpt-4",
"metadata": {
"description": "Name of the model to deploy."
}
},
"modelVersion": {
"type": "string",
"defaultValue": "0613",
"metadata": {
"description": "Version of the model to deploy."
}
},
"modelCapacity": {
"type": "int",
"defaultValue": 10,
"metadata": {
"description": "Capacity for the model deployment."
}
},
"publicNetworkAccess": {
"type": "string",
"allowedValues": [
"Enabled",
"Disabled"
],
"defaultValue": "Enabled",
"metadata": {
"description": "Enable or disable public network access for the resource."
}
},
"tags": {
"type": "object",
"metadata": {
"description": "Tags to be applied to the resource."
}
}
},
"resources": [
{
"type": "Microsoft.CognitiveServices/accounts",
"apiVersion": "2024-06-01-preview",
"name": "[parameters('openAiResourceName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('skuName')]"
},
"kind": "OpenAI",
"properties": {
"publicNetworkAccess": "[parameters('publicNetworkAccess')]"
},
"tags": "[parameters('tags')]"
},
{
"type": "Microsoft.CognitiveServices/accounts/deployments",
"apiVersion": "2024-06-01-preview",
"name": "[concat(parameters('openAiResourceName'), '/', parameters('deploymentName'))]",
"dependsOn": [
"[resourceId('Microsoft.CognitiveServices/accounts', parameters('openAiResourceName'))]"
],
"sku": {
"name": "Standard",
"capacity": "[parameters('modelCapacity')]"
},
"properties": {
"model": {
"format": "OpenAI",
"name": "[parameters('modelName')]",
"version": "[parameters('modelVersion')]"
},
"versionUpgradeOption": "OnceNewDefaultVersionAvailable",
"currentCapacity": "[parameters('modelCapacity')]"
}
}
]
}
sample yml file
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
variables:
serviceconnection: 'service connection name'
resourceGroupName: 'resource name'
location: 'location'
stages:
- stage: Deploy
jobs:
- job: ARMDeployment
steps:
- script: |
echo "Deploying resources with parameters from parameters.json"
displayName: 'Log Deployment Info'
- task: AzureResourceManagerTemplateDeployment@3
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: $(serviceconnection)
subscriptionId: 'your subscriptionId'
action: 'Create Or Update Resource Group'
resourceGroupName: $(resourceGroupName)
location: $(location)
templateLocation: 'Linked artifact'
csmFile: '$ path to arm template' # path to arm template
csmParametersFile: '$ Path to parameters file' # Path to your parameters file
deploymentMode: 'Incremental'
OpenAI Models
In case you don't use Azure Open AI Service, you can choose which model to use, the supported models are "gpt-4", "gpt-3.5-turbo" and "gpt-3.5-turbo-16k". if no model is selected the "gpt-3.5-turbo" is used.
How to use it
Install the extension
To use the GPT Pull Request Review Task, first install the extension in your Azure DevOps organization. Click on the "Get it free" button and follow the prompts to install it. You may need to authorize the extension to access your Azure DevOps account.
Add the task to the build pipeline
After installing the extension, add the task to your build pipeline. Go to your build pipeline, click on the "+" icon to add a new task, and search for "Review PullRequest by GPT". Select it and add it to your pipeline.
Once you have added the task to your pipeline, configure it. In the task configuration, provide your API key for OpenAI API. you will get key in azure portal under your openai resource.
endpoint OpenApi Endpoint : for that you have to use https://{XXXXXXXX}.openai.azure.com/openai/deployments/{MODEL_NAME}/chat/completions?api-version={API_VERSION} this format (eg. (Azure OpenApi Endpoint)/openai/deployments/{MODEL_NAME}/chat/completions?api-version=2024-02-15-preview) (MODEL_NAME)
below you can see sample yml file code.
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- main
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
persistCredentials: true # Persist credentials to be used in subsequent steps
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
- task: AssetByMPD.GPTPullRequestReview.GPTPullRequestReview.GPTPullRequestReview@0
inputs:
api_key: 'your api key'
model: 'gpt-4'
aoi_endpoint: '(azure open ai endpoint)/openai/deployments/(model name)/chat/completions?api-version=2024-02-15-preview'
configurablePrompt: 'you can give custom instruction for the format or what you want in comment to be added'
Then run pipeline once and then add build validation on main branch for that go to repository settings under policies add build validation on that branch and select pipeline under which you have added GPT task.
after this whenever pull request created to merge with main branch on which you have added build validation GPT task will runs and add comments on that pull request.
Review Pull Requests
When the build is triggered from a Pull Request, the task will review it. If there is feedback on the changed code, the task will add comments to the Pull Request. If the build is triggered manually, the task will be skipped.
Compatible with Linux Build Agents
The tasks can execute on all supported build agent operating systems including Linux and MacOS.
Disclaimer
This task uses Azure OpenAI to analyze and review pull requests. It is important to follow Microsoft's security and data privacy standards when using OpenAI services. For more details on data privacy and security requirements, please refer to Microsoft's Cognitive Services OpenAI Data Privacy Guidelines Microsoft's Cognitive Services OpenAI Data Privacy Guidelines.