可以创建必需的检查/请求状态吗? [英] Possible to create Required Check / Pull Request Status?

查看:37
本文介绍了可以创建必需的检查/请求状态吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第二步:

在api下运行,以使您之前添加的状态变为必需状态

  POST https://dev.azure.com/{org名称}/{repo名称}/_ apis/policy/Configurations?api-version = 5.0 

请求正文:

  {类型":{"id":"{xxxx}";\\放入您在上述步骤中复制的**状态ID **},"isBlocking":是,\\重要!请将其设置为** true **,因为** false **表示它是可选的" isEnabled" ;: true,\\为拉取请求启用设置":{"invalidateOnSourceUpdate":否,"statusName":"APIStatus",\\指定创建状态时使用的状态名称"statusGenre":"vsts-rm",\\与上面相同范围":[{"repositoryId":"2fe327b4-66f5-4ce3-9227-dfd2ec80af1c",\\指定此策略适用于"refName":"refs/heads/master","matchKind":完全"}]}} 

https://docs.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?

解决方案

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.

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"
      }
    ]
  }
}

这篇关于可以创建必需的检查/请求状态吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆