microsoft / PowerShellForGitHub

Microsoft PowerShell wrapper for GitHub API
Other
588 stars 185 forks source link

How can I search for a pull request by head (i.e. source branch)? #334

Closed Danl2620 closed 3 years ago

Danl2620 commented 3 years ago

A description of your problem or question

I'd like to find all pull requests that use branch "asdf" as their head/source.

Steps to reproduce the issue

$Repo | Get-GitHubPullRequest -state "open" -head "asdf"

Verbose logs showing the problem

This command just shows all open pull requests, regardless of source branch.

Suggested solution to the issue

Get-GitHubPullRequest -Head <ref> takes the name of a branch.

Operating System

Name                           Value
----                           -----
OSVersion                      Unix 11.0.0
Is 64-bit                      True
Current culture                en-US
Current UI culture             en-US

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Darwin 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module Version

Running: 0.16.0 Installed: 0.16.0

HowardWolosky commented 3 years ago

I think this can be chalked up to a poor cmdlet API design on my part back when I refactored this module for 0.2.0.

I designed it to literally follow the same structure that the API itself uses (as discussed here).

With the current implementation, you need to follow the format for head as discussed in that API documentation and in the cmdlet help (as seen here as well), where you have to specify head in the format user:ref-name. Of course, the cmdlet doesn't do attempt to do anything to validate that the user used the right syntax (doh!).

So, for your example, you'd currently need to use: $Repo | Get-GitHubPullRequest -state "open" -head "$($Repo.owner.login):asdf"

At the very least, I should add a validation check for that syntax to help users from misusing that parameter in the future. Even better would be to either update the parameter design to allow the user and ref-name to be specified separately, and/or have the user default to be the OwnerName of the repo being used.

Danl2620 commented 3 years ago

Thanks, that syntax works!