-
Notifications
You must be signed in to change notification settings - Fork 274
/
open-pullrequest.ps1
29 lines (22 loc) · 1.06 KB
/
open-pullrequest.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
param(
[Parameter(Mandatory)]
[string]
$SourceBranch
)
# Getting a created PR. Result object has interface in accordance with article https://docs.github.com/en/rest/reference/pulls#get-a-pull-request
function Get-PullRequest() {
return (gh api -X GET repos/:owner/:repo/pulls -F head=":owner:$SourceBranch" -f state=open -f base=master | ConvertFrom-Json)
}
$openedPR = Get-PullRequest
if ($openedPR.html_url.length -ne 0) {
throw "A PR from $SourceBranch to master already exists."
}
$buildUrl = "$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI$env:SYSTEM_TEAMPROJECT/_build/results?buildId=$env:BUILD_BUILDID&_a=summary"
$body = "This PR was auto-generated with [the localization pipeline build]($buildUrl)."
gh pr create --head $SourceBranch --title 'Localization update' --body $body
# Getting a number to the opened PR
$PR_NUMBER = (Get-PullRequest).number
Write-Host "##vso[task.setvariable variable=PR_NUMBER]$PR_NUMBER"
# Getting a link to the opened PR
$PR_LINK = (Get-PullRequest).html_url
Write-Host "##vso[task.setvariable variable=PR_LINK]$PR_LINK"