Skip to content

Add Merge-DevPullRequest cmdlet and update documentation#28718

Merged
isra-fel merged 10 commits intoAzure:mainfrom
isra-fel:azdev/github
Feb 9, 2026
Merged

Add Merge-DevPullRequest cmdlet and update documentation#28718
isra-fel merged 10 commits intoAzure:mainfrom
isra-fel:azdev/github

Conversation

@isra-fel
Copy link
Member

@isra-fel isra-fel commented Oct 20, 2025

  • 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.

Description

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

- 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.
@azure-client-tools-bot-prd
Copy link

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

@isra-fel isra-fel marked this pull request as ready for review October 20, 2025 05:21
Copilot AI review requested due to automatic review settings October 20, 2025 05:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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>
Copy link
Contributor

@DanielMicrosoft DanielMicrosoft left a comment

Choose a reason for hiding this comment

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

I think there is some valid points from Copilot we can address before merging.

@github-actions
Copy link

This PR was labeled "needs-revision" because it has unresolved review comments or CI failures.
Please resolve all open review comments and make sure all CI checks are green. Refer to our guide to troubleshoot common CI failures.

@isra-fel isra-fel added this to the Backlog milestone Oct 27, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings January 29, 2026 00:39
isra-fel and others added 2 commits January 29, 2026 11:39
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@isra-fel isra-fel removed this from the Backlog milestone Jan 29, 2026
@isra-fel
Copy link
Member Author

/azp run

@isra-fel isra-fel removed their assignment Jan 29, 2026
@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 5, 2026 12:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

@isra-fel
Copy link
Member Author

isra-fel commented Feb 8, 2026

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

'No.' = $_.number
'Title' = $_.title
'CreatedBy' = $_.author.login
'CreatedAt' = ([DateTime]::Parse($_.createdAt).ToUniversalTime().ToString('M/d/yyyy h:mm:ss tt'))
Copy link
Contributor

Choose a reason for hiding this comment

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

@isra-fel Realized this format is diff to L139, not sure if desired.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right. Let me remove the ToUniversalTime() as it's UTC and is inconvenient.

DanielMicrosoft
DanielMicrosoft previously approved these changes Feb 9, 2026
Copilot AI review requested due to automatic review settings February 9, 2026 05:40
@isra-fel isra-fel enabled auto-merge (squash) February 9, 2026 05:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Comment on lines +87 to +90
try {
$prJson = gh pr view $prNumber --json number,title,author,createdAt,url 2>$null
if ($LASTEXITCODE -ne 0) {
throw "Pull request #$prNumber not found."
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +102 to +106
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."
}
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +173 to +176
# Merge PR
Write-Host " Merging PR #$($pr.number)..." -ForegroundColor Cyan
gh pr merge $pr.number --squash 2>$null
if ($LASTEXITCODE -ne 0) {
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

-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.

Copilot uses AI. Check for mistakes.
Comment on lines +138 to +140
'CreatedBy' = $_.author.login
'CreatedAt' = [DateTime]::Parse($_.createdAt).ToString('M/d/yyyy h:mm:ss tt')
'Url' = $_.url
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +183 to +197
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
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +62
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
)
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Comment on lines +136 to +149
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
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
@isra-fel isra-fel merged commit a062a3d into Azure:main Feb 9, 2026
18 checks passed
@isra-fel isra-fel deleted the azdev/github branch February 10, 2026 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants