我正在尝试更新 Azure DevOps 存储库中分支的分支策略。我正在尝试使用 Rest API 调用来执行此操作,遵循 here 的文档。
当我从 Postman 运行此命令时,请求成功完成,状态代码为“200 OK”。在检查 Azure DevOps 中分支策略的状态时,我可以看到“限制合并类型”选项处于“打开”状态,但是,“允许的合并类型:”下没有选中任何复选框。
这是我使用的 json 有效负载。
POST https://dev.azure.com/{{Org}}/{{ProjectName}}/_apis/policy/configurations?api-version=7.0
{
"isEnabled": true,
"isBlocking": true,
"type": {
"id": "fa4e907d-c16b-4a4c-9dfa-4916e5d171ab"
},
"settings": {
"useSquashMerge": true,
"scope": [
{
"refName": "refs/heads/test_branch_for_policy",
"matchKind": "exact",
"repositoryId": "11223344-480x-4u1h-x16k-112233445566"
}
]
}
}
看来
"useSquashMerge": true
下的settings
没有被考虑。
TL;DR 使用
allowSquash
而不是 useSquashMerge
。
这在使用 Azure DevOps Services(云)时有效,不确定 Azure DevOps Server(托管)。
做了一些研究,我能够在
自动化分支策略中找到似乎是配置分支策略的
Limit Merge Types
部分的正确设置:
useSquashMerge
allowNoFastForward
allowSquash
allowRebase
allowRebaseMerge
除了
useSquashMerge
之外,所有设置都适用于 Azure DevOps Services。我找不到太多有关它的信息,但它似乎在 TFS / Azure DevOps Server 中使用 - 请参阅合并策略策略设置不一致。
在Postman上执行以下代码请求:
https://dev.azure.com/my-organization/my-project/_apis/policy/configurations?api-version=7.0
请求正文:
{
"isEnabled": true,
"isBlocking": true,
"type": {
"id": "fa4e907d-c16b-4a4c-9dfa-4916e5d171ab"
},
"settings": {
"allowSquash": true,
"useSquashMerge": true,
"allowRebaseMerge": false,
"allowRebase": false,
"allowNoFastForward": false,
"scope": [
{
"repositoryId": "1xxxx516-aaaa-4ce4-xxxx-d56abbbbb6ec",
"refName": "refs/heads/main",
"matchKind": "exact"
}
]
}
}
回应:
{
"createdBy": {
"displayName": "Some user",
"url": "https://spsprodeus21.vssps.visualstudio.com/xxxx-xxxx-xxxx-xxxx-xxxx/_apis/Identities/xxxx-xxxx-xxxx-xxxx-xxxx",
"_links": {
"avatar": {
"href": "https://dev.azure.com/my-organization/_apis/GraphProfile/MemberAvatars/aad.xxxxxx"
}
},
"id": "7af0d439-aa9b-40cf-93a4-fb725b0694a7",
"uniqueName": "[email protected]",
"imageUrl": "https://dev.azure.com/my-organization/_api/_common/identityImage?id=xxxx-xxxx-xxxx-xxxx-xxxx",
"descriptor": "aad.xxxxxx"
},
"createdDate": "2024-07-13T13:18:59.5387814",
"isEnabled": true,
"isBlocking": true,
"isDeleted": false,
"settings": {
"useSquashMerge": true,
"allowNoFastForward": true,
"allowSquash": true,
"allowRebase": true,
"allowRebaseMerge": true,
"scope": [
{
"refName": "refs/heads/main",
"matchKind": "Exact",
"repositoryId": "1xxxx516-aaaa-4ce4-xxxx-d56abbbbb6ec"
}
]
},
"isEnterpriseManaged": false,
"_links": {
"self": {
"href": "https://dev.azure.com/my-organization/xxxx-xxxx-xxxx-xxxx-xxxx/_apis/policy/configurations/75"
},
"policyType": {
"href": "https://dev.azure.com/my-organization/xxxx-xxxx-xxxx-xxxx-xxxx/_apis/policy/types/xxxx-xxxx-xxxx-xxxx-xxxx"
}
},
"revision": 1,
"id": 75,
"url": "https://dev.azure.com/my-organization/xxxx-xxxx-xxxx-xxxx-xxxx/_apis/policy/configurations/75",
"type": {
"id": "xxxx-xxxx-xxxx-xxxx-xxxx",
"url": "https://dev.azure.com/my-organization/xxxx-xxxx-xxxx-xxxx-xxxx/_apis/policy/types/xxxx-xxxx-xxxx-xxxx-xxxx",
"displayName": "Require a merge strategy"
}
}