Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 1478 #17580

Merged
merged 11 commits into from
Mar 26, 2021
6 changes: 3 additions & 3 deletions eng/common/pipelines/templates/steps/create-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ steps:
-PRTitle "${{ parameters.PRTitle }}"
-PRBody "${{ coalesce(parameters.PRBody, parameters.CommitMsg, parameters.PRTitle) }}"
-PRLabels "${{ parameters.PRLabels }}"
-UserReviewers "${{ parameters.GHReviewersVariable }}"
-TeamReviewers "${{ parameters.GHTeamReviewersVariable }}"
-Assignees "${{ parameters.GHAssignessVariable }}"
-UserReviewers "$(${{ parameters.GHReviewersVariable }})"
-TeamReviewers "$(${{ parameters.GHTeamReviewersVariable }})"
-Assignees "$(${{ parameters.GHAssignessVariable }})"
-CloseAfterOpenForTesting $${{ coalesce(parameters.CloseAfterOpenForTesting, 'false') }}
-OpenAsDraft $${{ parameters.OpenAsDraft }}
29 changes: 19 additions & 10 deletions eng/common/scripts/Invoke-GitHubAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,27 @@ function Get-GitHubApiHeaders ($token) {
return $headers
}

function Set-GitHubAPIParameters ($members, $parameterName, $parameters, $allowEmptyMembers=$false) {
if ($null -ne $members) {
if ($members -is [array])
{
$parameters[$parameterName] = $members
}
else {
$memberAdditions = @($members.Split(",") | % { $_.Trim() } | ? { return $_ })
if (($memberAdditions.Count -gt 0) -or $allowEmptyMembers) {
$parameters[$parameterName] = $memberAdditions
function SplitParameterArray($members) {
if ($null -ne $members) {
if ($members -is [array])
{
return $members
}
else {
return (@($members.Split(",") | % { $_.Trim() } | ? { return $_ }))
}
}
}

function Set-GitHubAPIParameters ($members, $parameterName, $parameters, $allowEmptyMembers = $false) {
if ($null -ne $members) {
[array]$memberAdditions = SplitParameterArray -members $members

if ($null -eq $memberAdditions -and $allowEmptyMembers){ $memberAdditions = @() }

if ($memberAdditions.Count -gt 0 -or $allowEmptyMembers) {
$parameters[$parameterName] = $memberAdditions
}
}

return $parameters
Expand Down
11 changes: 9 additions & 2 deletions eng/common/scripts/Submit-PullRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,19 @@ else {
$resp | Write-Verbose
LogDebug "Pull request created https://github.com/$RepoOwner/$RepoName/pull/$($resp.number)"

$prOwnerUser = $resp.user.login

# setting variable to reference the pull request by number
Write-Host "##vso[task.setvariable variable=Submitted.PullRequest.Number]$($resp.number)"

if ($UserReviewers -or $TeamReviewers) {
# ensure that the user that was used to create the PR is not attempted to add as a reviewer
# we cast to an array to ensure that length-1 arrays actually stay as array values
$cleanedUsers = @(SplitParameterArray -members $UserReviewers) | ? { $_ -ne $prOwnerUser -and $null -ne $_ }
$cleanedTeamReviewers = @(SplitParameterArray -members $TeamReviewers) | ? { $_ -ne $prOwnerUser -and $null -ne $_ }

if ($cleanedUsers -or $cleanedTeamReviewers) {
Add-GitHubPullRequestReviewers -RepoOwner $RepoOwner -RepoName $RepoName -PrNumber $resp.number `
-Users $UserReviewers -Teams $TeamReviewers -AuthToken $AuthToken
-Users $cleanedUsers -Teams $cleanedTeamReviewers -AuthToken $AuthToken
}

if ($CloseAfterOpenForTesting) {
Expand Down