【问题标题】:Create an automatic PR and complete it Azure DevOps创建自动 PR 并完成它 Azure DevOps
【发布时间】:2020-10-17 21:32:44
【问题描述】:

我正在尝试创建一个流程,当来自分支 a -> b 的 PR 完成时,会创建并完成来自分支 c -> d 的自动 PR。

我查看了这个问题,但没有提到自动完成

CI/CD pipelines Azure devops automatic merge after deploy release

另外,我可以为自动 PR 设置一个特定的策略,让它自动完成吗?

更新

我尝试使用以下调用:

https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull%20requests/update?view=azure-devops-rest-5.1

但我得到了错误:

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Invalid argument value.\r\nParameter name: Invalid 
pull request auto complete set by id. Valid values are either the current user identity id, or an empty guid (to unset 
auto complete)."

我试图从响应中获取创建者 ID,但它是空的。

我尝试分配 Project Collection Build Service (msazure),就像我在这里看到的那样: https://developercommunity.visualstudio.com/content/problem/298596/autocompletesetby-ignored-in-pull-request-rest-api.html

但我得到了错误。

【问题讨论】:

  • 在您提供的链接中提到的扩展中,有一个选项可以将“自动完成”设置为您创建的 PR。 (免责声明:我是扩展作者)
  • @ShaykiAbramczyk,感谢您的回复。由于安全问题,我无法使用第 3 方扩展,因此我尝试在脚本中自己进行操作。为了完成 PR,我究竟需要传递什么作为 Id
  • “项目集合构建服务 (msazure)”是否适合使用?
  • 您是否尝试使用 PowerShell 进行更新?是在构建期间吗?
  • 是的,我正在尝试通过 Powershell 进行更新。当我尝试运行包含 powershell 脚本的特定步骤时会发生这种情况,所以我假设它在运行时而不是构建(如果我错了,请纠正我)

标签: azure-devops azure-pipelines azure-pipelines-release-pipeline azure-devops-rest-api azure-devops-extensions


【解决方案1】:

创建 PR 后可以获得创建者 ID:

$response = Invoke-RestMethod -Uri $url -Method Post -Headers $head -Body $jsonBody -ContentType "application/json;charset=UTF-8"

$currentUserId = $response.createdBy.id

并在更新json正文中发送给他:

$body = @{
    autoCompleteSetBy = @{ id = "$buildUserId" }
    completionOptions = ""
}    

$response = Invoke-RestMethod -Uri $url -Method Patch -Headers $head -Body $jsonBody -ContentType application/json

【讨论】:

    【解决方案2】:

    在此处创建 PR 后,运行更新操作以设置 Autocomplet。检查以下链接

    https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull%20requests/update?view=azure-devops-rest-5.1

    【讨论】:

    • 更新了原始帖子 - 我正在尝试使用此 API,但出现错误(如上所述)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-19
    • 1970-01-01
    • 2020-05-11
    • 1970-01-01
    相关资源
    最近更新 更多