Skip to content

Add Pull Request management commands#547

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/add-pull-request-management-commands
Draft

Add Pull Request management commands#547
Copilot wants to merge 4 commits intomainfrom
copilot/add-pull-request-management-commands

Conversation

Copy link
Contributor

Copilot AI commented Feb 9, 2026

Module lacked commands for PR automation workflows. Needed ability to list/filter PRs, add comments, and update state for scenarios like closing superseded auto-update PRs.

Changes

Public Commands:

  • Get-GitHubPullRequest - List with filters (state, head/base branch, sort) or get by number
  • Update-GitHubPullRequest - Modify title, body, state, base branch; supports pipeline input
  • New-GitHubPullRequestComment - Add comments via Issues API; supports pipeline input

Class:

  • GitHubPullRequest - PR representation with null-safe handling for deleted fork repositories

Implementation:

  • Private helpers in src/functions/private/PullRequests/ for each operation
  • REST API via Invoke-GitHubAPI for CRUD operations
  • Error stream output for not-found resources

Example

# Close older auto-update PRs when a new one is created
Get-GitHubPullRequest -Owner 'PSModule' -Repository 'GoogleFonts' -Head 'PSModule:auto-update-*' -State 'open' |
    Sort-Object UpdatedAt | 
    Select-Object -First ($_.Count - 1) |
    ForEach-Object {
        $_ | New-GitHubPullRequestComment -Body "Superseded by newer Auto-Update PR"
        $_ | Update-GitHubPullRequest -State 'closed'
    }

Full examples in examples/PullRequests/PullRequests.ps1.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add Pull Request management commands (Get, Set/Update, Comment, Close)</issue_title>
<issue_description>## Summary

The GitHub PowerShell module is currently missing commands for managing pull requests. These are needed for automation scenarios such as listing/filtering PRs, adding comments, and closing superseded PRs.

Missing commands

The following commands (or equivalents) would be valuable additions to the module:

Get-GitHubPullRequest

  • List/filter pull requests by state, head branch, base branch, etc.
  • Get a specific pull request by number.
  • Similar to GET /repos/{owner}/{repo}/pulls and GET /repos/{owner}/{repo}/pulls/{pull_number}.

New-GitHubPullRequestComment

  • Add a comment to a pull request (via the issues comments endpoint).
  • Similar to POST /repos/{owner}/{repo}/issues/{issue_number}/comments.

Set-GitHubPullRequest / Update-GitHubPullRequest

  • Update a pull request's state (e.g., close it), title, body, base branch, etc.
  • Similar to PATCH /repos/{owner}/{repo}/pulls/{pull_number}.

Use case

In the PSModule/GoogleFonts repository, an automated workflow updates font data and creates a PR. When a new Auto-Update PR is created, older Auto-Update PRs should be commented on (explaining they are superseded) and then closed. This requires the ability to:

  1. List open PRs filtered by head branch or title pattern
  2. Add a comment to a PR
  3. Close a PR by updating its state

Currently we work around this by using the gh CLI directly, but native PowerShell commands in the GitHub module would be preferred for consistency and better integration with the rest of the module.

Related

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 9, 2026 09:50
- Add GitHubPullRequest class
- Add Get-GitHubPullRequest command (list and get by number)
- Add Update-GitHubPullRequest command (close, update title, body, etc.)
- Add New-GitHubPullRequestComment command (add comments to PRs)

Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
- Use $Owner and $Repository instead of $OwnerName/$RepositoryName
- Add examples demonstrating PR management use cases
- Fix linter issues

Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
- Add null checks for head/base repository properties
- Write errors to error stream when PR not found
- Address code review feedback

Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Copilot AI changed the title [WIP] Add pull request management commands for automation Add Pull Request management commands Feb 9, 2026
Copilot AI requested a review from MariusStorhaug February 9, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Add Pull Request management commands (Get, Set/Update, Comment, Close)

2 participants