azure-devops

Azure DevOps: approve Pull Request programatically


I'm using $Project Build Service ($org) account to create and merge PR (release/* into master after successful release)

..but it requires Bypass policies when completing pull requests option to be enabled for $Project Build Service ($org) account in scope of target branch

I can add $Project Build Service ($org) account as a reviewer for PRs to master but is there a way to approve PR in Azure DevOps programatically?


Solution

  • Is there a way to approve PR in Azure DevOps programatically?

    You can use the REST API Pull Request Reviewers - Create Pull Request Reviewer to approve pull request.

    PUT https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/reviewers/{reviewerId}?api-version=6.0
    

    Here is an example of request body:

    {
        "vote": 10
    }
    

    The value of vote sets the state of the review:

    10 - approved

    5 - approved with suggestions

    0 - no vote

    -5 - waiting for author

    -10 - rejected