I have the following script to create a PR via Azure DevOps automatically:
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)))
$uriBranchStatus = "https://dev.azure.com/$organization/$teamProject/_apis/git/repositories/$repoName/stats/branches?name=$branchTargetPath&api-version=5.1"
$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
This creates the PR. $result.createdBy.url show a page containing this info:
From where do I get the actual link to the created PR?