Skip to content

Commit

Permalink
Move summary script to Submit-PullRequest.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
hallipr committed May 28, 2024
1 parent 6be5762 commit 41b7d0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
21 changes: 16 additions & 5 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=$true
)

. (Join-Path $PSScriptRoot common.ps1)
Expand Down Expand Up @@ -106,33 +108,42 @@ else {
-AuthToken $AuthToken

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

$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 https://github.com/$RepoOwner/$RepoName/pull/$prNumber state to closed because this was only testing."
}
else {
$prState = "open"
}

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

if($AddBuildSummary) {
$summaryPath = "$(System.DefaultWorkingDirectory)/summary.md"
$summaryMarkdown = "**PR:** [Azure/$RepoName#$prNumber](https://github.com/Azure/$RepoName/pull/$prNumber)"
$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
10 changes: 0 additions & 10 deletions eng/pipelines/templates/stages/archetype-autorest-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,3 @@ stages:
-PRBody '$(PullRequestBody)'
-OpenAsDraft $true
-PRLabels 'Do Not Merge'
- pwsh: |
$summaryPath = "$(System.DefaultWorkingDirectory)/summary.md"
$summaryMarkdown = @"
**PR:** [Azure/$(sdkRepositoryName)#$(Submitted.PullRequest.Number)](https://github.com/Azure/$(sdkRepositoryName)/pull/$(Submitted.PullRequest.Number))
**Title:** $(PullRequestTitle)
"@
$summaryMarkdown | Out-File $summaryPath
Write-Host "##vso[task.addattachment type=Distributedtask.Core.Summary;name=Pull Request Created;]$summaryPath"
displayName: Write PR Data to build summary

0 comments on commit 41b7d0f

Please sign in to comment.