How can I create a Pull Request when a release com

2019-08-16 02:52发布

A project I'm working on has 2 long-standing feature branches as well as the master branch.

To fully automate deployments, I'd like to create a pull request from master into those two feature branches anytime a deployment goes out from a VSTS Release.

What kind of tooling in VSTS would allow me to do create pull requests as a release task?

1条回答
萌系小妹纸
2楼-- · 2019-08-16 03:17

You can create the Pull Request through Pull Request REST API during the release.

There is Invoke HTTP REST API task but may not good for your requirement.

The simple way is that you can do it through PowerShell task:

  1. Select the phase (e.g. Run on agent) and check Allow scripts to access OAuth token option. You can use Personal Access Token too.
  2. Add PowerShell task

Simple sample:

param(
[string]$project,
[string]$repo,
[string]$sourceBranch,
[string]$targetBranch,
[string]$title,
[string]$des,
[string]$token
)
$bodyObj=@{
  "sourceRefName"="refs/heads/$sourceBranch";
  "targetRefName"= "refs/heads/$targetBranch";
  "title"= "$title";
  "description"="$des";
}
$bodyJson=$bodyObj| ConvertTo-Json
$uri="https://XXX.visualstudio.com/DefaultCollection/$project/_apis/git/repositories/$repo/pullRequests?api-version=3.0"
Write-Output $bodyJson
Write-Output $uri
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "test",$token)))
$result= Invoke-RestMethod -Method POST -Uri $Uri -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $bodyJson

Arguments: -project "XXX" -repo "XXX" -sourceBranch "XX" -targetBranch "XX" -title "XX" -des "XX" -token [$(System.AccessToken) or personal access token]

查看更多
登录 后发表回答