Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions eng/common/scripts/Submit-PullRequest.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env pwsh -c
#!/usr/bin/env pwsh -c

<#
.DESCRIPTION
Expand Down Expand Up @@ -38,6 +38,10 @@ Close the PR after opening to save on CI resources and prevent alerts to code
owners, assignees, requested reviewers, or others.
.PARAMETER OpenAsDraft
Opens the PR as a draft
.PARAMETER AddBuildSummary
Whether to add an Azure DevOps build summary attachment for the created or existing PR.
.PARAMETER UpdateExistingPullRequest
Whether to update the existing PR title and body when the PR already exists. Defaults to false to preserve current behavior for existing callers.
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
Expand Down Expand Up @@ -79,7 +83,9 @@ param(

[boolean]$MaintainerCanModify=$true,

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

[boolean]$UpdateExistingPullRequest=$false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we should use [switch] type parameters instead of boolean flags, though I guess this script is already using boolean so probably better to stay consistent?

)

. (Join-Path $PSScriptRoot common.ps1)
Expand All @@ -101,14 +107,28 @@ if ($resp.Count -gt 0) {
$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]$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"

try {
if ($UpdateExistingPullRequest) {
Update-GitHubIssue -RepoOwner $RepoOwner -RepoName $RepoName -IssueNumber $existingNumber `
-Title $PRTitle -Body $PRBody -AuthToken $AuthToken | Out-Null
$existingTitle = $PRTitle
LogDebug "Updated existing pull request $existingUrl title and body"
}

# setting variable to reference the pull request by 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"
Comment thread
raych1 marked this conversation as resolved.
$summaryMarkdown | Out-File $summaryPath
Write-Host "##vso[task.addattachment type=Distributedtask.Core.Summary;name=Existing Pull Request;]$summaryPath"
}
}
catch {
LogError "Failed to process existing pull request $existingUrl with exception:`n$_"
exit 1
}
}
else {
Expand Down
Loading