Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 8324 (#29839)
Browse files Browse the repository at this point in the history
Sync eng/common directory with azure-sdk-tools for PR
Azure/azure-sdk-tools#8324 See [eng/common
workflow](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/README.md#workflow)

---------

Co-authored-by: Patrick Hallisey <pahallis@microsoft.com>
  • Loading branch information
azure-sdk and hallipr committed May 30, 2024
1 parent 6d9d599 commit 0877a38
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions eng/common/scripts/Submit-PullRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ param(

[boolean]$CloseAfterOpenForTesting=$false,

[boolean]$OpenAsDraft=$false
[boolean]$OpenAsDraft=$false,

[boolean]$AddBuildSummary=($null -ne $env:SYSTEM_TEAMPROJECTID)
)

. (Join-Path $PSScriptRoot common.ps1)
Expand All @@ -88,9 +90,20 @@ catch {
$resp | Write-Verbose

if ($resp.Count -gt 0) {
LogDebug "Pull request already exists $($resp[0].html_url)"
$existingPr = $resp[0]
$existingUrl = $existingPr.html_url
$existingNumber = $existingPr.number
$existingTitle = $existingPr.title
LogDebug "Pull request already exists $existingUrl"
# setting variable to reference the pull request by number
Write-Host "##vso[task.setvariable variable=Submitted.PullRequest.Number]$($resp[0].number)"
Write-Host "##vso[task.setvariable variable=Submitted.PullRequest.Number]$existingNumber"
if ($AddBuildSummary) {
$summaryPath = New-TemporaryFile
$summaryMarkdown = "**PR:** [Azure/$RepoName#$existingNumber]($existingUrl)"
$summaryMarkdown += "`n**Title:** $existingTitle"
$summaryMarkdown | Out-File $summaryPath
Write-Host "##vso[task.addattachment type=Distributedtask.Core.Summary;name=Existing Pull Request;]$summaryPath"
}
}
else {
try {
Expand All @@ -106,33 +119,43 @@ else {
-AuthToken $AuthToken

$resp | Write-Verbose
LogDebug "Pull request created https://github.com/$RepoOwner/$RepoName/pull/$($resp.number)"
$prNumber = $resp.number
$prUrl = $resp.html_url
LogDebug "Pull request created $prUrl"

$prOwnerUser = $resp.user.login

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

# 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 `
Add-GitHubPullRequestReviewers -RepoOwner $RepoOwner -RepoName $RepoName -PrNumber $prNumber `
-Users $cleanedUsers -Teams $cleanedTeamReviewers -AuthToken $AuthToken
}

if ($CloseAfterOpenForTesting) {
$prState = "closed"
LogDebug "Updating https://github.com/$RepoOwner/$RepoName/pull/$($resp.number) state to closed because this was only testing."
LogDebug "Updating $prUrl state to closed because this was only testing."
}
else {
$prState = "open"
}

Update-GitHubIssue -RepoOwner $RepoOwner -RepoName $RepoName -IssueNumber $resp.number `
Update-GitHubIssue -RepoOwner $RepoOwner -RepoName $RepoName -IssueNumber $prNumber `
-State $prState -Labels $PRLabels -Assignees $Assignees -AuthToken $AuthToken

if ($AddBuildSummary) {
$summaryPath = New-TemporaryFile
$summaryMarkdown = "**PR:** [Azure/$RepoName#$prNumber]($prUrl)"
$summaryMarkdown += "`n**Title:** $PRTitle"
$summaryMarkdown | Out-File $summaryPath
Write-Host "##vso[task.addattachment type=Distributedtask.Core.Summary;name=Pull Request Created;]$summaryPath"
}
}
catch {
LogError "Call to GitHub API failed with exception:`n$_"
Expand Down

0 comments on commit 0877a38

Please sign in to comment.