Sync eng/common directory with azure-sdk-tools repository for Tools PR https://github.com/Azure/azure-sdk-tools/pull/881 (#484)
This commit is contained in:
parent
20039198a4
commit
d2e2c8db1b
@ -15,6 +15,8 @@ parameters:
|
||||
ScriptDirectory: eng/common/scripts
|
||||
GHReviewersVariable: ''
|
||||
GHTeamReviewersVariable: ''
|
||||
# Multiple labels seperated by comma, e.g. "bug, APIView"
|
||||
PRLabels: ''
|
||||
|
||||
steps:
|
||||
|
||||
@ -66,6 +68,7 @@ steps:
|
||||
-PRBranch "${{ parameters.PRBranchName }}"
|
||||
-AuthToken "$(azuresdk-github-pat)"
|
||||
-PRTitle "${{ parameters.PRTitle }}"
|
||||
-PRLabels "${{ parameters.PRLabels}}"
|
||||
-PRBody "${{ parameters.PRBody }}"
|
||||
|
||||
- task: PowerShell@2
|
||||
|
||||
@ -15,31 +15,37 @@ The owner of the branch we want to create a pull request for.
|
||||
The branch which we want to create a pull request for.
|
||||
.PARAMETER AuthToken
|
||||
A personal access token
|
||||
.PARAMETER PRTitle
|
||||
The title of the pull request.
|
||||
.PARAMETER PRLabels
|
||||
The labels added to the PRs. Multple labels seperated by comma, e.g "bug, service"
|
||||
#>
|
||||
[CmdletBinding(SupportsShouldProcess = $true)]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
$RepoOwner,
|
||||
[string]$RepoOwner,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
$RepoName,
|
||||
[string]$RepoName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
$BaseBranch,
|
||||
[string]$BaseBranch,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
$PROwner,
|
||||
[string]$PROwner,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
$PRBranch,
|
||||
[string]$PRBranch,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
$AuthToken,
|
||||
[string]$AuthToken,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
$PRTitle,
|
||||
[string]$PRTitle,
|
||||
$PRBody = $PRTitle,
|
||||
|
||||
$PRBody=$PRTitle
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$PRLabels
|
||||
)
|
||||
|
||||
$headers = @{
|
||||
@ -48,6 +54,31 @@ $headers = @{
|
||||
|
||||
$query = "state=open&head=${PROwner}:${PRBranch}&base=${BaseBranch}"
|
||||
|
||||
function AddLabels([int] $prNumber, [string] $prLabelString)
|
||||
{
|
||||
# Adding labels to the pr.
|
||||
if (-not $prLabelString) {
|
||||
Write-Verbose "There are no labels added to the PR."
|
||||
return
|
||||
}
|
||||
|
||||
# Parse the labels from string to array
|
||||
$prLabelArray = @($prLabelString.Split(",") | % { $_.Trim() } | ? { return $_ })
|
||||
$prLabelUri = "https://api.github.com/repos/$RepoOwner/$RepoName/issues/$prNumber"
|
||||
$labelRequestData = @{
|
||||
labels = $prLabelArray
|
||||
}
|
||||
try {
|
||||
$resp = Invoke-RestMethod -Method PATCH -Headers $headers $prLabelUri -Body ($labelRequestData | ConvertTo-Json)
|
||||
}
|
||||
catch {
|
||||
Write-Error "Invoke-RestMethod $prLabelUri failed with exception:`n$_"
|
||||
}
|
||||
|
||||
$resp | Write-Verbose
|
||||
Write-Host -f green "Label(s) [$prLabelArray] added to pull request: https://github.com/$RepoOwner/$RepoName/pull/$prNumber"
|
||||
}
|
||||
|
||||
try {
|
||||
$resp = Invoke-RestMethod -Headers $headers "https://api.github.com/repos/$RepoOwner/$RepoName/pulls?$query"
|
||||
}
|
||||
@ -62,6 +93,7 @@ if ($resp.Count -gt 0) {
|
||||
|
||||
# setting variable to reference the pull request by number
|
||||
Write-Host "##vso[task.setvariable variable=Submitted.PullRequest.Number]$($resp[0].number)"
|
||||
AddLabels $resp[0].number $PRLabels
|
||||
}
|
||||
else {
|
||||
$data = @{
|
||||
@ -87,4 +119,6 @@ else {
|
||||
|
||||
# setting variable to reference the pull request by number
|
||||
Write-Host "##vso[task.setvariable variable=Submitted.PullRequest.Number]$($resp.number)"
|
||||
|
||||
AddLabels $resp.number $PRLabels
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user