使用 GitPullRequestCompletionOptions 在 Azure DevOps 拉取请求上强制执行 Squash 合并
Enforcing a Squash merge on Azure DevOps Pull Request using GitPullRequestCompletionOptions
我正在尝试使用 Azure DevOps 服务 REST API 来设置 PR Completion Options 以对拉取请求强制执行压缩合并。
注意:我无法设置分支策略来强制执行挤压合并,因为我正在测试某些条件以查看是否需要挤压合并并尝试强制执行一个壁球,就好像分支策略只为那个 PR 设置了一样。
当我进行以下调用时:
PATCH https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}?api-version=5.0
{
"completionOptions": {
"squashMerge": true
}
}
响应显示值已设置
然而,在尝试完成请求时,我希望 "Squash changes when merging" 复选框被选中并禁用。
如果我按原样保留表单并完成合并,则不会执行压缩。
如果我将 bypassPolicy
设置为 true,我仍然看不出完成选项有什么不同。
所以总而言之,我知道调用是成功的,因为响应返回时设置了选项,但更改似乎没有传递到 Azure DevOps 中的拉取请求。
Microsoft 在 the developer community forums 中做出了以下答复。
In this case there is a difference between expected behavior in the UI
and via the REST endpoint. Setting squashMerge in completion options
tells the PR to complete with a squash only if you complete it with
the REST endpoint. In the user interface we respect user settings to
enable users to choose what they would like to do (if there is no
policy enabled). In this case, you did not enable a policy so a user
can either squash or not. The users preference actually supersedes
what you do with the REST API. If they squash merged the previous PR
we will remember this and create the same default for them on the next
PR.
TLDR: You cannot necessarily control the form default values with
the REST endpoint and should use policy to enforce squash merge (or
expect your users can set the checkbox or not depending on their
preference, but we do not force a default).
您可以使用强制执行此操作的策略。
如果您转到 DevOps 中的分支机构,select 您的分支机构 -> 策略您只能允许壁球合并:
这应该使所有拉取请求都进入由要使用压缩合并完成的策略绑定的分支。
以下是 Set auto-complete 的工作原理:
我不这么认为。
分支政策与点击自动完成时看到的内容
我正在尝试使用 Azure DevOps 服务 REST API 来设置 PR Completion Options 以对拉取请求强制执行压缩合并。
注意:我无法设置分支策略来强制执行挤压合并,因为我正在测试某些条件以查看是否需要挤压合并并尝试强制执行一个壁球,就好像分支策略只为那个 PR 设置了一样。
当我进行以下调用时:
PATCH https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}?api-version=5.0
{
"completionOptions": {
"squashMerge": true
}
}
响应显示值已设置
然而,在尝试完成请求时,我希望 "Squash changes when merging" 复选框被选中并禁用。
如果我按原样保留表单并完成合并,则不会执行压缩。
如果我将 bypassPolicy
设置为 true,我仍然看不出完成选项有什么不同。
所以总而言之,我知道调用是成功的,因为响应返回时设置了选项,但更改似乎没有传递到 Azure DevOps 中的拉取请求。
Microsoft 在 the developer community forums 中做出了以下答复。
In this case there is a difference between expected behavior in the UI and via the REST endpoint. Setting squashMerge in completion options tells the PR to complete with a squash only if you complete it with the REST endpoint. In the user interface we respect user settings to enable users to choose what they would like to do (if there is no policy enabled). In this case, you did not enable a policy so a user can either squash or not. The users preference actually supersedes what you do with the REST API. If they squash merged the previous PR we will remember this and create the same default for them on the next PR.
TLDR: You cannot necessarily control the form default values with the REST endpoint and should use policy to enforce squash merge (or expect your users can set the checkbox or not depending on their preference, but we do not force a default).
您可以使用强制执行此操作的策略。
如果您转到 DevOps 中的分支机构,select 您的分支机构 -> 策略您只能允许壁球合并:
这应该使所有拉取请求都进入由要使用压缩合并完成的策略绑定的分支。
以下是 Set auto-complete 的工作原理:
我不这么认为。
分支政策与点击自动完成时看到的内容