Add Merge-DevPullRequest cmdlet and update documentation#28718
Add Merge-DevPullRequest cmdlet and update documentation#28718isra-fel merged 10 commits intoAzure:mainfrom
Conversation
- Introduced `Merge-DevPullRequest` cmdlet to facilitate merging pull requests in the azure-powershell repository. - Updated README.md to include usage instructions for the new cmdlet. - Added entry to CHANGELOG.md for the new feature. - Modified AzDev.psd1 to export the new cmdlet and its alias.
| Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status. |
There was a problem hiding this comment.
Pull Request Overview
Adds a new Merge-DevPullRequest cmdlet (alias Merge-DevPR) to assist with approving and merging pull requests in the azure-powershell repository. Updates documentation (README, CHANGELOG) and exports the new function and alias in AzDev.psd1.
- Introduces GitHub.psm1 with Merge-DevPullRequest implementation.
- Updates module manifest to load and export the new function and alias.
- Adds README usage and CHANGELOG entry for the new feature.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| tools/AzDev/README.md | Documents new GitHub helper section and usage examples for Merge-DevPullRequest. |
| tools/AzDev/CHANGELOG.md | Adds dated entry describing new cmdlet feature. |
| tools/AzDev/AzDev/GitHub.psm1 | Implements Merge-DevPullRequest cmdlet logic and exports it. |
| tools/AzDev/AzDev/AzDev.psd1 | Registers new nested module, function export, and alias. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
DanielMicrosoft
left a comment
There was a problem hiding this comment.
I think there is some valid points from Copilot we can address before merging.
|
This PR was labeled "needs-revision" because it has unresolved review comments or CI failures. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
tools/AzDev/AzDev/GitHub.psm1
Outdated
| 'No.' = $_.number | ||
| 'Title' = $_.title | ||
| 'CreatedBy' = $_.author.login | ||
| 'CreatedAt' = ([DateTime]::Parse($_.createdAt).ToUniversalTime().ToString('M/d/yyyy h:mm:ss tt')) |
There was a problem hiding this comment.
@isra-fel Realized this format is diff to L139, not sure if desired.
There was a problem hiding this comment.
You are right. Let me remove the ToUniversalTime() as it's UTC and is inconvenient.
| try { | ||
| $prJson = gh pr view $prNumber --json number,title,author,createdAt,url 2>$null | ||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "Pull request #$prNumber not found." |
There was a problem hiding this comment.
gh pr ... commands here rely on the current working directory being the Azure/azure-powershell git repo. If the user runs this cmdlet from a different folder (or not in a git repo), gh will target the wrong repo or fail. Consider either (a) adding --repo Azure/azure-powershell to every gh invocation, or (b) using Get-DevContext and temporarily Push-Location to the configured repo root before running any gh commands.
| try { | ||
| $allPRsJson = gh pr list --state open --author azure-powershell-bot --json number,title,author,createdAt,url 2>$null | ||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "Failed to list pull requests." | ||
| } |
There was a problem hiding this comment.
gh pr list defaults to a limited number of PRs (typically 30). With -AllArchivePR, this can silently miss older archive PRs, contradicting the intent to merge “all” matching PRs. Pass an explicit --limit (or implement pagination) so the full set is considered before filtering/sorting.
| # Merge PR | ||
| Write-Host " Merging PR #$($pr.number)..." -ForegroundColor Cyan | ||
| gh pr merge $pr.number --squash 2>$null | ||
| if ($LASTEXITCODE -ne 0) { |
There was a problem hiding this comment.
-Force currently only skips this script’s confirmation prompt, but gh pr merge can still prompt for confirmation interactively. Add --yes (and any other non-interactive flags you require) to the gh pr merge invocation so the cmdlet is fully non-interactive when -Force is used.
| 'CreatedBy' = $_.author.login | ||
| 'CreatedAt' = [DateTime]::Parse($_.createdAt).ToString('M/d/yyyy h:mm:ss tt') | ||
| 'Url' = $_.url |
There was a problem hiding this comment.
The CreatedAt formatting uses a culture-dependent pattern (M/d/yyyy h:mm:ss tt), which can be ambiguous and vary by locale. Prefer returning a DateTime (letting callers format) or formatting using an invariant/ISO-8601 representation (ideally UTC) for consistent output.
| catch { | ||
| Write-Error "Failed to merge PR #$($pr.number): $_" | ||
| $failedPRs += $pr | ||
| } | ||
| } | ||
|
|
||
| # Report results | ||
| if ($mergedPRs.Count -gt 0) { | ||
| Write-Host "`nSuccessfully merged $($mergedPRs.Count) pull request(s)." -ForegroundColor Green | ||
| } | ||
|
|
||
| if ($failedPRs.Count -gt 0) { | ||
| $errorMessage = "Failed to merge $($failedPRs.Count) pull request(s): $($failedPRs.number -join ', ')" | ||
| Write-Error $errorMessage | ||
| throw $errorMessage |
There was a problem hiding this comment.
Errors are emitted twice for failed merges: once in the per-PR catch (Write-Error ...) and again in the summary block before throwing. This can create noisy/duplicated error output. Consider collecting failure details in the loop (without Write-Error), then emitting a single consolidated terminating error at the end (or a single summary Write-Error if you want non-terminating behavior).
| function Merge-DevPullRequest { | ||
| <# | ||
| .SYNOPSIS | ||
| Merges pull requests in the azure-powershell repository. | ||
|
|
||
| .DESCRIPTION | ||
| Helps merge pull requests in the azure-powershell repo. When using -AllArchivePR, for safety, | ||
| it only supports merging PRs with the "[skip ci]" prefix in the title and created by the | ||
| "azure-powershell-bot" user, which are the archive PRs for generated modules. | ||
| When using -Number, any PR can be merged. | ||
|
|
||
| .PARAMETER Number | ||
| The pull request number(s) to merge. Can be a single number or an array of numbers. | ||
|
|
||
| .PARAMETER AllArchivePR | ||
| Lists all matching PRs (ordered by CreatedAt ascending) and prompts for confirmation before merging. | ||
|
|
||
| .PARAMETER Approve | ||
| Approve the pull request before merging. | ||
|
|
||
| .PARAMETER Force | ||
| Skip confirmation prompts. | ||
|
|
||
| .EXAMPLE | ||
| Merge-DevPullRequest -Approve -Number 28690 | ||
|
|
||
| .EXAMPLE | ||
| Merge-DevPullRequest -Approve -Number 28690, 28691, 28692 | ||
|
|
||
| .EXAMPLE | ||
| Merge-DevPullRequest -Approve -AllArchivePR -Force | ||
|
|
||
| .NOTES | ||
| Requires GitHub CLI to be installed and authenticated (gh auth login). | ||
| #> | ||
| [CmdletBinding(DefaultParameterSetName = 'Single')] | ||
| [Alias('Merge-DevPR')] | ||
| param( | ||
| [Parameter(Mandatory = $true, ParameterSetName = 'Single')] | ||
| [int[]]$Number, | ||
|
|
||
| [Parameter(Mandatory = $true, ParameterSetName = 'All')] | ||
| [switch]$AllArchivePR, | ||
|
|
||
| [switch]$Approve, | ||
|
|
||
| [switch]$Force | ||
| ) |
There was a problem hiding this comment.
There are existing Pester tests for AzDev cmdlets, but this new cmdlet has no automated coverage. Add Pester tests that mock the gh executable to validate: (1) -AllArchivePR filtering/sorting behavior, (2) -Force skips prompting, and (3) failures produce a terminating error (and don’t attempt to merge unapproved PRs unless -Approve is set).
| Do you want to approve and merge the following pull request? | ||
| - 28690 [skip ci] Archive e36b0a91ac13ad8c173760dab2d1c038495d41cc | ||
| Type Y to approve and merge, N to cancel: Y | ||
|
|
||
| No. Title CreatedBy CreatedAt Url | ||
| --- ----- --------- --------- --- | ||
| 28690 [skip ci] Archive e36b0a91ac13ad8c173760dab2d1c038495d41cc azure-powershell-bot 6/10/2024 2:15:30 PM | ||
|
|
||
| PS C:\> Merge-DevPullRequest -Approve -AllArchivePR -Force | ||
|
|
||
| No. Title CreatedBy CreatedAt Url | ||
| --- ----- --------- --------- --- | ||
| 28690 [skip ci] Archive e36b0a91ac13ad8c173760dab2d1c038495d41cc azure-powershell-bot 6/10/2024 2:15:30 PM | ||
| 28689 [skip ci] Archive deed8db801365cc26557b46c7a8a01d134f0b524 azure-powershell-bot 6/29/2024 11:05:12 AM |
There was a problem hiding this comment.
The example output during confirmation shows a bullet list (- 28690 ...), but the cmdlet currently prints a formatted table before prompting (via Format-Table | ... | Write-Host). Update the example to match the actual prompt-time output, or adjust the cmdlet to print the list format shown here.
| Do you want to approve and merge the following pull request? | |
| - 28690 [skip ci] Archive e36b0a91ac13ad8c173760dab2d1c038495d41cc | |
| Type Y to approve and merge, N to cancel: Y | |
| No. Title CreatedBy CreatedAt Url | |
| --- ----- --------- --------- --- | |
| 28690 [skip ci] Archive e36b0a91ac13ad8c173760dab2d1c038495d41cc azure-powershell-bot 6/10/2024 2:15:30 PM | |
| PS C:\> Merge-DevPullRequest -Approve -AllArchivePR -Force | |
| No. Title CreatedBy CreatedAt Url | |
| --- ----- --------- --------- --- | |
| 28690 [skip ci] Archive e36b0a91ac13ad8c173760dab2d1c038495d41cc azure-powershell-bot 6/10/2024 2:15:30 PM | |
| 28689 [skip ci] Archive deed8db801365cc26557b46c7a8a01d134f0b524 azure-powershell-bot 6/29/2024 11:05:12 AM | |
| No. Title CreatedBy CreatedAt Url | |
| --- ----- --------- --------- --- | |
| 28690 [skip ci] Archive e36b0a91ac13ad8c173760dab2d1c038495d41cc azure-powershell-bot 6/10/2024 2:15:30 PM | |
| Do you want to approve and merge the following pull request? | |
| Type Y to approve and merge, N to cancel: Y | |
| No. Title CreatedBy CreatedAt Url | |
| --- ----- --------- --------- --- | |
| 28690 [skip ci] Archive e36b0a91ac13ad8c173760dab2d1c038495d41cc azure-powershell-bot 6/10/2024 2:15:30 PM | |
| PS C:\> Merge-DevPullRequest -Approve -AllArchivePR -Force | |
| No. Title CreatedBy CreatedAt Url | |
| --- ----- --------- --------- --- | |
| 28690 [skip ci] Archive e36b0a91ac13ad8c173760dab2d1c038495d41cc azure-powershell-bot 6/10/2024 2:15:30 PM | |
| 28689 [skip ci] Archive deed8db801365cc26557b46c7a8a01d134f0b524 azure-powershell-bot 6/29/2024 11:05:12 AM |
Merge-DevPullRequestcmdlet to facilitate merging pull requests in the azure-powershell repository.Description
Mandatory Checklist
Please choose the target release of Azure PowerShell. (⚠️ Target release is a different concept from API readiness. Please click below links for details.)
Check this box to confirm: I have read the Submitting Changes section of
CONTRIBUTING.mdand reviewed the following information:ChangeLog.mdfile(s) appropriatelysrc/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.## Upcoming Releaseheader in the past tense.ChangeLog.mdif no new release is required, such as fixing test case only.