A PowerShell module to help you approve and reject VSTS pull requests based on the status of your CI process.
If the build is successful it will:
- Set the PR as approved from the account you've configured.
- Leave a comment linking to the successful build.
else if it has failed:
- Set the PR as rejected.
- Leave a comment linking to the failed build.
You can get started with the module in a number of ways.
Install-Module -ModuleUrl https://github.com/naeemkhedarun/VstsPullRequestApprover/raw/master/VstsPullRequestApprover/VstsPullRequestApprover.psm1
Download the latest release from the releases page:
https://github.com/naeemkhedarun/VstsPullRequestApprover/releases/latest
You can unpack it into the PSModulePath C:\Users\_user_\Documents\WindowsPowerShell\Modules
to autoload it.
If you are using TeamCity you can roll it out across the agents as an agent tool.
You can either use your own account or create a dedicated account to do the approvals. This account should be included in the branch policies and its access token used to submit the approval.
Next log in as the approval user and generate an access token which you can pass to the module when setting the pull request status. It will need the Code (read and write)
permission.
You can now call the module to set the status:
Import-Module VstsPullRequestApprover
Set-PullRequestStatus `
-vcsroot "https://domain.visualstudio.com/DefaultCollection/Project/_git/git-repository" `
-branch "refs/pull/_id_/merge" `
-accessToken "xxx" `
-reviewerAccount "Reviewer" `
-approve $false `
-buildUri "https://teamcity/?build-id=1"
This is the uri of the Git repository that your build is using. It is broken down and used to constructor the uris for the VSTS API.
The VSTS pull request branch which is being built. It contains the ID of the pull request used
in the api calls. It is in the format ref/pull/_id_/merge
.
The approving users access token with the Code (read and write)
permission.
The display name of the approving users account. We search the available reviewers from the API to resolve the users ID. If the user isn't set up as a reviewer you will get an error and a list of available reviewer names.
$true for approving the pull request, and $false for denying.
The uri for the build which is compiling and testing the pull request.
Please start raise an issue on github for any bugs or features you would like to see.