Motoko
Motoko

Reputation: 1132

Possible to create Required Check / Pull Request Status?

https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pull%20request%20statuses/create?view=azure-devops-rest-6.0

I have tried the above API and the Check / Status is Optional so it doesn't prevent the users from completing the pull request. How do I make the status Required?

Upvotes: 0

Views: 4279

Answers (2)

Mengdi Liang
Mengdi Liang

Reputation: 18978

As the doc that shared by Matt,

Status policy - provides a mechanism to block pull request completion until the pull request status indicates success.

If you would like to make this status required for pull request, you need add this status configuration as a status policy. Because the required status info of pull request can only read from Status policy.

The pipeline status info was posted into pull request after you ran this api successfully. At this moment, you need to execute another step to make this status be required.

Step1:

Use below api to get the corresponding Status id:

GET https://dev.azure.com/{org name}/{project}/_apis/policy/types?api-version=6.0

Then you will find the Status id from the response body. Paste this id into txt, it is necessary for next step.

enter image description here

Step2:

Run below api to make the status you added previously to be required:

POST https://dev.azure.com/{org name}/{repo name}/_apis/policy/Configurations?api-version=5.0

Request body:

{
  "type": {
    "id": "{xxxx}" \\Put the **Status id** you copied in above step
  },
  "isBlocking": true, \\ IMPORTANT! Please set it to **true** since **false** means it is opitional
  "isEnabled": true,  \\Enable this for pull request
  "settings": {
    "invalidateOnSourceUpdate": false,
    "statusName": "APIStatus", \\Specify the status name you used while you create a status
    "statusGenre": "vsts-rm",  \\Same as above
    "scope": [
      {
        "repositoryId": "2fe327b4-66f5-4ce3-9227-dfd2ec80af1c", \\Specify this policy would apply to
        "refName": "refs/heads/master",  
        "matchKind": "Exact"
      }
    ]
  }
}

Upvotes: 3

Matt
Matt

Reputation: 4035

To add blocking on the PR you will also need to add a Status Policy.

Status policy

Using status alone, details from an external service can be provided to users within the PR experience. Sometimes, sharing information about a PR is all that is necessary, but in other cases PRs should be blocked from merging until requirements are met. Like the in-box policies, the Status policy provides a way for external services to block PR completion until requirements are met. If the policy is required, it must pass in order to complete the pull request. If the policy is optional, it is informational only, and a status of succeeded is not required in order to complete the pull request.

Status policies are configured just like other branch policies. When adding a new status policy, the name and genre of the status policy must be entered. If the status has been posted previously you can pick it from the list; if it is a new policy you can type in the name of the policy in the format genre/name.

Upvotes: 0

Related Questions