Skip to content

Commit 8142b48

Browse files
authored
Sync eng/common directory with azure-sdk-tools repository for Tools PR Azure/azure-sdk-tools#881 (#14239)
1 parent ba5ce16 commit 8142b48

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

eng/common/pipelines/templates/steps/create-pull-request.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ parameters:
1515
ScriptDirectory: eng/common/scripts
1616
GHReviewersVariable: ''
1717
GHTeamReviewersVariable: ''
18+
# Multiple labels seperated by comma, e.g. "bug, APIView"
19+
PRLabels: ''
1820

1921
steps:
2022

@@ -66,6 +68,7 @@ steps:
6668
-PRBranch "${{ parameters.PRBranchName }}"
6769
-AuthToken "$(azuresdk-github-pat)"
6870
-PRTitle "${{ parameters.PRTitle }}"
71+
-PRLabels "${{ parameters.PRLabels}}"
6972
-PRBody "${{ parameters.PRBody }}"
7073
7174
- task: PowerShell@2

eng/common/scripts/Submit-PullRequest.ps1

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,37 @@ The owner of the branch we want to create a pull request for.
1515
The branch which we want to create a pull request for.
1616
.PARAMETER AuthToken
1717
A personal access token
18+
.PARAMETER PRTitle
19+
The title of the pull request.
20+
.PARAMETER PRLabels
21+
The labels added to the PRs. Multple labels seperated by comma, e.g "bug, service"
1822
#>
1923
[CmdletBinding(SupportsShouldProcess = $true)]
2024
param(
2125
[Parameter(Mandatory = $true)]
22-
$RepoOwner,
26+
[string]$RepoOwner,
2327

2428
[Parameter(Mandatory = $true)]
25-
$RepoName,
29+
[string]$RepoName,
2630

2731
[Parameter(Mandatory = $true)]
28-
$BaseBranch,
32+
[string]$BaseBranch,
2933

3034
[Parameter(Mandatory = $true)]
31-
$PROwner,
35+
[string]$PROwner,
3236

3337
[Parameter(Mandatory = $true)]
34-
$PRBranch,
38+
[string]$PRBranch,
3539

3640
[Parameter(Mandatory = $true)]
37-
$AuthToken,
41+
[string]$AuthToken,
3842

3943
[Parameter(Mandatory = $true)]
40-
$PRTitle,
44+
[string]$PRTitle,
45+
$PRBody = $PRTitle,
4146

42-
$PRBody=$PRTitle
47+
[Parameter(Mandatory = $false)]
48+
[string]$PRLabels
4349
)
4450

4551
$headers = @{
@@ -48,6 +54,31 @@ $headers = @{
4854

4955
$query = "state=open&head=${PROwner}:${PRBranch}&base=${BaseBranch}"
5056

57+
function AddLabels([int] $prNumber, [string] $prLabelString)
58+
{
59+
# Adding labels to the pr.
60+
if (-not $prLabelString) {
61+
Write-Verbose "There are no labels added to the PR."
62+
return
63+
}
64+
65+
# Parse the labels from string to array
66+
$prLabelArray = @($prLabelString.Split(",") | % { $_.Trim() } | ? { return $_ })
67+
$prLabelUri = "https://api.github.com/repos/$RepoOwner/$RepoName/issues/$prNumber"
68+
$labelRequestData = @{
69+
labels = $prLabelArray
70+
}
71+
try {
72+
$resp = Invoke-RestMethod -Method PATCH -Headers $headers $prLabelUri -Body ($labelRequestData | ConvertTo-Json)
73+
}
74+
catch {
75+
Write-Error "Invoke-RestMethod $prLabelUri failed with exception:`n$_"
76+
}
77+
78+
$resp | Write-Verbose
79+
Write-Host -f green "Label(s) [$prLabelArray] added to pull request: https://github.com/$RepoOwner/$RepoName/pull/$prNumber"
80+
}
81+
5182
try {
5283
$resp = Invoke-RestMethod -Headers $headers "https://api.github.com/repos/$RepoOwner/$RepoName/pulls?$query"
5384
}
@@ -62,6 +93,7 @@ if ($resp.Count -gt 0) {
6293

6394
# setting variable to reference the pull request by number
6495
Write-Host "##vso[task.setvariable variable=Submitted.PullRequest.Number]$($resp[0].number)"
96+
AddLabels $resp[0].number $PRLabels
6597
}
6698
else {
6799
$data = @{
@@ -87,4 +119,6 @@ else {
87119

88120
# setting variable to reference the pull request by number
89121
Write-Host "##vso[task.setvariable variable=Submitted.PullRequest.Number]$($resp.number)"
122+
123+
AddLabels $resp.number $PRLabels
90124
}

0 commit comments

Comments
 (0)