我有以下脚本通过 Azure DevOps 自动创建 PR:
CreatePRBuildTask.ps1
$user = ""
$branchTarget = "refs/heads/main"
$branchSource = "refs/heads/develop"
$branchTargetPath = $branchTarget -replace "refs/heads/", ""
$teamProject = "Project"
$repoName = "Repo"
$organization = "Org"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$uriCheckActivePR = "https://dev.azure.com/$organization/$teamProject/_apis/git/repositories/$repoName/pullrequests?searchCriteria.targetRefName=$branchTarget&searchCriteria.sourceRefName=$branchSource&api-version=5.1"
$uriCreatePR = "https://dev.azure.com/$organization/$teamProject/_apis/git/repositories/$repoName/pullrequests?api-version=5.1"
$bodyCreatePR = "{sourceRefName:'$branchSource',targetRefName:'$branchTarget',title:'Sync changes from $branchSource'}"
$result = Invoke-RestMethod -Uri $uriCreatePR -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $bodyCreatePR
Write-Host "Created PR" $result.pullRequestId
这将创建 PR。有没有办法找出源分支和目标分支中的最新提交是否不同,然后创建 PR?如果提交相同,不创建 PR?