【发布时间】:2020-01-24 13:49:23
【问题描述】:
我对 Azure DevOps API POST 感到困惑。我已经成功地为“最少审阅者”创建了一个策略,但它没有针对我指定的分支创建。目前我已经在 Fiddler 中完成了这项工作,这是我的请求(私有值被混淆):
POST http://our-tfs-server:8080/tfs/TheCollection/TheProject/_apis/policy/configurations?api-version=5.1 HTTP/1.1
Content-Type: application/json; charset=utf-8
Host: our-tfs-server:8080
Authorization: Basic MyBase64EncodedToken
{
"IsBlocking": true,
"IsEnabled": true,
"Settings": {
"MinimumApproverCount": 2,
"Scope": [
{
"RefName": "refs/heads/master",
"MatchKind": "exact",
"RepositoryId": "7718333c-044e-423a-baa1-45e6a1f0ff41"
}
]
},
"Type": {
"Id": "fa4e907d-c16b-4a4c-9dfa-4906e5d171dd"
}
}
这是响应正文:
{
"createdBy": {
"displayName": "Surname, Firstname",
"url": "http://our-tfs-server:8080/tfs/TheCollection/_apis/Identities/SomeString",
"_links": { "avatar": { "href": "http://our-tfs-server:8080/tfs/TheCollection/_apis/GraphProfile/MemberAvatars/win.SomeString" } },
"id": "7b40f8ab-a933-4b43-bdf8-bf0b179d28e6",
"uniqueName": "MyUsername",
"imageUrl": "http://our-tfs-server:8080/tfs/TheCollection/_api/_common/identityImage?id=SomeString",
"descriptor": "win.SomeOtherString"
},
"createdDate": "2020-01-23T02:09:34.4738854",
"isEnabled": true,
"isBlocking": true,
"isDeleted": false,
"settings": {
"minimumApproverCount": 2,
"creatorVoteCounts": false,
"allowDownvotes": false,
"resetOnSourcePush": false,
"scope": [ { "repositoryId": "7718333c-044e-423a-baa1-45e6a1f0ff41" } ]
},
"_links": {
"self": { "href": "http://our-tfs-server:8080/tfs/TheCollection/8b7e65ed-1136-4b0f-9780-de2a3860447a/_apis/policy/configurations/254" },
"policyType": { "href": "http://our-tfs-server:8080/tfs/TheCollection/8b7e65ed-1136-4b0f-9780-de2a3860447a/_apis/policy/types/fa4e907d-c16b-4a4c-9dfa-4906e5d171dd" }
},
"revision": 1,
"id": 254,
"url": "http://our-tfs-server:8080/tfs/TheCollection/8b7e65ed-1136-4b0f-9780-de2a3860447a/_apis/policy/configurations/254",
"type": {
"id": "fa4e907d-c16b-4a4c-9dfa-4906e5d171dd",
"url": "http://our-tfs-server:8080/tfs/TheCollection/8b7e65ed-1136-4b0f-9780-de2a3860447a/_apis/policy/types/fa4e907d-c16b-4a4c-9dfa-4906e5d171dd",
"displayName": "Minimum number of reviewers"
}
}
注意"scope": [ { "repositoryId": "7718333c-044e-423a-baa1-45e6a1f0ff41" } ] 只有repositoryId。
在分支策略的 UI 中,未勾选“最少审阅者人数”选项,并且没有完整存储库级别的问题版本。如果我打电话给/_apis/policy/configurations,那么我会看到新政策,所以它已经被创建了。也许现在这将使用该策略保护所有分支,但我们不希望在全球范围内使用它,并且鉴于 DevOps web ui 中没有用于它的工具,我很确定它无论如何都不会是这样的。
那么,这是 API 功能方式的疏忽,还是分支应用策略配置以使用其他技术设置?
【问题讨论】:
-
为什么不能使用 UI 手动将策略应用到分支级别,然后执行 GET 以查看它的外观,然后参考 POST 正文应该是什么样子的结果?
-
自发布以来,我实际上已经在 Fiddler 运行的情况下完成了该操作并接受了它的请求。我不完全清楚是哪个属性导致了这个问题。我正在逐步从请求中一次删除默认值属性,然后删除以查看返回的内容。困扰我的是我需要从 C# 应用程序驱动它以批量应用规则,并且调用看起来对我来说是正确的,但是从我发出与 Fiddler 捕获的相同请求的应用程序中,它在那里失败了。将继续堵住它。除了请求正文中的某些内容外,我似乎没有遗漏任何内容。谢谢
标签: azure-devops azure-devops-rest-api