From 20d5d3c2123cf9a897f632971a7c0ee63137b984 Mon Sep 17 00:00:00 2001 From: Patrick Hallisey Date: Tue, 28 May 2024 08:25:25 -0700 Subject: [PATCH 1/2] Reuse same branch name for previews of a PR --- eng/common/scripts/Submit-PullRequest.ps1 | 39 ++++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/eng/common/scripts/Submit-PullRequest.ps1 b/eng/common/scripts/Submit-PullRequest.ps1 index f272ba479e3fd..ed4b4d8a168f2 100644 --- a/eng/common/scripts/Submit-PullRequest.ps1 +++ b/eng/common/scripts/Submit-PullRequest.ps1 @@ -71,7 +71,9 @@ param( [boolean]$CloseAfterOpenForTesting=$false, - [boolean]$OpenAsDraft=$false + [boolean]$OpenAsDraft=$false, + + [boolean]$AddBuildSummary=$true ) . (Join-Path $PSScriptRoot common.ps1) @@ -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 { @@ -106,12 +119,14 @@ 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 @@ -119,20 +134,28 @@ else { $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$_" From d9837b969276fe648d20c725860b9451b1291bd1 Mon Sep 17 00:00:00 2001 From: Patrick Hallisey Date: Tue, 28 May 2024 15:34:45 -0700 Subject: [PATCH 2/2] Default AddBuildSummary parameter using pipeline variable existence --- eng/common/scripts/Submit-PullRequest.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/Submit-PullRequest.ps1 b/eng/common/scripts/Submit-PullRequest.ps1 index ed4b4d8a168f2..a4c6545b8cafb 100644 --- a/eng/common/scripts/Submit-PullRequest.ps1 +++ b/eng/common/scripts/Submit-PullRequest.ps1 @@ -73,7 +73,7 @@ param( [boolean]$OpenAsDraft=$false, - [boolean]$AddBuildSummary=$true + [boolean]$AddBuildSummary=($null -ne $env:SYSTEM_TEAMPROJECTID) ) . (Join-Path $PSScriptRoot common.ps1)