API POST 未应用于 Azure DevOps Server 分支(2019 更新 1)
API POST not applied to branch with Azure DevOps Server (2019 Update 1)
我对 Azure DevOps 感到困惑 API POST。我已经成功地为 "Minimum number of reviewers" 创建了一个策略,但它不是针对我指定的分支创建的。我目前在 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 网络中没有工具 ui 我很确定它不是那样的无论如何。
那么,这是对 API 功能方式的疏忽,还是应用策略配置以使用另一种技术进行设置的分支?
所以...答案在于 json 请求正文中 属性 名称的大写。虽然 json 不区分大小写,并且我发出的请求在内部返回 200 和一个有效正文,但服务器在应用策略配置的分支设置上崩溃了。 NewtonSoft 在开始时使用大写字母序列化 属性 名称,我发现使用小写字母修复了原始问题,然后创建的返回对象分配了 refName 和 matchKind 并勾选了 MinimumNumberOfReviewers 复选框并设置了数字到 2. 为什么 MS 无法仅序列化一个或两个属性有点奇怪,无论如何我在全球范围内应用了 JsonSerializationSettings 以避免需要在任何地方添加 JsonPropertyAttribute 以及忽略空属性。
我对 Azure DevOps 感到困惑 API POST。我已经成功地为 "Minimum number of reviewers" 创建了一个策略,但它不是针对我指定的分支创建的。我目前在 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 网络中没有工具 ui 我很确定它不是那样的无论如何。
那么,这是对 API 功能方式的疏忽,还是应用策略配置以使用另一种技术进行设置的分支?
所以...答案在于 json 请求正文中 属性 名称的大写。虽然 json 不区分大小写,并且我发出的请求在内部返回 200 和一个有效正文,但服务器在应用策略配置的分支设置上崩溃了。 NewtonSoft 在开始时使用大写字母序列化 属性 名称,我发现使用小写字母修复了原始问题,然后创建的返回对象分配了 refName 和 matchKind 并勾选了 MinimumNumberOfReviewers 复选框并设置了数字到 2. 为什么 MS 无法仅序列化一个或两个属性有点奇怪,无论如何我在全球范围内应用了 JsonSerializationSettings 以避免需要在任何地方添加 JsonPropertyAttribute 以及忽略空属性。