From 9fbc2b68a2817d104b783999607eefd897515e43 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 28 May 2020 14:11:28 -0700 Subject: [PATCH 01/18] Add GitHub Reactions support --- GitHubReactions.ps1 | 354 ++++++++++++++++++++++++++++++++ PowerShellForGitHub.psd1 | 4 + Tests/GitHubReactions.Tests.ps1 | 83 ++++++++ 3 files changed, 441 insertions(+) create mode 100644 GitHubReactions.ps1 create mode 100644 Tests/GitHubReactions.Tests.ps1 diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 new file mode 100644 index 00000000..f327dbf7 --- /dev/null +++ b/GitHubReactions.ps1 @@ -0,0 +1,354 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +function Get-GitHubReaction +{ +<# + .SYNOPSIS + Retrieve reations of a given GitHub issue. + + .DESCRIPTION + Retrieve reactions of a given GitHub issue. + + The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub + + .PARAMETER OwnerName + Owner of the repository. + If not supplied here, the DefaultOwnerName configuration property value will be used. + + .PARAMETER RepositoryName + Name of the repository. + If not supplied here, the DefaultRepositoryName configuration property value will be used. + + .PARAMETER Uri + Uri for the repository. + The OwnerName and RepositoryName will be extracted from here instead of needing to provide + them individually. + + .PARAMETER Issue + The issue number. + + .PARAMETER ReactionType + The type of reaction you want to retrieve. This is aslo called the 'content' in the GitHub API. + Valid options are based off: https://developer.github.com/v3/reactions/#reaction-types + + .PARAMETER AccessToken + If provided, this will be used as the AccessToken for authentication with the + REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated. + + .PARAMETER NoStatus + If this switch is specified, long-running commands will run on the main thread + with no commandline status update. When not specified, those commands run in + the background, enabling the command prompt to provide status information. + If not supplied here, the DefaultNoStatus configuration property value will be used. + + .EXAMPLE + Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 + + Gets the reactions for issue 157 from the Microsoft\PowerShellForGitHub project. + + .EXAMPLE + Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 -ReactionType eyes + + Gets the 'eyes' reactions for issue 157 from the Microsoft\PowerShellForGitHub project. + + .EXAMPLE + Get-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 | Get-GitHubReaction + + Gets a GitHub issue and pipe it into Get-GitHubReaction to get all the reactions for that issue. + + .NOTES + Currently, this only supports reacting to issues. + + .NOTES + The alias parameters 'number' and 'repository_url' are so that this cmdlet composes with `Get-GitHubIssue`. +#> + [CmdletBinding( + SupportsShouldProcess, + DefaultParameterSetName='Elements')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + param( + [Parameter(Mandatory, ParameterSetName='Elements')] + [string] $OwnerName, + + [Parameter(Mandatory, ParameterSetName='Elements')] + [string] $RepositoryName, + + [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] + [Alias("repository_url")] + [string] $Uri, + + [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] + [Alias("number")] + [int64] $Issue, + + [ValidateSet('+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocket', 'eyes')] + [string] $ReactionType, + + [string] $AccessToken, + + [switch] $NoStatus + ) + + Write-InvocationLog + + $elements = Resolve-RepositoryElements + $OwnerName = $elements.ownerName + $RepositoryName = $elements.repositoryName + + $telemetryProperties = @{ + 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) + 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) + } + + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$Issue/reactions" + if ($PSBoundParameters.ContainsKey('ReactionType')) { + $uriFragment += "?content=" + [Uri]::EscapeDataString($ReactionType) + } + + $description = "Getting reactions for Issue $Issue in $RepositoryName" + + $params = @{ + 'UriFragment' = $uriFragment + 'Description' = $description + 'AcceptHeader' = 'application/vnd.github.squirrel-girl-preview+json' + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + } + + $result = Invoke-GHRestMethodMultipleResult @params + + # Add metadata to reactions so that they compose with Remove-GitHubReaction + if ($result) { + $result | Add-Member -NotePropertyMembers @{ + OwnerName = $OwnerName + RepositoryName = $RepositoryName + Issue = $Issue + } + + return $result + } +} + +function Set-GitHubReaction +{ +<# + .SYNOPSIS + Sets a reation of a given GitHub issue. + + .DESCRIPTION + Sets a reaction of a given GitHub issue. + + The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub + + .PARAMETER OwnerName + Owner of the repository. + If not supplied here, the DefaultOwnerName configuration property value will be used. + + .PARAMETER RepositoryName + Name of the repository. + If not supplied here, the DefaultRepositoryName configuration property value will be used. + + .PARAMETER Uri + Uri for the repository. + The OwnerName and RepositoryName will be extracted from here instead of needing to provide + them individually. + + .PARAMETER Issue + The issue number. + + .PARAMETER ReactionType + The type of reaction you want to set. This is aslo called the 'content' in the GitHub API. + Valid options are based off: https://developer.github.com/v3/reactions/#reaction-types + + .PARAMETER AccessToken + If provided, this will be used as the AccessToken for authentication with the + REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated. + + .PARAMETER NoStatus + If this switch is specified, long-running commands will run on the main thread + with no commandline status update. When not specified, those commands run in + the background, enabling the command prompt to provide status information. + If not supplied here, the DefaultNoStatus configuration property value will be used. + + .EXAMPLE + Set-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket + + Sets the 'rocket' reaction for issue 12626 of the PowerShell\PowerShell project. +#> + [CmdletBinding( + SupportsShouldProcess, + DefaultParameterSetName='Elements')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + param( + [Parameter(Mandatory, ParameterSetName='Elements')] + [string] $OwnerName, + + [Parameter(Mandatory, ParameterSetName='Elements')] + [string] $RepositoryName, + + [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] + [Alias("repository_url")] + [string] $Uri, + + [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] + [Alias("number")] + [int64] $Issue, + + [ValidateSet('+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocket', 'eyes')] + [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter(Mandatory, ParameterSetName='Uri')] + [string] $ReactionType, + + [switch] $PassThru, + + [string] $AccessToken, + + [switch] $NoStatus + ) + + Write-InvocationLog + + $elements = Resolve-RepositoryElements + $OwnerName = $elements.ownerName + $RepositoryName = $elements.repositoryName + + $telemetryProperties = @{ + 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) + 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) + } + + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$Issue/reactions" + $description = "Setting reaction $ReactionType for Issue $Issue in $RepositoryName" + + $params = @{ + 'UriFragment' = $uriFragment + 'Description' = $description + 'Method' = 'Post' + 'Body' = @{ content = $ReactionType } | ConvertTo-Json + 'AcceptHeader' = 'application/vnd.github.squirrel-girl-preview+json' + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + } + + $result = Invoke-GHRestMethod @params + if ($PSBoundParameters.ContainsKey('PassThru')) { + return $result + } +} + +function Remove-GitHubReaction +{ +<# + .SYNOPSIS + Removes a reation on a given GitHub issue. + + .DESCRIPTION + Removes a reation on a given GitHub issue. + + The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub + + .PARAMETER OwnerName + Owner of the repository. + If not supplied here, the DefaultOwnerName configuration property value will be used. + + .PARAMETER RepositoryName + Name of the repository. + If not supplied here, the DefaultRepositoryName configuration property value will be used. + + .PARAMETER Uri + Uri for the repository. + The OwnerName and RepositoryName will be extracted from here instead of needing to provide + them individually. + + .PARAMETER Issue + The issue number. + + .PARAMETER ReactionId + The Id of the reaction. You can get this from using Get-GitHubReaction. + + .PARAMETER AccessToken + If provided, this will be used as the AccessToken for authentication with the + REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated. + + .PARAMETER NoStatus + If this switch is specified, long-running commands will run on the main thread + with no commandline status update. When not specified, those commands run in + the background, enabling the command prompt to provide status information. + If not supplied here, the DefaultNoStatus configuration property value will be used. + + .EXAMPLE + Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionId 1234 + + Remove a reaction by Id on Issue 12626 from the PowerShell\PowerShell project. + + .EXAMPLE + Get-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket | Remove-GitHubReaction + + Gets a reaction using Get-GitHubReaction and pipes it into Remove-GitHubReaction. +#> + [CmdletBinding( + SupportsShouldProcess, + DefaultParameterSetName='Elements')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + param( + [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] + [string] $OwnerName, + + [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] + [string] $RepositoryName, + + [Parameter(Mandatory, ParameterSetName='Uri')] + [string] $Uri, + + [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] + [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] + [int64] $Issue, + + [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName, ValueFromPipeline)] + [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName, ValueFromPipeline)] + [Alias('Id')] + [int64] $ReactionId, + + [switch] $PassThru, + + [string] $AccessToken, + + [switch] $NoStatus + ) + + process { + Write-InvocationLog + + $elements = Resolve-RepositoryElements + $OwnerName = $elements.ownerName + $RepositoryName = $elements.repositoryName + + $telemetryProperties = @{ + 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) + 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) + } + + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$Issue/reactions/$ReactionId" + $description = "Removing reaction $ReactionId for Issue $Issue in $RepositoryName" + + $params = @{ + 'UriFragment' = $uriFragment + 'Description' = $description + 'Method' = 'Delete' + 'AcceptHeader' = 'application/vnd.github.squirrel-girl-preview+json' + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + } + + return Invoke-GHRestMethod @params + } +} diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index c7f51c82..b3692284 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -36,6 +36,7 @@ 'GitHubProjectCards.ps1', 'GitHubProjectColumns.ps1', 'GitHubPullRequests.ps1', + 'GitHubReactions.ps1', 'GitHubReleases.ps1', 'GitHubRepositories.ps1', 'GitHubRepositoryForks.ps1', @@ -75,6 +76,7 @@ 'Get-GitHubProjectColumn', 'Get-GitHubPullRequest', 'Get-GitHubRateLimit', + 'Get-GitHubReaction', 'Get-GitHubReferrerTraffic', 'Get-GitHubRelease', 'Get-GitHubRepository', @@ -119,6 +121,7 @@ 'Remove-GitHubProject', 'Remove-GitHubProjectCard', 'Remove-GitHubProjectColumn', + 'Remove-GitHubReaction', 'Remove-GitHubRepository', 'Rename-GitHubRepository', 'Reset-GitHubConfiguration', @@ -132,6 +135,7 @@ 'Set-GitHubProject', 'Set-GitHubProjectCard', 'Set-GitHubProjectColumn', + 'Set-GitHubReaction', 'Set-GitHubRepositoryTopic', 'Split-GitHubUri', 'Test-GitHubAssignee', diff --git a/Tests/GitHubReactions.Tests.ps1 b/Tests/GitHubReactions.Tests.ps1 new file mode 100644 index 00000000..e28c5ded --- /dev/null +++ b/Tests/GitHubReactions.Tests.ps1 @@ -0,0 +1,83 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Tests for GitHubReactions.ps1 module +#> + +# This is common test code setup logic for all Pester test files +$moduleRootPath = Split-Path -Path $PSScriptRoot -Parent +. (Join-Path -Path $moduleRootPath -ChildPath 'Tests\Common.ps1') + +try +{ + # Define Script-scoped, readonly, hidden variables. + @{ + defaultIssueTitle = "Test Title" + defaultCommentBody = "This is a test body." + defaultReactionType = "+1" + otherReactionType = "eyes" + }.GetEnumerator() | ForEach-Object { + Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value + } + + Describe 'Creating, modifying and deleting comments' { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + $issue = New-GitHubIssue -Uri $repo.svn_url -Title $defaultIssueTitle + + Context 'For creating a reaction' { + Set-GitHubReaction -Uri $repo.svn_url -Issue $issue.number -ReactionType $defaultReactionType + $existingReaction = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number + + It "Should have the expected reaction type" { + $existingReaction.content | Should be $defaultReactionType + } + } + + Context 'For getting reactions from an issue' { + Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number | Set-GitHubReaction -ReactionType $otherReactionType + $allReactions = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number + $specificReactions = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number -ReactionType $otherReactionType + + It 'Should have the expected number of reactions' { + $allReactions.Count | Should be 2 + $specificReactions.Count | Should be 1 + } + + It 'Should have the expected reaction content' { + + $specificReactions.content | Should be $otherReactionType + $specificReactions.RepositoryName | Should be $repo.name + } + } + + Context 'For getting reactions from a repository and deleting them' { + $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number) + + It 'Should have the expected number of reactions' { + $existingReactions.Count | Should be 2 + } + + $existingReactions | Remove-GitHubReaction + + $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number) + + It 'Should have no reactions' { + $existingReactions + $existingReactions.Count | Should be 0 + } + } + + Remove-GitHubRepository -Uri $repo.svn_url + } +} +finally +{ + if (Test-Path -Path $script:originalConfigFile -PathType Leaf) + { + # Restore the user's configuration to its pre-test state + Restore-GitHubConfiguration -Path $script:originalConfigFile + $script:originalConfigFile = $null + } +} From a510502b49b0d8a3dfd24213ea99e5ec0ea8358c Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 28 May 2020 14:32:44 -0700 Subject: [PATCH 02/18] added note --- GitHubReactions.ps1 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index f327dbf7..d86962bf 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -58,7 +58,7 @@ function Get-GitHubReaction Gets a GitHub issue and pipe it into Get-GitHubReaction to get all the reactions for that issue. .NOTES - Currently, this only supports reacting to issues. + Currently, this only supports reacting to issues. Issue comments, commit comments and PR comments will come later. .NOTES The alias parameters 'number' and 'repository_url' are so that this cmdlet composes with `Get-GitHubIssue`. @@ -178,6 +178,12 @@ function Set-GitHubReaction Set-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket Sets the 'rocket' reaction for issue 12626 of the PowerShell\PowerShell project. + + .NOTES + Currently, this only supports reacting to issues. Issue comments, commit comments and PR comments will come later. + + .NOTES + The alias parameters 'number' and 'repository_url' are so that this cmdlet composes with `Get-GitHubIssue`. #> [CmdletBinding( SupportsShouldProcess, @@ -292,6 +298,9 @@ function Remove-GitHubReaction Get-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket | Remove-GitHubReaction Gets a reaction using Get-GitHubReaction and pipes it into Remove-GitHubReaction. + + .NOTES + Currently, this only supports reacting to issues. Issue comments, commit comments and PR comments will come later. #> [CmdletBinding( SupportsShouldProcess, From ee85c83b553e919cdca8dcfa60e251372fc6cc31 Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Tue, 2 Jun 2020 09:37:31 -0700 Subject: [PATCH 03/18] Apply suggestions from code review Co-authored-by: Howard Wolosky --- GitHubReactions.ps1 | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index d86962bf..361407b9 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -5,7 +5,7 @@ function Get-GitHubReaction { <# .SYNOPSIS - Retrieve reations of a given GitHub issue. + Retrieve reactions of a given GitHub issue. .DESCRIPTION Retrieve reactions of a given GitHub issue. @@ -29,7 +29,7 @@ function Get-GitHubReaction The issue number. .PARAMETER ReactionType - The type of reaction you want to retrieve. This is aslo called the 'content' in the GitHub API. + The type of reaction you want to retrieve. This is also called the 'content' in the GitHub API. Valid options are based off: https://developer.github.com/v3/reactions/#reaction-types .PARAMETER AccessToken @@ -83,7 +83,7 @@ function Get-GitHubReaction [Alias("number")] [int64] $Issue, - [ValidateSet('+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocket', 'eyes')] + [ValidateSet('+1', '-1', 'Laugh', 'Confused', 'Heart', 'Hooray', 'Rocket', 'Eyes')] [string] $ReactionType, [string] $AccessToken, @@ -103,8 +103,9 @@ function Get-GitHubReaction } $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$Issue/reactions" - if ($PSBoundParameters.ContainsKey('ReactionType')) { - $uriFragment += "?content=" + [Uri]::EscapeDataString($ReactionType) + if ($PSBoundParameters.ContainsKey('ReactionType')) + { + $uriFragment += "?content=" + [Uri]::EscapeDataString($ReactionType.ToLower()) } $description = "Getting reactions for Issue $Issue in $RepositoryName" @@ -112,7 +113,7 @@ function Get-GitHubReaction $params = @{ 'UriFragment' = $uriFragment 'Description' = $description - 'AcceptHeader' = 'application/vnd.github.squirrel-girl-preview+json' + 'AcceptHeader' = $script:squirrelAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -122,7 +123,8 @@ function Get-GitHubReaction $result = Invoke-GHRestMethodMultipleResult @params # Add metadata to reactions so that they compose with Remove-GitHubReaction - if ($result) { + if ($result) + { $result | Add-Member -NotePropertyMembers @{ OwnerName = $OwnerName RepositoryName = $RepositoryName @@ -137,7 +139,7 @@ function Set-GitHubReaction { <# .SYNOPSIS - Sets a reation of a given GitHub issue. + Sets a reaction of a given GitHub issue. .DESCRIPTION Sets a reaction of a given GitHub issue. @@ -236,7 +238,7 @@ function Set-GitHubReaction 'Description' = $description 'Method' = 'Post' 'Body' = @{ content = $ReactionType } | ConvertTo-Json - 'AcceptHeader' = 'application/vnd.github.squirrel-girl-preview+json' + 'AcceptHeader' = $script:squirrelAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -244,7 +246,8 @@ function Set-GitHubReaction } $result = Invoke-GHRestMethod @params - if ($PSBoundParameters.ContainsKey('PassThru')) { + if ($PSBoundParameters.ContainsKey('PassThru')) + { return $result } } @@ -253,10 +256,10 @@ function Remove-GitHubReaction { <# .SYNOPSIS - Removes a reation on a given GitHub issue. + Removes a reaction on a given GitHub issue. .DESCRIPTION - Removes a reation on a given GitHub issue. + Removes a reaction on a given GitHub issue. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -306,6 +309,7 @@ function Remove-GitHubReaction SupportsShouldProcess, DefaultParameterSetName='Elements')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [Alias('Delete-GitHubReaction')] param( [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] [string] $OwnerName, @@ -351,7 +355,7 @@ function Remove-GitHubReaction 'UriFragment' = $uriFragment 'Description' = $description 'Method' = 'Delete' - 'AcceptHeader' = 'application/vnd.github.squirrel-girl-preview+json' + 'AcceptHeader' = $script:squirrelAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties From 1fe71d20be39402ac0bcbe3554d4c0eed223aecb Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Tue, 2 Jun 2020 11:59:57 -0700 Subject: [PATCH 04/18] ShouldProcess and misc feedback --- GitHubReactions.ps1 | 56 ++++++++++++++++++--------------- Tests/GitHubReactions.Tests.ps1 | 2 +- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index 361407b9..87c90413 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -176,6 +176,9 @@ function Set-GitHubReaction the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .PARAMETER PassThru + If specified, this will emit the result of the operation to the pipeline. + .EXAMPLE Set-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket @@ -207,9 +210,8 @@ function Set-GitHubReaction [Alias("number")] [int64] $Issue, - [ValidateSet('+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocket', 'eyes')] - [Parameter(Mandatory, ParameterSetName='Elements')] - [Parameter(Mandatory, ParameterSetName='Uri')] + [ValidateSet('+1', '-1', 'Laugh', 'Confused', 'Heart', 'Hooray', 'Rocket', 'Eyes')] + [Parameter(Mandatory)] [string] $ReactionType, [switch] $PassThru, @@ -237,7 +239,7 @@ function Set-GitHubReaction 'UriFragment' = $uriFragment 'Description' = $description 'Method' = 'Post' - 'Body' = @{ content = $ReactionType } | ConvertTo-Json + 'Body' = @{ content = $ReactionType.ToLower() } | ConvertTo-Json 'AcceptHeader' = $script:squirrelAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name @@ -295,10 +297,15 @@ function Remove-GitHubReaction .EXAMPLE Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionId 1234 - Remove a reaction by Id on Issue 12626 from the PowerShell\PowerShell project. + Remove a reaction by Id on Issue 12626 from the PowerShell\PowerShell project interactively. + + .EXAMPLE + Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionId 1234 -Confirm:$false + + Remove a reaction by Id on Issue 12626 from the PowerShell\PowerShell project non-interactively. .EXAMPLE - Get-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket | Remove-GitHubReaction + Get-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket | Remove-GitHubReaction -Confirm:$false Gets a reaction using Get-GitHubReaction and pipes it into Remove-GitHubReaction. @@ -307,8 +314,8 @@ function Remove-GitHubReaction #> [CmdletBinding( SupportsShouldProcess, - DefaultParameterSetName='Elements')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + DefaultParameterSetName='Elements', + ConfirmImpact='High')] [Alias('Delete-GitHubReaction')] param( [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] @@ -320,17 +327,13 @@ function Remove-GitHubReaction [Parameter(Mandatory, ParameterSetName='Uri')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] - [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] + [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [int64] $Issue, - [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName, ValueFromPipeline)] - [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName, ValueFromPipeline)] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)] [Alias('Id')] [int64] $ReactionId, - [switch] $PassThru, - [string] $AccessToken, [switch] $NoStatus @@ -351,17 +354,20 @@ function Remove-GitHubReaction $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$Issue/reactions/$ReactionId" $description = "Removing reaction $ReactionId for Issue $Issue in $RepositoryName" - $params = @{ - 'UriFragment' = $uriFragment - 'Description' = $description - 'Method' = 'Delete' - 'AcceptHeader' = $script:squirrelAcceptHeader - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + if ($PSCmdlet.ShouldProcess($ReactionId, "Removing reaction for Issue $Issue in $RepositoryName")) + { + $params = @{ + 'UriFragment' = $uriFragment + 'Description' = $description + 'Method' = 'Delete' + 'AcceptHeader' = $script:squirrelAcceptHeader + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + } + + return Invoke-GHRestMethod @params } - - return Invoke-GHRestMethod @params } } diff --git a/Tests/GitHubReactions.Tests.ps1 b/Tests/GitHubReactions.Tests.ps1 index e28c5ded..5f32cecd 100644 --- a/Tests/GitHubReactions.Tests.ps1 +++ b/Tests/GitHubReactions.Tests.ps1 @@ -59,7 +59,7 @@ try $existingReactions.Count | Should be 2 } - $existingReactions | Remove-GitHubReaction + $existingReactions | Remove-GitHubReaction -Confirm:$false $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number) From 642dd459a17537dd7a4a03b20d680124731d2ea7 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Tue, 2 Jun 2020 12:15:56 -0700 Subject: [PATCH 05/18] remove PassThru --- GitHubReactions.ps1 | 11 +---------- Tests/GitHubReactions.Tests.ps1 | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index 87c90413..4556103e 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -176,9 +176,6 @@ function Set-GitHubReaction the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. - .PARAMETER PassThru - If specified, this will emit the result of the operation to the pipeline. - .EXAMPLE Set-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket @@ -214,8 +211,6 @@ function Set-GitHubReaction [Parameter(Mandatory)] [string] $ReactionType, - [switch] $PassThru, - [string] $AccessToken, [switch] $NoStatus @@ -247,11 +242,7 @@ function Set-GitHubReaction 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - $result = Invoke-GHRestMethod @params - if ($PSBoundParameters.ContainsKey('PassThru')) - { - return $result - } + return Invoke-GHRestMethod @params } function Remove-GitHubReaction diff --git a/Tests/GitHubReactions.Tests.ps1 b/Tests/GitHubReactions.Tests.ps1 index 5f32cecd..07a34737 100644 --- a/Tests/GitHubReactions.Tests.ps1 +++ b/Tests/GitHubReactions.Tests.ps1 @@ -69,7 +69,7 @@ try } } - Remove-GitHubRepository -Uri $repo.svn_url + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } } finally From e960c27b0b924b8dfe3a87e28641a26f22db592d Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Thu, 4 Jun 2020 10:44:27 -0700 Subject: [PATCH 06/18] Apply suggestions from code review Co-authored-by: Howard Wolosky --- Tests/GitHubReactions.Tests.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Tests/GitHubReactions.Tests.ps1 b/Tests/GitHubReactions.Tests.ps1 index 07a34737..f39dad20 100644 --- a/Tests/GitHubReactions.Tests.ps1 +++ b/Tests/GitHubReactions.Tests.ps1 @@ -46,13 +46,12 @@ try } It 'Should have the expected reaction content' { - $specificReactions.content | Should be $otherReactionType $specificReactions.RepositoryName | Should be $repo.name } } - Context 'For getting reactions from a repository and deleting them' { + Context 'For getting reactions from an Issue and deleting them' { $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number) It 'Should have the expected number of reactions' { From c975512439c88a723e694ca2e71d8d89e33b7ad9 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Sat, 6 Jun 2020 14:18:29 -0700 Subject: [PATCH 07/18] static analysis --- GitHubReactions.ps1 | 59 +++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index 4556103e..783af036 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubReaction +filter Get-GitHubReaction { <# .SYNOPSIS @@ -67,6 +67,7 @@ function Get-GitHubReaction SupportsShouldProcess, DefaultParameterSetName='Elements')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(Mandatory, ParameterSetName='Elements')] [string] $OwnerName, @@ -135,7 +136,7 @@ function Get-GitHubReaction } } -function Set-GitHubReaction +filter Set-GitHubReaction { <# .SYNOPSIS @@ -191,6 +192,7 @@ function Set-GitHubReaction SupportsShouldProcess, DefaultParameterSetName='Elements')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(Mandatory, ParameterSetName='Elements')] [string] $OwnerName, @@ -245,7 +247,7 @@ function Set-GitHubReaction return Invoke-GHRestMethod @params } -function Remove-GitHubReaction +filter Remove-GitHubReaction { <# .SYNOPSIS @@ -308,6 +310,7 @@ function Remove-GitHubReaction DefaultParameterSetName='Elements', ConfirmImpact='High')] [Alias('Delete-GitHubReaction')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] [string] $OwnerName, @@ -330,35 +333,33 @@ function Remove-GitHubReaction [switch] $NoStatus ) - process { - Write-InvocationLog + Write-InvocationLog - $elements = Resolve-RepositoryElements - $OwnerName = $elements.ownerName - $RepositoryName = $elements.repositoryName + $elements = Resolve-RepositoryElements + $OwnerName = $elements.ownerName + $RepositoryName = $elements.repositoryName - $telemetryProperties = @{ - 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) - 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) - } + $telemetryProperties = @{ + 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) + 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) + } - $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$Issue/reactions/$ReactionId" - $description = "Removing reaction $ReactionId for Issue $Issue in $RepositoryName" - - if ($PSCmdlet.ShouldProcess($ReactionId, "Removing reaction for Issue $Issue in $RepositoryName")) - { - $params = @{ - 'UriFragment' = $uriFragment - 'Description' = $description - 'Method' = 'Delete' - 'AcceptHeader' = $script:squirrelAcceptHeader - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - } - - return Invoke-GHRestMethod @params + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$Issue/reactions/$ReactionId" + $description = "Removing reaction $ReactionId for Issue $Issue in $RepositoryName" + + if ($PSCmdlet.ShouldProcess($ReactionId, "Removing reaction for Issue $Issue in $RepositoryName")) + { + $params = @{ + 'UriFragment' = $uriFragment + 'Description' = $description + 'Method' = 'Delete' + 'AcceptHeader' = $script:squirrelAcceptHeader + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params } } From 77203bc00a774c6c533e3fbba16677d0ca495cf5 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 24 Jun 2020 11:54:34 -0700 Subject: [PATCH 08/18] Add proper pipelining --- GitHubReactions.ps1 | 251 ++++++++++++++++++++++++-------- Tests/GitHubReactions.Tests.ps1 | 39 ++++- 2 files changed, 219 insertions(+), 71 deletions(-) diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index 783af036..0841caa9 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -1,6 +1,12 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +@{ + GitHubReactionTypeName = 'GitHub.Reaction' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + filter Get-GitHubReaction { <# @@ -25,8 +31,10 @@ filter Get-GitHubReaction The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER Issue - The issue number. + .PARAMETER IssueNumber + The issue *OR* pull request number. This parameter has an alias called + `PullRequestNumber` so that the experience feels natural but in this case, + PRs are handled the same as issues. .PARAMETER ReactionType The type of reaction you want to retrieve. This is also called the 'content' in the GitHub API. @@ -42,26 +50,36 @@ filter Get-GitHubReaction the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.Issue + GitHub.PullRequest + GitHub.Reaction + + .OUTPUTS + GitHub.Reaction + .EXAMPLE - Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 + Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -IssueNumber 157 Gets the reactions for issue 157 from the Microsoft\PowerShellForGitHub project. .EXAMPLE - Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 -ReactionType eyes + Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -IssueNumber 157 -ReactionType eyes Gets the 'eyes' reactions for issue 157 from the Microsoft\PowerShellForGitHub project. .EXAMPLE - Get-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 | Get-GitHubReaction + Get-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -IssueNumber 157 | Get-GitHubReaction Gets a GitHub issue and pipe it into Get-GitHubReaction to get all the reactions for that issue. - .NOTES - Currently, this only supports reacting to issues. Issue comments, commit comments and PR comments will come later. + .EXAMPLE + Get-GitHubPullRequest -Uri https://github.com/microsoft/PowerShellForGitHub -PullRequest 193 | Get-GitHubReaction + + Gets a GitHub pull request and pipes it into Get-GitHubReaction to get all the reactions for that pull request. .NOTES - The alias parameters 'number' and 'repository_url' are so that this cmdlet composes with `Get-GitHubIssue`. + Currently, this only supports reacting to issues and pull requests. Issue comments, commit comments and PR comments will come later. #> [CmdletBinding( SupportsShouldProcess, @@ -69,20 +87,28 @@ filter Get-GitHubReaction [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( - [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $OwnerName, - [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $RepositoryName, - [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] - [Alias("repository_url")] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] - [Alias("number")] - [int64] $Issue, + [Alias('Issue')] + [Alias('PullRequestNumber')] + [int64] $IssueNumber, [ValidateSet('+1', '-1', 'Laugh', 'Confused', 'Heart', 'Hooray', 'Rocket', 'Eyes')] [string] $ReactionType, @@ -103,18 +129,18 @@ filter Get-GitHubReaction 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$Issue/reactions" + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$IssueNumber/reactions" if ($PSBoundParameters.ContainsKey('ReactionType')) { $uriFragment += "?content=" + [Uri]::EscapeDataString($ReactionType.ToLower()) } - $description = "Getting reactions for Issue $Issue in $RepositoryName" + $description = "Getting reactions for Issue $IssueNumber in $RepositoryName" $params = @{ 'UriFragment' = $uriFragment 'Description' = $description - 'AcceptHeader' = $script:squirrelAcceptHeader + 'AcceptHeader' = $script:squirrelGirlAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -122,18 +148,8 @@ filter Get-GitHubReaction } $result = Invoke-GHRestMethodMultipleResult @params - - # Add metadata to reactions so that they compose with Remove-GitHubReaction - if ($result) - { - $result | Add-Member -NotePropertyMembers @{ - OwnerName = $OwnerName - RepositoryName = $RepositoryName - Issue = $Issue - } - - return $result - } + return ($result | + Add-GitHubReactionAdditionalProperties -OwnerName $OwnerName -RepositoryName $RepositoryName -IssueNumber $IssueNumber) } filter Set-GitHubReaction @@ -160,8 +176,10 @@ filter Set-GitHubReaction The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER Issue - The issue number. + .PARAMETER IssueNumber + The issue *OR* pull request number. This parameter has an alias called + `PullRequestNumber` so that the experience feels natural but in this case, + PRs are handled the same as issues. .PARAMETER ReactionType The type of reaction you want to set. This is aslo called the 'content' in the GitHub API. @@ -177,16 +195,26 @@ filter Set-GitHubReaction the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.Issue + GitHub.PullRequest + GitHub.Reaction + + .OUTPUTS + GitHub.Reaction + .EXAMPLE - Set-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket + Set-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -IssueNumber 12626 -ReactionType rocket Sets the 'rocket' reaction for issue 12626 of the PowerShell\PowerShell project. - .NOTES - Currently, this only supports reacting to issues. Issue comments, commit comments and PR comments will come later. + .EXAMPLE + Get-GitHubPullRequest -Uri https://github.com/microsoft/PowerShellForGitHub -PullRequest 193 | Set-GitHubReaction -ReactionType Heart + + Gets a GitHub pull request and pipes it into Set-GitHubReaction to set the 'heart' reaction for that pull request. .NOTES - The alias parameters 'number' and 'repository_url' are so that this cmdlet composes with `Get-GitHubIssue`. + Currently, this only supports reacting to issues and pull requests. Issue comments, commit comments and PR comments will come later. #> [CmdletBinding( SupportsShouldProcess, @@ -194,20 +222,29 @@ filter Set-GitHubReaction [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( - [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $OwnerName, - [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $RepositoryName, - [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] - [Alias("repository_url")] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] - [Alias("number")] - [int64] $Issue, + [Alias('Issue')] + [Alias('PullRequest')] + [Alias('PullRequestNumber')] + [int64] $IssueNumber, [ValidateSet('+1', '-1', 'Laugh', 'Confused', 'Heart', 'Hooray', 'Rocket', 'Eyes')] [Parameter(Mandatory)] @@ -229,22 +266,24 @@ filter Set-GitHubReaction 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$Issue/reactions" - $description = "Setting reaction $ReactionType for Issue $Issue in $RepositoryName" + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$IssueNumber/reactions" + $description = "Setting reaction $ReactionType for Issue $IssueNumber in $RepositoryName" $params = @{ 'UriFragment' = $uriFragment 'Description' = $description 'Method' = 'Post' 'Body' = @{ content = $ReactionType.ToLower() } | ConvertTo-Json - 'AcceptHeader' = $script:squirrelAcceptHeader + 'AcceptHeader' = $script:squirrelGirlAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + $result = Invoke-GHRestMethod @params + return ($result | + Add-GitHubReactionAdditionalProperties -OwnerName $OwnerName -RepositoryName $RepositoryName -IssueNumber $IssueNumber) } filter Remove-GitHubReaction @@ -271,8 +310,10 @@ filter Remove-GitHubReaction The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER Issue - The issue number. + .PARAMETER IssueNumber + The issue *OR* pull request number. This parameter has an alias called + `PullRequestNumber` so that the experience feels natural but in this case, + PRs are handled the same as issues. .PARAMETER ReactionId The Id of the reaction. You can get this from using Get-GitHubReaction. @@ -287,23 +328,31 @@ filter Remove-GitHubReaction the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.Issue + GitHub.PullRequests + GitHub.Reaction + + .OUTPUTS + None + .EXAMPLE - Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionId 1234 + Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -IssueNumber 12626 -ReactionId 1234 Remove a reaction by Id on Issue 12626 from the PowerShell\PowerShell project interactively. .EXAMPLE - Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionId 1234 -Confirm:$false + Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -IssueNumber 12626 -ReactionId 1234 -Confirm:$false Remove a reaction by Id on Issue 12626 from the PowerShell\PowerShell project non-interactively. .EXAMPLE - Get-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket | Remove-GitHubReaction -Confirm:$false + Get-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -IssueNumber 12626 -ReactionType rocket | Remove-GitHubReaction -Confirm:$false Gets a reaction using Get-GitHubReaction and pipes it into Remove-GitHubReaction. .NOTES - Currently, this only supports reacting to issues. Issue comments, commit comments and PR comments will come later. + Currently, this only supports reacting to issues and pull requests. Issue comments, commit comments and PR comments will come later. #> [CmdletBinding( SupportsShouldProcess, @@ -312,20 +361,31 @@ filter Remove-GitHubReaction [Alias('Delete-GitHubReaction')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( - [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $OwnerName, - [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $RepositoryName, - [Parameter(Mandatory, ParameterSetName='Uri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ValueFromPipelineByPropertyName)] - [int64] $Issue, + [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] + [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] + [Alias('Issue')] + [Alias('PullRequest')] + [Alias('PullRequestNumber')] + [int64] $IssueNumber, [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)] - [Alias('Id')] [int64] $ReactionId, [string] $AccessToken, @@ -344,16 +404,16 @@ filter Remove-GitHubReaction 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$Issue/reactions/$ReactionId" - $description = "Removing reaction $ReactionId for Issue $Issue in $RepositoryName" + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$IssueNumber/reactions/$ReactionId" + $description = "Removing reaction $ReactionId for Issue $IssueNumber in $RepositoryName" - if ($PSCmdlet.ShouldProcess($ReactionId, "Removing reaction for Issue $Issue in $RepositoryName")) + if ($PSCmdlet.ShouldProcess($ReactionId, "Removing reaction for Issue $IssueNumber in $RepositoryName")) { $params = @{ 'UriFragment' = $uriFragment 'Description' = $description 'Method' = 'Delete' - 'AcceptHeader' = $script:squirrelAcceptHeader + 'AcceptHeader' = $script:squirrelGirlAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -363,3 +423,68 @@ filter Remove-GitHubReaction return Invoke-GHRestMethod @params } } + +filter Add-GitHubReactionAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Reaction objects. + .PARAMETER InputObject + The GitHub object to add additional properties to. + .PARAMETER TypeName + The type that should be assigned to the object. + .INPUTS + [PSCustomObject] + .OUTPUTS + GitHub.Reaction +#> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] + [PSCustomObject[]] $InputObject, + + [Parameter(Mandatory)] + [string] $OwnerName, + + [Parameter(Mandatory)] + [string] $RepositoryName, + + [Parameter(Mandatory)] + [string] $IssueNumber, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubReactionTypeName + ) + + if ($null -eq $InputObject) { + return + } + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + $repositoryUrl = Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'ReactionId' -Value $item.id -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'IssueNumber' -Value $IssueNumber -MemberType NoteProperty -Force + + @('assignee', 'assignees', 'user') | + ForEach-Object { + if ($null -ne $item.$_) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.$_ + } + } + } + + Write-Output $item + } +} diff --git a/Tests/GitHubReactions.Tests.ps1 b/Tests/GitHubReactions.Tests.ps1 index f39dad20..85946d14 100644 --- a/Tests/GitHubReactions.Tests.ps1 +++ b/Tests/GitHubReactions.Tests.ps1 @@ -27,8 +27,8 @@ try $issue = New-GitHubIssue -Uri $repo.svn_url -Title $defaultIssueTitle Context 'For creating a reaction' { - Set-GitHubReaction -Uri $repo.svn_url -Issue $issue.number -ReactionType $defaultReactionType - $existingReaction = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number + Set-GitHubReaction -Uri $repo.svn_url -IssueNumber $issue.number -ReactionType $defaultReactionType + $existingReaction = Get-GitHubReaction -Uri $repo.svn_url -IssueNumber $issue.number It "Should have the expected reaction type" { $existingReaction.content | Should be $defaultReactionType @@ -36,9 +36,9 @@ try } Context 'For getting reactions from an issue' { - Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number | Set-GitHubReaction -ReactionType $otherReactionType - $allReactions = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number - $specificReactions = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number -ReactionType $otherReactionType + Get-GitHubIssue -Uri $repo.svn_url -IssueNumber $issue.number | Set-GitHubReaction -ReactionType $otherReactionType + $allReactions = Get-GitHubReaction -Uri $repo.svn_url -IssueNumber $issue.number + $specificReactions = Get-GitHubReaction -Uri $repo.svn_url -IssueNumber $issue.number -ReactionType $otherReactionType It 'Should have the expected number of reactions' { $allReactions.Count | Should be 2 @@ -47,12 +47,35 @@ try It 'Should have the expected reaction content' { $specificReactions.content | Should be $otherReactionType - $specificReactions.RepositoryName | Should be $repo.name + $specificReactions.RepositoryUrl | Should be $repo.RepositoryUrl + } + } + + Context 'For getting reactions from a pull request' { + # TODO: there are currently PRs out to add the ability to create new branches and add content to a repo. + # When those go in, this test can be refactored to use those so the test is more reliable using a test PR. + $url = 'https://github.com/microsoft/PowerShellForGitHub' + $pr = Get-GitHubPullRequest -Uri $url -PullRequest 193 + $pr | Get-GitHubReaction | Remove-GitHubReaction -ErrorAction Ignore -Confirm:$false + + $pr | Set-GitHubReaction -ReactionType $defaultReactionType + $pr | Set-GitHubReaction -ReactionType $otherReactionType + $allReactions = $pr | Get-GitHubReaction + $specificReactions = $pr | Get-GitHubReaction -ReactionType $otherReactionType + + It 'Should have the expected number of reactions' { + $allReactions.Count | Should be 2 + $specificReactions.Count | Should be 1 + } + + It 'Should have the expected reaction content' { + $specificReactions.content | Should be $otherReactionType + $specificReactions.RepositoryUrl | Should be $url } } Context 'For getting reactions from an Issue and deleting them' { - $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number) + $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -IssueNumber $issue.number) It 'Should have the expected number of reactions' { $existingReactions.Count | Should be 2 @@ -60,7 +83,7 @@ try $existingReactions | Remove-GitHubReaction -Confirm:$false - $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number) + $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -IssueNumber $issue.number) It 'Should have no reactions' { $existingReactions From 4d88a3162fbe887dd2b1392db26c6dc62ae5b951 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 24 Jun 2020 12:48:38 -0700 Subject: [PATCH 09/18] add -Force --- GitHubReactions.ps1 | 5 ++++- Tests/GitHubReactions.Tests.ps1 | 34 +++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index 0841caa9..30335ea4 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -388,6 +388,9 @@ filter Remove-GitHubReaction [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)] [int64] $ReactionId, + [Parameter()] + [switch] $Force, + [string] $AccessToken, [switch] $NoStatus @@ -407,7 +410,7 @@ filter Remove-GitHubReaction $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$IssueNumber/reactions/$ReactionId" $description = "Removing reaction $ReactionId for Issue $IssueNumber in $RepositoryName" - if ($PSCmdlet.ShouldProcess($ReactionId, "Removing reaction for Issue $IssueNumber in $RepositoryName")) + if ($Force.IsPresent -or $PSCmdlet.ShouldProcess($ReactionId, "Removing reaction for Issue $IssueNumber in $RepositoryName")) { $params = @{ 'UriFragment' = $uriFragment diff --git a/Tests/GitHubReactions.Tests.ps1 b/Tests/GitHubReactions.Tests.ps1 index 85946d14..f0d1c5bf 100644 --- a/Tests/GitHubReactions.Tests.ps1 +++ b/Tests/GitHubReactions.Tests.ps1 @@ -58,19 +58,25 @@ try $pr = Get-GitHubPullRequest -Uri $url -PullRequest 193 $pr | Get-GitHubReaction | Remove-GitHubReaction -ErrorAction Ignore -Confirm:$false - $pr | Set-GitHubReaction -ReactionType $defaultReactionType - $pr | Set-GitHubReaction -ReactionType $otherReactionType - $allReactions = $pr | Get-GitHubReaction - $specificReactions = $pr | Get-GitHubReaction -ReactionType $otherReactionType - - It 'Should have the expected number of reactions' { - $allReactions.Count | Should be 2 - $specificReactions.Count | Should be 1 - } - - It 'Should have the expected reaction content' { - $specificReactions.content | Should be $otherReactionType - $specificReactions.RepositoryUrl | Should be $url + $reaction1 = $pr | Set-GitHubReaction -ReactionType $defaultReactionType + $reaction2 = $pr | Set-GitHubReaction -ReactionType $otherReactionType + + try { + $allReactions = $pr | Get-GitHubReaction + $specificReactions = $pr | Get-GitHubReaction -ReactionType $otherReactionType + + It 'Should have the expected number of reactions' { + $allReactions.Count | Should be 2 + $specificReactions.Count | Should be 1 + } + + It 'Should have the expected reaction content' { + $specificReactions.content | Should be $otherReactionType + $specificReactions.RepositoryUrl | Should be $url + } + } finally { + $reaction1 | Remove-GitHubReaction -Force + $reaction2 | Remove-GitHubReaction -Force } } @@ -81,7 +87,7 @@ try $existingReactions.Count | Should be 2 } - $existingReactions | Remove-GitHubReaction -Confirm:$false + $existingReactions | Remove-GitHubReaction -Force $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -IssueNumber $issue.number) From b37462ebf697409650e77fbf2804929113d97b7b Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 24 Jun 2020 21:16:03 -0700 Subject: [PATCH 10/18] address most of the feedback --- GitHubReactions.ps1 | 361 ++++++++++++++++++++++++-------- PowerShellForGitHub.psd1 | 3 +- Tests/GitHubReactions.Tests.ps1 | 28 ++- 3 files changed, 293 insertions(+), 99 deletions(-) diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index 30335ea4..40414316 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -11,10 +11,10 @@ filter Get-GitHubReaction { <# .SYNOPSIS - Retrieve reactions of a given GitHub issue. + Retrieve reactions of a given GitHub Issue or Pull Request. .DESCRIPTION - Retrieve reactions of a given GitHub issue. + Retrieve reactions of a given GitHub Issue or Pull Request. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -31,18 +31,21 @@ filter Get-GitHubReaction The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER IssueNumber - The issue *OR* pull request number. This parameter has an alias called - `PullRequestNumber` so that the experience feels natural but in this case, - PRs are handled the same as issues. + .PARAMETER Issue + The issue number. + + .PARAMETER PullRequest + The pull request number. .PARAMETER ReactionType - The type of reaction you want to retrieve. This is also called the 'content' in the GitHub API. - Valid options are based off: https://developer.github.com/v3/reactions/#reaction-types + The type of reaction you want to retrieve. This is also called the 'content' in + the GitHub API. Valid options are based off: + https://developer.github.com/v3/reactions/#reaction-types .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the - REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated. + REST Api. Otherwise, will attempt to use the configured value or will run + unauthenticated. .PARAMETER NoStatus If this switch is specified, long-running commands will run on the main thread @@ -59,56 +62,90 @@ filter Get-GitHubReaction GitHub.Reaction .EXAMPLE - Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -IssueNumber 157 + Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 - Gets the reactions for issue 157 from the Microsoft\PowerShellForGitHub project. + Gets the reactions for issue 157 from the Microsoft\PowerShellForGitHub + project. .EXAMPLE - Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -IssueNumber 157 -ReactionType eyes + Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 ` + -ReactionType eyes - Gets the 'eyes' reactions for issue 157 from the Microsoft\PowerShellForGitHub project. + Gets the 'eyes' reactions for issue 157 from the Microsoft\PowerShellForGitHub + project. .EXAMPLE - Get-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -IssueNumber 157 | Get-GitHubReaction + Get-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 | + Get-GitHubReaction - Gets a GitHub issue and pipe it into Get-GitHubReaction to get all the reactions for that issue. + Gets a GitHub issue and pipe it into Get-GitHubReaction to get all + the reactions for that issue. .EXAMPLE - Get-GitHubPullRequest -Uri https://github.com/microsoft/PowerShellForGitHub -PullRequest 193 | Get-GitHubReaction + Get-GitHubPullRequest -Uri https://github.com/microsoft/PowerShellForGitHub ` + -PullRequest 193 | Get-GitHubReaction - Gets a GitHub pull request and pipes it into Get-GitHubReaction to get all the reactions for that pull request. + Gets a GitHub pull request and pipes it into Get-GitHubReaction + to get all the reactions for that pull request. .NOTES - Currently, this only supports reacting to issues and pull requests. Issue comments, commit comments and PR comments will come later. + Currently, this only supports reacting to issues and pull requests. Issue comments, + commit comments and PR comments will come later. #> [CmdletBinding( SupportsShouldProcess, - DefaultParameterSetName='Elements')] + DefaultParameterSetName='ElementsIssue')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter( Mandatory, - ParameterSetName='Elements')] + ParameterSetName='ElementsIssue')] + [Parameter( + Mandatory, + ParameterSetName='ElementsPullRequest')] [string] $OwnerName, [Parameter( Mandatory, - ParameterSetName='Elements')] + ParameterSetName='ElementsIssue')] + [Parameter( + Mandatory, + ParameterSetName='ElementsPullRequest')] [string] $RepositoryName, [Parameter( Mandatory, ValueFromPipelineByPropertyName, - ParameterSetName='Uri')] + ParameterSetName='UriIssue')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='UriPullRequest')] [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] - [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] - [Alias('Issue')] + [Parameter( + Mandatory, + ParameterSetName='ElementsIssue', + ValueFromPipelineByPropertyName)] + [Parameter( + Mandatory, + ParameterSetName='UriIssue', + ValueFromPipelineByPropertyName)] + [Alias('IssueNumber')] + [int64] $Issue, + + [Parameter( + Mandatory, + ParameterSetName='ElementsPullRequest', + ValueFromPipelineByPropertyName)] + [Parameter( + Mandatory, + ParameterSetName='UriPullRequest', + ValueFromPipelineByPropertyName)] [Alias('PullRequestNumber')] - [int64] $IssueNumber, + [int64] $PullRequest, [ValidateSet('+1', '-1', 'Laugh', 'Confused', 'Heart', 'Hooray', 'Rocket', 'Eyes')] [string] $ReactionType, @@ -129,13 +166,31 @@ filter Get-GitHubReaction 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$IssueNumber/reactions" + $splatForAddedProperties = @{ + OwnerName = $OwnerName + Repository = $RepositoryName + } + + if ($Issue) + { + $issueOrPullRequest = $Issue + $descriptionText = "Issue" + $splatForAddedProperties.Issue = $Issue + } + else + { + $issueOrPullRequest = $PullRequest + $descriptionText = "Pull Request" + $splatForAddedProperties.PullRequest = $PullRequest + } + + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$issueOrPullRequest/reactions" if ($PSBoundParameters.ContainsKey('ReactionType')) { $uriFragment += "?content=" + [Uri]::EscapeDataString($ReactionType.ToLower()) } - $description = "Getting reactions for Issue $IssueNumber in $RepositoryName" + $description = "Getting reactions for $descriptionText $issueOrPullRequest in $RepositoryName" $params = @{ 'UriFragment' = $uriFragment @@ -148,18 +203,17 @@ filter Get-GitHubReaction } $result = Invoke-GHRestMethodMultipleResult @params - return ($result | - Add-GitHubReactionAdditionalProperties -OwnerName $OwnerName -RepositoryName $RepositoryName -IssueNumber $IssueNumber) + return ($result | Add-GitHubReactionAdditionalProperties @splatForAddedProperties) } filter Set-GitHubReaction { <# .SYNOPSIS - Sets a reaction of a given GitHub issue. + Sets a reaction of a given GitHub Issue or Pull Request. .DESCRIPTION - Sets a reaction of a given GitHub issue. + Sets a reaction of a given GitHub Issue or Pull Request. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -176,10 +230,11 @@ filter Set-GitHubReaction The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER IssueNumber - The issue *OR* pull request number. This parameter has an alias called - `PullRequestNumber` so that the experience feels natural but in this case, - PRs are handled the same as issues. + .PARAMETER Issue + The issue number. + + .PARAMETER PullRequest + The pull request number. .PARAMETER ReactionType The type of reaction you want to set. This is aslo called the 'content' in the GitHub API. @@ -204,47 +259,76 @@ filter Set-GitHubReaction GitHub.Reaction .EXAMPLE - Set-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -IssueNumber 12626 -ReactionType rocket + Set-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 ` + -ReactionType rocket Sets the 'rocket' reaction for issue 12626 of the PowerShell\PowerShell project. .EXAMPLE - Get-GitHubPullRequest -Uri https://github.com/microsoft/PowerShellForGitHub -PullRequest 193 | Set-GitHubReaction -ReactionType Heart + Get-GitHubPullRequest -Uri https://github.com/microsoft/PowerShellForGitHub ` + -PullRequest 193 | Set-GitHubReaction -ReactionType Heart - Gets a GitHub pull request and pipes it into Set-GitHubReaction to set the 'heart' reaction for that pull request. + Gets a GitHub pull request and pipes it into Set-GitHubReaction to set the + 'heart' reaction for that pull request. .NOTES - Currently, this only supports reacting to issues and pull requests. Issue comments, commit comments and PR comments will come later. + Currently, this only supports reacting to issues and pull requests. + Issue comments, commit comments and PR comments will come later. #> [CmdletBinding( SupportsShouldProcess, - DefaultParameterSetName='Elements')] + DefaultParameterSetName='ElementsIssue')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter( Mandatory, - ParameterSetName='Elements')] + ParameterSetName='ElementsIssue')] + [Parameter( + Mandatory, + ParameterSetName='ElementsPullRequest')] [string] $OwnerName, [Parameter( Mandatory, - ParameterSetName='Elements')] + ParameterSetName='ElementsIssue')] + [Parameter( + Mandatory, + ParameterSetName='ElementsPullRequest')] [string] $RepositoryName, [Parameter( Mandatory, ValueFromPipelineByPropertyName, - ParameterSetName='Uri')] + ParameterSetName='UriIssue')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='UriPullRequest')] [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] - [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] - [Alias('Issue')] - [Alias('PullRequest')] + [Parameter( + Mandatory, + ParameterSetName='ElementsIssue', + ValueFromPipelineByPropertyName)] + [Parameter( + Mandatory, + ParameterSetName='UriIssue', + ValueFromPipelineByPropertyName)] + [Alias('IssueNumber')] + [int64] $Issue, + + [Parameter( + Mandatory, + ParameterSetName='ElementsPullRequest', + ValueFromPipelineByPropertyName)] + [Parameter( + Mandatory, + ParameterSetName='UriPullRequest', + ValueFromPipelineByPropertyName)] [Alias('PullRequestNumber')] - [int64] $IssueNumber, + [int64] $PullRequest, [ValidateSet('+1', '-1', 'Laugh', 'Confused', 'Heart', 'Hooray', 'Rocket', 'Eyes')] [Parameter(Mandatory)] @@ -266,14 +350,32 @@ filter Set-GitHubReaction 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$IssueNumber/reactions" - $description = "Setting reaction $ReactionType for Issue $IssueNumber in $RepositoryName" + $splatForAddedProperties = @{ + OwnerName = $OwnerName + Repository = $RepositoryName + } + + if ($Issue) + { + $issueOrPullRequest = $Issue + $descriptionText = "Issue" + $splatForAddedProperties.Issue = $Issue + } + else + { + $issueOrPullRequest = $PullRequest + $descriptionText = "Pull Request" + $splatForAddedProperties.PullRequest = $PullRequest + } + + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$issueOrPullRequest/reactions" + $description = "Setting reaction $ReactionType for $descriptionText $issueOrPullRequest in $RepositoryName" $params = @{ 'UriFragment' = $uriFragment 'Description' = $description 'Method' = 'Post' - 'Body' = @{ content = $ReactionType.ToLower() } | ConvertTo-Json + 'Body' = ConvertTo-Json -InputObject @{ content = $ReactionType.ToLower() } 'AcceptHeader' = $script:squirrelGirlAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name @@ -282,18 +384,18 @@ filter Set-GitHubReaction } $result = Invoke-GHRestMethod @params - return ($result | - Add-GitHubReactionAdditionalProperties -OwnerName $OwnerName -RepositoryName $RepositoryName -IssueNumber $IssueNumber) + + return ($result | Add-GitHubReactionAdditionalProperties @splatForAddedProperties) } filter Remove-GitHubReaction { <# .SYNOPSIS - Removes a reaction on a given GitHub issue. + Removes a reaction on a given GitHub Issue or Pull Request. .DESCRIPTION - Removes a reaction on a given GitHub issue. + Removes a reaction on a given GitHub Issue or Pull Request. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -310,10 +412,11 @@ filter Remove-GitHubReaction The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER IssueNumber - The issue *OR* pull request number. This parameter has an alias called - `PullRequestNumber` so that the experience feels natural but in this case, - PRs are handled the same as issues. + .PARAMETER Issue + The issue number. + + .PARAMETER PullRequest + The pull request number. .PARAMETER ReactionId The Id of the reaction. You can get this from using Get-GitHubReaction. @@ -337,55 +440,89 @@ filter Remove-GitHubReaction None .EXAMPLE - Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -IssueNumber 12626 -ReactionId 1234 + Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 ` + -ReactionId 1234 - Remove a reaction by Id on Issue 12626 from the PowerShell\PowerShell project interactively. + Remove a reaction by Id on Issue 12626 from the PowerShell\PowerShell project + interactively. .EXAMPLE - Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -IssueNumber 12626 -ReactionId 1234 -Confirm:$false + Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 ` + -ReactionId 1234 -Confirm:$false - Remove a reaction by Id on Issue 12626 from the PowerShell\PowerShell project non-interactively. + Remove a reaction by Id on Issue 12626 from the PowerShell\PowerShell project + non-interactively. .EXAMPLE - Get-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -IssueNumber 12626 -ReactionType rocket | Remove-GitHubReaction -Confirm:$false + Get-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 ` + -ReactionType rocket | Remove-GitHubReaction -Confirm:$false Gets a reaction using Get-GitHubReaction and pipes it into Remove-GitHubReaction. .NOTES - Currently, this only supports reacting to issues and pull requests. Issue comments, commit comments and PR comments will come later. + Currently, this only supports reacting to issues and pull requests. + Issue comments, commit comments and PR comments will come later. #> [CmdletBinding( SupportsShouldProcess, - DefaultParameterSetName='Elements', + DefaultParameterSetName='ElementsIssue', ConfirmImpact='High')] [Alias('Delete-GitHubReaction')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter( Mandatory, - ParameterSetName='Elements')] + ParameterSetName='ElementsIssue')] + [Parameter( + Mandatory, + ParameterSetName='ElementsPullRequest')] [string] $OwnerName, [Parameter( Mandatory, - ParameterSetName='Elements')] + ParameterSetName='ElementsIssue')] + [Parameter( + Mandatory, + ParameterSetName='ElementsPullRequest')] [string] $RepositoryName, [Parameter( Mandatory, ValueFromPipelineByPropertyName, - ParameterSetName='Uri')] + ParameterSetName='UriIssue')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='UriPullRequest')] [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName='Elements', ValueFromPipelineByPropertyName)] - [Parameter(Mandatory, ParameterSetName='Uri', ValueFromPipelineByPropertyName)] - [Alias('Issue')] - [Alias('PullRequest')] + [Parameter( + Mandatory, + ParameterSetName='ElementsIssue', + ValueFromPipelineByPropertyName)] + [Parameter( + Mandatory, + ParameterSetName='UriIssue', + ValueFromPipelineByPropertyName)] + [Alias('IssueNumber')] + [int64] $Issue, + + [Parameter( + Mandatory, + ParameterSetName='ElementsPullRequest', + ValueFromPipelineByPropertyName)] + [Parameter( + Mandatory, + ParameterSetName='UriPullRequest', + ValueFromPipelineByPropertyName)] [Alias('PullRequestNumber')] - [int64] $IssueNumber, + [int64] $PullRequest, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ValueFromPipeline)] [int64] $ReactionId, [Parameter()] @@ -407,10 +544,28 @@ filter Remove-GitHubReaction 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$IssueNumber/reactions/$ReactionId" - $description = "Removing reaction $ReactionId for Issue $IssueNumber in $RepositoryName" + if ($Issue) + { + $issueOrPullRequest = $Issue + $descriptionText = "Issue" + } + else + { + $issueOrPullRequest = $PullRequest + $descriptionText = "Pull Request" + } + + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$issueOrPullRequest/reactions/$ReactionId" + $description = "Removing reaction $ReactionId for $descriptionText $issueOrPullRequest in $RepositoryName" + + if ($Force -and (-not $Confirm)) + { + $ConfirmPreference = 'None' + } - if ($Force.IsPresent -or $PSCmdlet.ShouldProcess($ReactionId, "Removing reaction for Issue $IssueNumber in $RepositoryName")) + if ($PSCmdlet.ShouldProcess( + $ReactionId, + "Removing reaction for $descriptionText $issueOrPullRequest in $RepositoryName")) { $params = @{ 'UriFragment' = $uriFragment @@ -432,12 +587,29 @@ filter Add-GitHubReactionAdditionalProperties <# .SYNOPSIS Adds type name and additional properties to ease pipelining to GitHub Reaction objects. + .PARAMETER InputObject The GitHub object to add additional properties to. + .PARAMETER TypeName The type that should be assigned to the object. + + .PARAMETER OwnerName + Owner of the repository. + If not supplied here, the DefaultOwnerName configuration property value will be used. + + .PARAMETER RepositoryName + Name of the repository. + If not supplied here, the DefaultRepositoryName configuration property value will be used. + + .PARAMETER Issue + The issue *OR* pull request number. This parameter has an alias called + `PullRequestNumber` so that the experience feels natural but in this case, + PRs are handled the same as issues. + .INPUTS [PSCustomObject] + .OUTPUTS GitHub.Reaction #> @@ -451,23 +623,28 @@ filter Add-GitHubReactionAdditionalProperties [AllowEmptyCollection()] [PSCustomObject[]] $InputObject, + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubReactionTypeName, + [Parameter(Mandatory)] [string] $OwnerName, [Parameter(Mandatory)] [string] $RepositoryName, - [Parameter(Mandatory)] - [string] $IssueNumber, + [Parameter( + Mandatory, + ParameterSetName='Issue')] + [Alias('IssueNumber')] + [int64] $Issue, - [ValidateNotNullOrEmpty()] - [string] $TypeName = $script:GitHubReactionTypeName + [Parameter( + Mandatory, + ParameterSetName='PullRequest')] + [Alias('PullRequestNumber')] + [int64] $PullRequest ) - if ($null -eq $InputObject) { - return - } - foreach ($item in $InputObject) { $item.PSObject.TypeNames.Insert(0, $TypeName) @@ -477,7 +654,15 @@ filter Add-GitHubReactionAdditionalProperties $repositoryUrl = Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force Add-Member -InputObject $item -Name 'ReactionId' -Value $item.id -MemberType NoteProperty -Force - Add-Member -InputObject $item -Name 'IssueNumber' -Value $IssueNumber -MemberType NoteProperty -Force + + if ($PullRequest) + { + Add-Member -InputObject $item -Name 'PullRequestNumber' -Value $PullRequest -MemberType NoteProperty -Force + } + else + { + Add-Member -InputObject $item -Name 'IssueNumber' -Value $Issue -MemberType NoteProperty -Force + } @('assignee', 'assignees', 'user') | ForEach-Object { diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index b3692284..d353b2f6 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -155,7 +155,8 @@ 'Delete-GitHubMilestone', 'Delete-GitHubProject', 'Delete-GitHubProjectCard', - 'Delete-GitHubProjectColumn' + 'Delete-GitHubProjectColumn', + 'Delete-GitHubReaction', 'Delete-GitHubRepository', 'Get-GitHubBranch', 'Get-GitHubComment', diff --git a/Tests/GitHubReactions.Tests.ps1 b/Tests/GitHubReactions.Tests.ps1 index f0d1c5bf..f2fef079 100644 --- a/Tests/GitHubReactions.Tests.ps1 +++ b/Tests/GitHubReactions.Tests.ps1 @@ -23,12 +23,14 @@ try } Describe 'Creating, modifying and deleting comments' { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - $issue = New-GitHubIssue -Uri $repo.svn_url -Title $defaultIssueTitle + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + $issue = New-GitHubIssue -Uri $repo.svn_url -Title $defaultIssueTitle + } Context 'For creating a reaction' { - Set-GitHubReaction -Uri $repo.svn_url -IssueNumber $issue.number -ReactionType $defaultReactionType - $existingReaction = Get-GitHubReaction -Uri $repo.svn_url -IssueNumber $issue.number + Set-GitHubReaction -Uri $repo.svn_url -Issue $issue.IssueNumber -ReactionType $defaultReactionType + $existingReaction = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.IssueNumber It "Should have the expected reaction type" { $existingReaction.content | Should be $defaultReactionType @@ -36,9 +38,9 @@ try } Context 'For getting reactions from an issue' { - Get-GitHubIssue -Uri $repo.svn_url -IssueNumber $issue.number | Set-GitHubReaction -ReactionType $otherReactionType - $allReactions = Get-GitHubReaction -Uri $repo.svn_url -IssueNumber $issue.number - $specificReactions = Get-GitHubReaction -Uri $repo.svn_url -IssueNumber $issue.number -ReactionType $otherReactionType + Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.IssueNumber | Set-GitHubReaction -ReactionType $otherReactionType + $allReactions = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.IssueNumber + $specificReactions = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.IssueNumber -ReactionType $otherReactionType It 'Should have the expected number of reactions' { $allReactions.Count | Should be 2 @@ -48,6 +50,8 @@ try It 'Should have the expected reaction content' { $specificReactions.content | Should be $otherReactionType $specificReactions.RepositoryUrl | Should be $repo.RepositoryUrl + $specificReactions.IssueNumber | Should be $issue.IssueNumber + $specificReactions.ReactionId | Should be $specificReactions.id } } @@ -73,6 +77,8 @@ try It 'Should have the expected reaction content' { $specificReactions.content | Should be $otherReactionType $specificReactions.RepositoryUrl | Should be $url + $specificReactions.PullRequestNumber | Should be $pr.PullRequestNumber + $specificReactions.ReactionId | Should be $specificReactions.id } } finally { $reaction1 | Remove-GitHubReaction -Force @@ -81,7 +87,7 @@ try } Context 'For getting reactions from an Issue and deleting them' { - $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -IssueNumber $issue.number) + $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number) It 'Should have the expected number of reactions' { $existingReactions.Count | Should be 2 @@ -89,7 +95,7 @@ try $existingReactions | Remove-GitHubReaction -Force - $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -IssueNumber $issue.number) + $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number) It 'Should have no reactions' { $existingReactions @@ -97,7 +103,9 @@ try } } - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + AfterAll { + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + } } } finally From 1d2a5acc88bbf97b8e4f11f11cd879c087dd1dd2 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 24 Jun 2020 21:32:49 -0700 Subject: [PATCH 11/18] Update .input --- GitHubAssignees.ps1 | 4 ++++ GitHubBranches.ps1 | 1 + GitHubContents.ps1 | 1 + GitHubEvents.ps1 | 1 + GitHubIssueComments.ps1 | 4 ++++ GitHubIssues.ps1 | 6 ++++++ GitHubLabels.ps1 | 8 +++++++ GitHubMilestones.ps1 | 4 ++++ GitHubMiscellaneous.ps1 | 5 ++--- GitHubProjects.ps1 | 2 ++ GitHubPullRequests.ps1 | 2 ++ GitHubReactions.ps1 | 42 +++++++++++++++++++++++++++++++++---- GitHubReleases.ps1 | 1 + GitHubRepositories.ps1 | 11 ++++++++++ GitHubRepositoryForks.ps1 | 2 ++ GitHubRepositoryTraffic.ps1 | 4 ++++ GitHubTeams.ps1 | 1 + 17 files changed, 92 insertions(+), 7 deletions(-) diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index eccc9810..7e1c3cdf 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -44,6 +44,7 @@ filter Get-GitHubAssignee GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository GitHub.User @@ -156,6 +157,7 @@ filter Test-GitHubAssignee GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository GitHub.User @@ -299,6 +301,7 @@ function New-GitHubAssignee GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository GitHub.User @@ -475,6 +478,7 @@ function Remove-GitHubAssignee GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubBranches.ps1 b/GitHubBranches.ps1 index 357d5792..872b491e 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -56,6 +56,7 @@ filter Get-GitHubRepositoryBranch GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubContents.ps1 b/GitHubContents.ps1 index 780a538d..a744f162 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -68,6 +68,7 @@ GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubEvents.ps1 b/GitHubEvents.ps1 index c904bc6a..000574af 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -58,6 +58,7 @@ filter Get-GitHubEvent GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubIssueComments.ps1 b/GitHubIssueComments.ps1 index a388db93..ab2afc8b 100644 --- a/GitHubIssueComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -79,6 +79,7 @@ filter Get-GitHubIssueComment GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -343,6 +344,7 @@ filter New-GitHubIssueComment GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository GitHub.User @@ -486,6 +488,7 @@ filter Set-GitHubIssueComment GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository GitHub.User @@ -616,6 +619,7 @@ filter Remove-GitHubIssueComment GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index fa043e3d..b9b3b40b 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -128,6 +128,7 @@ filter Get-GitHubIssue GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository GitHub.User @@ -431,6 +432,7 @@ filter Get-GitHubIssueTimeline GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -569,6 +571,7 @@ filter New-GitHubIssue GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -737,6 +740,7 @@ filter Update-GitHubIssue GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -886,6 +890,7 @@ filter Lock-GitHubIssue GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -1016,6 +1021,7 @@ filter Unlock-GitHubIssue GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index b020e54c..b3e8448d 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -63,6 +63,7 @@ filter Get-GitHubLabel GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -250,6 +251,7 @@ filter New-GitHubLabel GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -391,6 +393,7 @@ filter Remove-GitHubLabel GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -548,6 +551,7 @@ filter Update-GitHubLabel GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -693,6 +697,7 @@ filter Set-GitHubLabel GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -832,6 +837,7 @@ function Add-GitHubIssueLabel GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -992,6 +998,7 @@ function Set-GitHubIssueLabel GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -1183,6 +1190,7 @@ filter Remove-GitHubIssueLabel GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index 70b5b003..aefe5974 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -67,6 +67,7 @@ filter Get-GitHubMilestone GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -269,6 +270,7 @@ filter New-GitHubMilestone GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -450,6 +452,7 @@ filter Set-GitHubMilestone GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -630,6 +633,7 @@ filter Remove-GitHubMilestone GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubMiscellaneous.ps1 b/GitHubMiscellaneous.ps1 index 10f98fb5..872e924b 100644 --- a/GitHubMiscellaneous.ps1 +++ b/GitHubMiscellaneous.ps1 @@ -235,7 +235,6 @@ filter Get-GitHubLicense the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. - .INPUTS [String] GitHub.Branch @@ -249,10 +248,10 @@ filter Get-GitHubLicense GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository - .OUTPUTS GitHub.License @@ -487,10 +486,10 @@ filter Get-GitHubCodeOfConduct GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository - .OUTPUTS GitHub.CodeOfConduct diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 3476f263..c96dc30f 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -62,6 +62,7 @@ filter Get-GitHubProject GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -274,6 +275,7 @@ filter New-GitHubProject GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index c08c887a..b856ea31 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -76,6 +76,7 @@ filter Get-GitHubPullRequest GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -271,6 +272,7 @@ filter New-GitHubPullRequest GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index 40414316..b9969b5e 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -54,9 +54,20 @@ filter Get-GitHubReaction If not supplied here, the DefaultNoStatus configuration property value will be used. .INPUTS + GitHub.Branch + GitHub.Content + GitHub.Event GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn GitHub.Reaction + GitHub.Release + GitHub.Repository .OUTPUTS GitHub.Reaction @@ -251,9 +262,20 @@ filter Set-GitHubReaction If not supplied here, the DefaultNoStatus configuration property value will be used. .INPUTS + GitHub.Branch + GitHub.Content + GitHub.Event GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn GitHub.Reaction + GitHub.Release + GitHub.Repository .OUTPUTS GitHub.Reaction @@ -432,9 +454,20 @@ filter Remove-GitHubReaction If not supplied here, the DefaultNoStatus configuration property value will be used. .INPUTS + GitHub.Branch + GitHub.Content + GitHub.Event GitHub.Issue - GitHub.PullRequests + GitHub.IssueComment + GitHub.Label + GitHub.Milestone + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn GitHub.Reaction + GitHub.Release + GitHub.Repository .OUTPUTS None @@ -603,9 +636,10 @@ filter Add-GitHubReactionAdditionalProperties If not supplied here, the DefaultRepositoryName configuration property value will be used. .PARAMETER Issue - The issue *OR* pull request number. This parameter has an alias called - `PullRequestNumber` so that the experience feels natural but in this case, - PRs are handled the same as issues. + The issue number. + + .PARAMETER PullRequest + The pull request number. .INPUTS [PSCustomObject] diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index b4024828..018367e5 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -65,6 +65,7 @@ filter Get-GitHubRelease GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index e61bc1d5..46d947a2 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -276,6 +276,7 @@ filter Remove-GitHubRepository GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -442,6 +443,7 @@ filter Get-GitHubRepository GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -755,6 +757,7 @@ filter Rename-GitHubRepository GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -936,6 +939,7 @@ filter Update-GitHubRepository GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -1119,6 +1123,7 @@ filter Get-GitHubRepositoryTopic GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -1234,6 +1239,7 @@ function Set-GitHubRepositoryTopic GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -1421,6 +1427,7 @@ filter Get-GitHubRepositoryContributor GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -1569,6 +1576,7 @@ filter Get-GitHubRepositoryCollaborator GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -1682,6 +1690,7 @@ filter Get-GitHubRepositoryLanguage GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -1790,6 +1799,7 @@ filter Get-GitHubRepositoryTag GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -1904,6 +1914,7 @@ filter Move-GitHubRepositoryOwnership GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubRepositoryForks.ps1 b/GitHubRepositoryForks.ps1 index 457ee90d..18b5e79d 100644 --- a/GitHubRepositoryForks.ps1 +++ b/GitHubRepositoryForks.ps1 @@ -50,6 +50,7 @@ filter Get-GitHubRepositoryFork GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -167,6 +168,7 @@ filter New-GitHubRepositoryFork GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubRepositoryTraffic.ps1 b/GitHubRepositoryTraffic.ps1 index bcdcda13..130a2b2b 100644 --- a/GitHubRepositoryTraffic.ps1 +++ b/GitHubRepositoryTraffic.ps1 @@ -56,6 +56,7 @@ filter Get-GitHubReferrerTraffic GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -169,6 +170,7 @@ filter Get-GitHubPathTraffic GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -289,6 +291,7 @@ filter Get-GitHubViewTraffic GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository @@ -413,6 +416,7 @@ filter Get-GitHubCloneTraffic GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository diff --git a/GitHubTeams.ps1 b/GitHubTeams.ps1 index fa6da2cc..67d61be6 100644 --- a/GitHubTeams.ps1 +++ b/GitHubTeams.ps1 @@ -60,6 +60,7 @@ filter Get-GitHubTeam GitHub.Project GitHub.ProjectCard GitHub.ProjectColumn + GitHub.Reaction GitHub.Release GitHub.Repository GitHub.Team From d0d8d280449ee1c99aefb5b20283de7236d44f09 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 25 Jun 2020 11:02:24 -0700 Subject: [PATCH 12/18] added issue and pr comments --- GitHubReactions.ps1 | 241 +++++++++++++++++++++++--------- Tests/GitHubReactions.Tests.ps1 | 56 ++++++-- 2 files changed, 219 insertions(+), 78 deletions(-) diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index b9969b5e..f9ba72d6 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -37,6 +37,9 @@ filter Get-GitHubReaction .PARAMETER PullRequest The pull request number. + .PARAMETER Comment + The comment id. + .PARAMETER ReactionType The type of reaction you want to retrieve. This is also called the 'content' in the GitHub API. Valid options are based off: @@ -79,29 +82,31 @@ filter Get-GitHubReaction project. .EXAMPLE - Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 ` - -ReactionType eyes + Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 -ReactionType eyes Gets the 'eyes' reactions for issue 157 from the Microsoft\PowerShellForGitHub project. .EXAMPLE - Get-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 | - Get-GitHubReaction + Get-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 | Get-GitHubReaction Gets a GitHub issue and pipe it into Get-GitHubReaction to get all the reactions for that issue. .EXAMPLE - Get-GitHubPullRequest -Uri https://github.com/microsoft/PowerShellForGitHub ` - -PullRequest 193 | Get-GitHubReaction + Get-GitHubPullRequest -Uri https://github.com/microsoft/PowerShellForGitHub -PullRequest 193 | Get-GitHubReaction Gets a GitHub pull request and pipes it into Get-GitHubReaction to get all the reactions for that pull request. + .EXAMPLE + Get-GitHubIssueComment -Uri https://github.com/microsoft/PowerShellForGitHub -Comment 638276748 | Get-GitHubReaction + + Gets a GitHub issue comment and pipes it into Get-GitHubReaction + to get all the reactions for that issue comment. + .NOTES - Currently, this only supports reacting to issues and pull requests. Issue comments, - commit comments and PR comments will come later. + Currently, commit comments are not supported. #> [CmdletBinding( SupportsShouldProcess, @@ -115,6 +120,9 @@ filter Get-GitHubReaction [Parameter( Mandatory, ParameterSetName='ElementsPullRequest')] + [Parameter( + Mandatory, + ParameterSetName='ElementsComment')] [string] $OwnerName, [Parameter( @@ -123,6 +131,9 @@ filter Get-GitHubReaction [Parameter( Mandatory, ParameterSetName='ElementsPullRequest')] + [Parameter( + Mandatory, + ParameterSetName='ElementsComment')] [string] $RepositoryName, [Parameter( @@ -133,13 +144,17 @@ filter Get-GitHubReaction Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='UriPullRequest')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='UriComment')] [Alias('RepositoryUrl')] [string] $Uri, [Parameter( Mandatory, - ParameterSetName='ElementsIssue', - ValueFromPipelineByPropertyName)] + ValueFromPipelineByPropertyName, + ParameterSetName='ElementsIssue')] [Parameter( Mandatory, ParameterSetName='UriIssue', @@ -149,15 +164,26 @@ filter Get-GitHubReaction [Parameter( Mandatory, - ParameterSetName='ElementsPullRequest', - ValueFromPipelineByPropertyName)] + ValueFromPipelineByPropertyName, + ParameterSetName='ElementsPullRequest')] [Parameter( Mandatory, - ParameterSetName='UriPullRequest', - ValueFromPipelineByPropertyName)] + ValueFromPipelineByPropertyName, + ParameterSetName='UriPullRequest')] [Alias('PullRequestNumber')] [int64] $PullRequest, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='ElementsComment')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='UriComment')] + [Alias('CommentId')] + [int64] $Comment, + [ValidateSet('+1', '-1', 'Laugh', 'Confused', 'Heart', 'Hooray', 'Rocket', 'Eyes')] [string] $ReactionType, @@ -184,24 +210,33 @@ filter Get-GitHubReaction if ($Issue) { - $issueOrPullRequest = $Issue - $descriptionText = "Issue" $splatForAddedProperties.Issue = $Issue + $targetObjectNumber = $Issue + $targetObjectTypeName = 'Issue' + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions" } - else + elseif ($PullRequest) { - $issueOrPullRequest = $PullRequest - $descriptionText = "Pull Request" $splatForAddedProperties.PullRequest = $PullRequest + $targetObjectNumber = $PullRequest + $targetObjectTypeName = 'Pull Request' + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions" + } + else + { + # Comments + $splatForAddedProperties.Comment = $Comment + $targetObjectNumber = $Comment + $targetObjectTypeName = 'Comment' + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/comments/$targetObjectNumber/reactions" } - $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$issueOrPullRequest/reactions" if ($PSBoundParameters.ContainsKey('ReactionType')) { $uriFragment += "?content=" + [Uri]::EscapeDataString($ReactionType.ToLower()) } - $description = "Getting reactions for $descriptionText $issueOrPullRequest in $RepositoryName" + $description = "Getting reactions for $targetObjectTypeName $targetObjectNumber in $RepositoryName" $params = @{ 'UriFragment' = $uriFragment @@ -247,6 +282,9 @@ filter Set-GitHubReaction .PARAMETER PullRequest The pull request number. + .PARAMETER Comment + The comment id. + .PARAMETER ReactionType The type of reaction you want to set. This is aslo called the 'content' in the GitHub API. Valid options are based off: https://developer.github.com/v3/reactions/#reaction-types @@ -281,21 +319,24 @@ filter Set-GitHubReaction GitHub.Reaction .EXAMPLE - Set-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 ` - -ReactionType rocket + Set-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket Sets the 'rocket' reaction for issue 12626 of the PowerShell\PowerShell project. .EXAMPLE - Get-GitHubPullRequest -Uri https://github.com/microsoft/PowerShellForGitHub ` - -PullRequest 193 | Set-GitHubReaction -ReactionType Heart + Get-GitHubPullRequest -Uri https://github.com/microsoft/PowerShellForGitHub -PullRequest 193 | Set-GitHubReaction -ReactionType Heart Gets a GitHub pull request and pipes it into Set-GitHubReaction to set the 'heart' reaction for that pull request. + .EXAMPLE + Get-GitHubIssueComment -Uri https://github.com/microsoft/PowerShellForGitHub -Comment 638276748 | Set-GitHubReaction -Reaction Eyes + + Gets a GitHub issue comment and pipes it into Set-GitHubReaction to set the + 'eyes' reaction for that issue comment. + .NOTES - Currently, this only supports reacting to issues and pull requests. - Issue comments, commit comments and PR comments will come later. + Currently, commit comments are not supported. #> [CmdletBinding( SupportsShouldProcess, @@ -309,6 +350,9 @@ filter Set-GitHubReaction [Parameter( Mandatory, ParameterSetName='ElementsPullRequest')] + [Parameter( + Mandatory, + ParameterSetName='ElementsComment')] [string] $OwnerName, [Parameter( @@ -317,6 +361,9 @@ filter Set-GitHubReaction [Parameter( Mandatory, ParameterSetName='ElementsPullRequest')] + [Parameter( + Mandatory, + ParameterSetName='ElementsComment')] [string] $RepositoryName, [Parameter( @@ -327,13 +374,17 @@ filter Set-GitHubReaction Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='UriPullRequest')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='UriComment')] [Alias('RepositoryUrl')] [string] $Uri, [Parameter( Mandatory, - ParameterSetName='ElementsIssue', - ValueFromPipelineByPropertyName)] + ValueFromPipelineByPropertyName, + ParameterSetName='ElementsIssue')] [Parameter( Mandatory, ParameterSetName='UriIssue', @@ -343,15 +394,26 @@ filter Set-GitHubReaction [Parameter( Mandatory, - ParameterSetName='ElementsPullRequest', - ValueFromPipelineByPropertyName)] + ValueFromPipelineByPropertyName, + ParameterSetName='ElementsPullRequest')] [Parameter( Mandatory, - ParameterSetName='UriPullRequest', - ValueFromPipelineByPropertyName)] + ValueFromPipelineByPropertyName, + ParameterSetName='UriPullRequest')] [Alias('PullRequestNumber')] [int64] $PullRequest, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='ElementsComment')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='UriComment')] + [Alias('CommentId')] + [int64] $Comment, + [ValidateSet('+1', '-1', 'Laugh', 'Confused', 'Heart', 'Hooray', 'Rocket', 'Eyes')] [Parameter(Mandatory)] [string] $ReactionType, @@ -379,19 +441,28 @@ filter Set-GitHubReaction if ($Issue) { - $issueOrPullRequest = $Issue - $descriptionText = "Issue" $splatForAddedProperties.Issue = $Issue + $targetObjectNumber = $Issue + $targetObjectTypeName = 'Issue' + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions" } - else + elseif ($PullRequest) { - $issueOrPullRequest = $PullRequest - $descriptionText = "Pull Request" $splatForAddedProperties.PullRequest = $PullRequest + $targetObjectNumber = $PullRequest + $targetObjectTypeName = 'Pull Request' + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions" + } + else + { + # Comments + $splatForAddedProperties.Comment = $Comment + $targetObjectNumber = $Comment + $targetObjectTypeName = 'Comment' + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/comments/$targetObjectNumber/reactions" } - $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$issueOrPullRequest/reactions" - $description = "Setting reaction $ReactionType for $descriptionText $issueOrPullRequest in $RepositoryName" + $description = "Setting reaction $ReactionType for $targetObjectTypeName $targetObjectNumber in $RepositoryName" $params = @{ 'UriFragment' = $uriFragment @@ -440,9 +511,15 @@ filter Remove-GitHubReaction .PARAMETER PullRequest The pull request number. + .PARAMETER Comment + The comment id. + .PARAMETER ReactionId The Id of the reaction. You can get this from using Get-GitHubReaction. + .PARAMETER Force + If this switch is specified, you will not be prompted for confirmation of command execution. + .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated. @@ -480,21 +557,18 @@ filter Remove-GitHubReaction interactively. .EXAMPLE - Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 ` - -ReactionId 1234 -Confirm:$false + Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionId 1234 -Confirm:$false Remove a reaction by Id on Issue 12626 from the PowerShell\PowerShell project non-interactively. .EXAMPLE - Get-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 ` - -ReactionType rocket | Remove-GitHubReaction -Confirm:$false + Get-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket | Remove-GitHubReaction -Confirm:$false Gets a reaction using Get-GitHubReaction and pipes it into Remove-GitHubReaction. .NOTES - Currently, this only supports reacting to issues and pull requests. - Issue comments, commit comments and PR comments will come later. + Currently, commit comments are not supported. #> [CmdletBinding( SupportsShouldProcess, @@ -509,6 +583,9 @@ filter Remove-GitHubReaction [Parameter( Mandatory, ParameterSetName='ElementsPullRequest')] + [Parameter( + Mandatory, + ParameterSetName='ElementsComment')] [string] $OwnerName, [Parameter( @@ -517,6 +594,9 @@ filter Remove-GitHubReaction [Parameter( Mandatory, ParameterSetName='ElementsPullRequest')] + [Parameter( + Mandatory, + ParameterSetName='ElementsComment')] [string] $RepositoryName, [Parameter( @@ -527,13 +607,17 @@ filter Remove-GitHubReaction Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='UriPullRequest')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='UriComment')] [Alias('RepositoryUrl')] [string] $Uri, [Parameter( Mandatory, - ParameterSetName='ElementsIssue', - ValueFromPipelineByPropertyName)] + ValueFromPipelineByPropertyName, + ParameterSetName='ElementsIssue')] [Parameter( Mandatory, ParameterSetName='UriIssue', @@ -543,15 +627,26 @@ filter Remove-GitHubReaction [Parameter( Mandatory, - ParameterSetName='ElementsPullRequest', - ValueFromPipelineByPropertyName)] + ValueFromPipelineByPropertyName, + ParameterSetName='ElementsPullRequest')] [Parameter( Mandatory, - ParameterSetName='UriPullRequest', - ValueFromPipelineByPropertyName)] + ValueFromPipelineByPropertyName, + ParameterSetName='UriPullRequest')] [Alias('PullRequestNumber')] [int64] $PullRequest, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='ElementsComment')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='UriComment')] + [Alias('CommentId')] + [int64] $Comment, + [Parameter( Mandatory, ValueFromPipelineByPropertyName, @@ -579,17 +674,25 @@ filter Remove-GitHubReaction if ($Issue) { - $issueOrPullRequest = $Issue - $descriptionText = "Issue" + $targetObjectNumber = $Issue + $targetObjectTypeName = 'Issue' + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions/$ReactionId" + } + elseif ($PullRequest) + { + $targetObjectNumber = $PullRequest + $targetObjectTypeName = 'Pull Request' + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions/$ReactionId" } else { - $issueOrPullRequest = $PullRequest - $descriptionText = "Pull Request" + # Comments + $targetObjectNumber = $Comment + $targetObjectTypeName = 'Comment' + $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/comments/$targetObjectNumber/reactions/$ReactionId" } - $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$issueOrPullRequest/reactions/$ReactionId" - $description = "Removing reaction $ReactionId for $descriptionText $issueOrPullRequest in $RepositoryName" + $description = "Removing reaction $ReactionId for $targetObjectTypeName $targetObjectNumber in $RepositoryName" if ($Force -and (-not $Confirm)) { @@ -598,7 +701,7 @@ filter Remove-GitHubReaction if ($PSCmdlet.ShouldProcess( $ReactionId, - "Removing reaction for $descriptionText $issueOrPullRequest in $RepositoryName")) + "Removing reaction for $targetObjectTypeName $targetObjectNumber in $RepositoryName")) { $params = @{ 'UriFragment' = $uriFragment @@ -629,11 +732,9 @@ filter Add-GitHubReactionAdditionalProperties .PARAMETER OwnerName Owner of the repository. - If not supplied here, the DefaultOwnerName configuration property value will be used. .PARAMETER RepositoryName Name of the repository. - If not supplied here, the DefaultRepositoryName configuration property value will be used. .PARAMETER Issue The issue number. @@ -641,6 +742,9 @@ filter Add-GitHubReactionAdditionalProperties .PARAMETER PullRequest The pull request number. + .PARAMETER Comment + The comment id. + .INPUTS [PSCustomObject] @@ -676,7 +780,13 @@ filter Add-GitHubReactionAdditionalProperties Mandatory, ParameterSetName='PullRequest')] [Alias('PullRequestNumber')] - [int64] $PullRequest + [int64] $PullRequest, + + [Parameter( + Mandatory, + ParameterSetName='Comment')] + [Alias('CommentId')] + [int64] $Comment ) foreach ($item in $InputObject) @@ -693,10 +803,15 @@ filter Add-GitHubReactionAdditionalProperties { Add-Member -InputObject $item -Name 'PullRequestNumber' -Value $PullRequest -MemberType NoteProperty -Force } - else + elseif ($Issue) { Add-Member -InputObject $item -Name 'IssueNumber' -Value $Issue -MemberType NoteProperty -Force } + else + { + # Comment + Add-Member -InputObject $item -Name 'CommentId' -Value $Comment -MemberType NoteProperty -Force + } @('assignee', 'assignees', 'user') | ForEach-Object { diff --git a/Tests/GitHubReactions.Tests.ps1 b/Tests/GitHubReactions.Tests.ps1 index f2fef079..a4bf5b17 100644 --- a/Tests/GitHubReactions.Tests.ps1 +++ b/Tests/GitHubReactions.Tests.ps1 @@ -26,6 +26,10 @@ try BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit $issue = New-GitHubIssue -Uri $repo.svn_url -Title $defaultIssueTitle + $issueComment = $issue | New-GitHubIssueComment -Body "Foo" + + # To get rid of linting issue saying this variable isn't used. + $issueComment.CommentId } Context 'For creating a reaction' { @@ -33,7 +37,7 @@ try $existingReaction = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.IssueNumber It "Should have the expected reaction type" { - $existingReaction.content | Should be $defaultReactionType + $existingReaction.content | Should -Be $defaultReactionType } } @@ -43,15 +47,16 @@ try $specificReactions = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.IssueNumber -ReactionType $otherReactionType It 'Should have the expected number of reactions' { - $allReactions.Count | Should be 2 - $specificReactions.Count | Should be 1 + $allReactions.Count | Should -Be 2 + $specificReactions.Count | Should -Be 1 } It 'Should have the expected reaction content' { - $specificReactions.content | Should be $otherReactionType - $specificReactions.RepositoryUrl | Should be $repo.RepositoryUrl - $specificReactions.IssueNumber | Should be $issue.IssueNumber - $specificReactions.ReactionId | Should be $specificReactions.id + $specificReactions.content | Should -Be $otherReactionType + $specificReactions.RepositoryUrl | Should -Be $repo.RepositoryUrl + $specificReactions.IssueNumber | Should -Be $issue.IssueNumber + $specificReactions.ReactionId | Should -Be $specificReactions.id + $specificReactions.PSObject.TypeNames[0] | Should -Be 'GitHub.Reaction' } } @@ -70,15 +75,16 @@ try $specificReactions = $pr | Get-GitHubReaction -ReactionType $otherReactionType It 'Should have the expected number of reactions' { - $allReactions.Count | Should be 2 - $specificReactions.Count | Should be 1 + $allReactions.Count | Should -Be 2 + $specificReactions.Count | Should -Be 1 } It 'Should have the expected reaction content' { - $specificReactions.content | Should be $otherReactionType - $specificReactions.RepositoryUrl | Should be $url - $specificReactions.PullRequestNumber | Should be $pr.PullRequestNumber - $specificReactions.ReactionId | Should be $specificReactions.id + $specificReactions.content | Should -Be $otherReactionType + $specificReactions.RepositoryUrl | Should -Be $url + $specificReactions.PullRequestNumber | Should -Be $pr.PullRequestNumber + $specificReactions.ReactionId | Should -Be $specificReactions.id + $specificReactions.PSObject.TypeNames[0] | Should -Be 'GitHub.Reaction' } } finally { $reaction1 | Remove-GitHubReaction -Force @@ -86,11 +92,31 @@ try } } + Context 'For getting reactions from an issue comment' { + Set-GitHubReaction -Uri $repo.svn_url -Comment $issueComment.CommentId -ReactionType $defaultReactionType + $issueComment | Set-GitHubReaction -ReactionType $otherReactionType + $allReactions = Get-GitHubReaction -Uri $repo.svn_url -Comment $issueComment.CommentId + $specificReactions = Get-GitHubReaction -Uri $repo.svn_url -Comment $issueComment.CommentId -ReactionType $otherReactionType + + It 'Should have the expected number of reactions' { + $allReactions.Count | Should -Be 2 + $specificReactions.Count | Should -Be 1 + } + + It 'Should have the expected reaction content' { + $specificReactions.content | Should -Be $otherReactionType + $specificReactions.RepositoryUrl | Should -Be $repo.RepositoryUrl + $specificReactions.CommentId | Should -Be $issueComment.CommentId + $specificReactions.ReactionId | Should -Be $specificReactions.id + $specificReactions.PSObject.TypeNames[0] | Should -Be 'GitHub.Reaction' + } + } + Context 'For getting reactions from an Issue and deleting them' { $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number) It 'Should have the expected number of reactions' { - $existingReactions.Count | Should be 2 + $existingReactions.Count | Should -Be 2 } $existingReactions | Remove-GitHubReaction -Force @@ -99,7 +125,7 @@ try It 'Should have no reactions' { $existingReactions - $existingReactions.Count | Should be 0 + $existingReactions.Count | Should -Be 0 } } From e1c190e15fadac13edb4965e7dad3a54768a8eec Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 25 Jun 2020 14:35:13 -0700 Subject: [PATCH 13/18] misc feedback --- GitHubReactions.ps1 | 14 ++++++++++---- Tests/GitHubReactions.Tests.ps1 | 10 ++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index f9ba72d6..7ccd0efc 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -38,7 +38,7 @@ filter Get-GitHubReaction The pull request number. .PARAMETER Comment - The comment id. + The comment ID. .PARAMETER ReactionType The type of reaction you want to retrieve. This is also called the 'content' in @@ -228,6 +228,8 @@ filter Get-GitHubReaction $splatForAddedProperties.Comment = $Comment $targetObjectNumber = $Comment $targetObjectTypeName = 'Comment' + + # Even for PR comments, you can use the same endpoint as issue comments. $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/comments/$targetObjectNumber/reactions" } @@ -283,7 +285,7 @@ filter Set-GitHubReaction The pull request number. .PARAMETER Comment - The comment id. + The comment ID. .PARAMETER ReactionType The type of reaction you want to set. This is aslo called the 'content' in the GitHub API. @@ -459,6 +461,8 @@ filter Set-GitHubReaction $splatForAddedProperties.Comment = $Comment $targetObjectNumber = $Comment $targetObjectTypeName = 'Comment' + + # Even for PR comments, you can use the same endpoint as issue comments. $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/comments/$targetObjectNumber/reactions" } @@ -512,7 +516,7 @@ filter Remove-GitHubReaction The pull request number. .PARAMETER Comment - The comment id. + The comment ID. .PARAMETER ReactionId The Id of the reaction. You can get this from using Get-GitHubReaction. @@ -689,6 +693,8 @@ filter Remove-GitHubReaction # Comments $targetObjectNumber = $Comment $targetObjectTypeName = 'Comment' + + # Even for PR comments, you can use the same endpoint as issue comments. $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/comments/$targetObjectNumber/reactions/$ReactionId" } @@ -743,7 +749,7 @@ filter Add-GitHubReactionAdditionalProperties The pull request number. .PARAMETER Comment - The comment id. + The comment ID. .INPUTS [PSCustomObject] diff --git a/Tests/GitHubReactions.Tests.ps1 b/Tests/GitHubReactions.Tests.ps1 index a4bf5b17..a09bfef7 100644 --- a/Tests/GitHubReactions.Tests.ps1 +++ b/Tests/GitHubReactions.Tests.ps1 @@ -3,9 +3,14 @@ <# .Synopsis - Tests for GitHubReactions.ps1 module + Tests for GitHubAssignees.ps1 module #> +[CmdletBinding()] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', + Justification='Suppress false positives in Pester code blocks')] +param() + # This is common test code setup logic for all Pester test files $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent . (Join-Path -Path $moduleRootPath -ChildPath 'Tests\Common.ps1') @@ -27,9 +32,6 @@ try $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit $issue = New-GitHubIssue -Uri $repo.svn_url -Title $defaultIssueTitle $issueComment = $issue | New-GitHubIssueComment -Body "Foo" - - # To get rid of linting issue saying this variable isn't used. - $issueComment.CommentId } Context 'For creating a reaction' { From da7f4ff82edf1a2bb58d1f4688730fbcb736a892 Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Fri, 26 Jun 2020 09:29:44 -0700 Subject: [PATCH 14/18] typo --- Tests/GitHubReactions.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/GitHubReactions.Tests.ps1 b/Tests/GitHubReactions.Tests.ps1 index a09bfef7..e5b4b538 100644 --- a/Tests/GitHubReactions.Tests.ps1 +++ b/Tests/GitHubReactions.Tests.ps1 @@ -3,7 +3,7 @@ <# .Synopsis - Tests for GitHubAssignees.ps1 module + Tests for GitHubReactions.ps1 module #> [CmdletBinding()] From cc9493204fd3931718864ca7faff7668ec67a787 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Fri, 26 Jun 2020 09:48:08 -0700 Subject: [PATCH 15/18] test fix for PS5 --- Tests/GitHubReactions.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/GitHubReactions.Tests.ps1 b/Tests/GitHubReactions.Tests.ps1 index e5b4b538..def5e125 100644 --- a/Tests/GitHubReactions.Tests.ps1 +++ b/Tests/GitHubReactions.Tests.ps1 @@ -50,7 +50,7 @@ try It 'Should have the expected number of reactions' { $allReactions.Count | Should -Be 2 - $specificReactions.Count | Should -Be 1 + $specificReactions | Measure-Object | Select-Object -ExpandProperty Count | Should -Be 1 } It 'Should have the expected reaction content' { @@ -78,7 +78,7 @@ try It 'Should have the expected number of reactions' { $allReactions.Count | Should -Be 2 - $specificReactions.Count | Should -Be 1 + $specificReactions | Measure-Object | Select-Object -ExpandProperty Count | Should -Be 1 } It 'Should have the expected reaction content' { @@ -102,7 +102,7 @@ try It 'Should have the expected number of reactions' { $allReactions.Count | Should -Be 2 - $specificReactions.Count | Should -Be 1 + $specificReactions | Measure-Object | Select-Object -ExpandProperty Count | Should -Be 1 } It 'Should have the expected reaction content' { From df88faf5c2ea5dbaf578893814592b7a252cce3b Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Fri, 26 Jun 2020 11:45:21 -0700 Subject: [PATCH 16/18] Make PR test get only until Branch cmdlets are in --- Tests/GitHubReactions.Tests.ps1 | 39 +++++++++++++-------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/Tests/GitHubReactions.Tests.ps1 b/Tests/GitHubReactions.Tests.ps1 index def5e125..6b09a46f 100644 --- a/Tests/GitHubReactions.Tests.ps1 +++ b/Tests/GitHubReactions.Tests.ps1 @@ -67,30 +67,21 @@ try # When those go in, this test can be refactored to use those so the test is more reliable using a test PR. $url = 'https://github.com/microsoft/PowerShellForGitHub' $pr = Get-GitHubPullRequest -Uri $url -PullRequest 193 - $pr | Get-GitHubReaction | Remove-GitHubReaction -ErrorAction Ignore -Confirm:$false - - $reaction1 = $pr | Set-GitHubReaction -ReactionType $defaultReactionType - $reaction2 = $pr | Set-GitHubReaction -ReactionType $otherReactionType - - try { - $allReactions = $pr | Get-GitHubReaction - $specificReactions = $pr | Get-GitHubReaction -ReactionType $otherReactionType - - It 'Should have the expected number of reactions' { - $allReactions.Count | Should -Be 2 - $specificReactions | Measure-Object | Select-Object -ExpandProperty Count | Should -Be 1 - } - - It 'Should have the expected reaction content' { - $specificReactions.content | Should -Be $otherReactionType - $specificReactions.RepositoryUrl | Should -Be $url - $specificReactions.PullRequestNumber | Should -Be $pr.PullRequestNumber - $specificReactions.ReactionId | Should -Be $specificReactions.id - $specificReactions.PSObject.TypeNames[0] | Should -Be 'GitHub.Reaction' - } - } finally { - $reaction1 | Remove-GitHubReaction -Force - $reaction2 | Remove-GitHubReaction -Force + + $allReactions = $pr | Get-GitHubReaction + $specificReactions = $pr | Get-GitHubReaction -ReactionType $otherReactionType + + It 'Should have the expected number of reactions' { + $allReactions.Count | Should -Be 2 + $specificReactions | Measure-Object | Select-Object -ExpandProperty Count | Should -Be 1 + } + + It 'Should have the expected reaction content' { + $specificReactions.content | Should -Be $otherReactionType + $specificReactions.RepositoryUrl | Should -Be $url + $specificReactions.PullRequestNumber | Should -Be $pr.PullRequestNumber + $specificReactions.ReactionId | Should -Be $specificReactions.id + $specificReactions.PSObject.TypeNames[0] | Should -Be 'GitHub.Reaction' } } From c33871b508cf68411121f46eb9e08a4be0fe3920 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 15 Jul 2020 11:24:05 -0700 Subject: [PATCH 17/18] remove comments --- GitHubReactions.ps1 | 147 +++----------------------------- Tests/GitHubReactions.Tests.ps1 | 22 +---- 2 files changed, 13 insertions(+), 156 deletions(-) diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index 7ccd0efc..47c6e992 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -37,9 +37,6 @@ filter Get-GitHubReaction .PARAMETER PullRequest The pull request number. - .PARAMETER Comment - The comment ID. - .PARAMETER ReactionType The type of reaction you want to retrieve. This is also called the 'content' in the GitHub API. Valid options are based off: @@ -99,14 +96,8 @@ filter Get-GitHubReaction Gets a GitHub pull request and pipes it into Get-GitHubReaction to get all the reactions for that pull request. - .EXAMPLE - Get-GitHubIssueComment -Uri https://github.com/microsoft/PowerShellForGitHub -Comment 638276748 | Get-GitHubReaction - - Gets a GitHub issue comment and pipes it into Get-GitHubReaction - to get all the reactions for that issue comment. - .NOTES - Currently, commit comments are not supported. + Currently, issue comments, pull request comments and commit comments are not supported. #> [CmdletBinding( SupportsShouldProcess, @@ -120,9 +111,6 @@ filter Get-GitHubReaction [Parameter( Mandatory, ParameterSetName='ElementsPullRequest')] - [Parameter( - Mandatory, - ParameterSetName='ElementsComment')] [string] $OwnerName, [Parameter( @@ -131,9 +119,6 @@ filter Get-GitHubReaction [Parameter( Mandatory, ParameterSetName='ElementsPullRequest')] - [Parameter( - Mandatory, - ParameterSetName='ElementsComment')] [string] $RepositoryName, [Parameter( @@ -144,10 +129,6 @@ filter Get-GitHubReaction Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='UriPullRequest')] - [Parameter( - Mandatory, - ValueFromPipelineByPropertyName, - ParameterSetName='UriComment')] [Alias('RepositoryUrl')] [string] $Uri, @@ -173,17 +154,6 @@ filter Get-GitHubReaction [Alias('PullRequestNumber')] [int64] $PullRequest, - [Parameter( - Mandatory, - ValueFromPipelineByPropertyName, - ParameterSetName='ElementsComment')] - [Parameter( - Mandatory, - ValueFromPipelineByPropertyName, - ParameterSetName='UriComment')] - [Alias('CommentId')] - [int64] $Comment, - [ValidateSet('+1', '-1', 'Laugh', 'Confused', 'Heart', 'Hooray', 'Rocket', 'Eyes')] [string] $ReactionType, @@ -215,23 +185,14 @@ filter Get-GitHubReaction $targetObjectTypeName = 'Issue' $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions" } - elseif ($PullRequest) + else { + # Pull Request $splatForAddedProperties.PullRequest = $PullRequest $targetObjectNumber = $PullRequest $targetObjectTypeName = 'Pull Request' $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions" } - else - { - # Comments - $splatForAddedProperties.Comment = $Comment - $targetObjectNumber = $Comment - $targetObjectTypeName = 'Comment' - - # Even for PR comments, you can use the same endpoint as issue comments. - $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/comments/$targetObjectNumber/reactions" - } if ($PSBoundParameters.ContainsKey('ReactionType')) { @@ -284,9 +245,6 @@ filter Set-GitHubReaction .PARAMETER PullRequest The pull request number. - .PARAMETER Comment - The comment ID. - .PARAMETER ReactionType The type of reaction you want to set. This is aslo called the 'content' in the GitHub API. Valid options are based off: https://developer.github.com/v3/reactions/#reaction-types @@ -331,14 +289,8 @@ filter Set-GitHubReaction Gets a GitHub pull request and pipes it into Set-GitHubReaction to set the 'heart' reaction for that pull request. - .EXAMPLE - Get-GitHubIssueComment -Uri https://github.com/microsoft/PowerShellForGitHub -Comment 638276748 | Set-GitHubReaction -Reaction Eyes - - Gets a GitHub issue comment and pipes it into Set-GitHubReaction to set the - 'eyes' reaction for that issue comment. - .NOTES - Currently, commit comments are not supported. + Currently, issue comments, pull request comments and commit comments are not supported. #> [CmdletBinding( SupportsShouldProcess, @@ -352,9 +304,6 @@ filter Set-GitHubReaction [Parameter( Mandatory, ParameterSetName='ElementsPullRequest')] - [Parameter( - Mandatory, - ParameterSetName='ElementsComment')] [string] $OwnerName, [Parameter( @@ -363,9 +312,6 @@ filter Set-GitHubReaction [Parameter( Mandatory, ParameterSetName='ElementsPullRequest')] - [Parameter( - Mandatory, - ParameterSetName='ElementsComment')] [string] $RepositoryName, [Parameter( @@ -376,10 +322,6 @@ filter Set-GitHubReaction Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='UriPullRequest')] - [Parameter( - Mandatory, - ValueFromPipelineByPropertyName, - ParameterSetName='UriComment')] [Alias('RepositoryUrl')] [string] $Uri, @@ -405,17 +347,6 @@ filter Set-GitHubReaction [Alias('PullRequestNumber')] [int64] $PullRequest, - [Parameter( - Mandatory, - ValueFromPipelineByPropertyName, - ParameterSetName='ElementsComment')] - [Parameter( - Mandatory, - ValueFromPipelineByPropertyName, - ParameterSetName='UriComment')] - [Alias('CommentId')] - [int64] $Comment, - [ValidateSet('+1', '-1', 'Laugh', 'Confused', 'Heart', 'Hooray', 'Rocket', 'Eyes')] [Parameter(Mandatory)] [string] $ReactionType, @@ -448,23 +379,14 @@ filter Set-GitHubReaction $targetObjectTypeName = 'Issue' $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions" } - elseif ($PullRequest) + else { + # Pull request $splatForAddedProperties.PullRequest = $PullRequest $targetObjectNumber = $PullRequest $targetObjectTypeName = 'Pull Request' $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions" } - else - { - # Comments - $splatForAddedProperties.Comment = $Comment - $targetObjectNumber = $Comment - $targetObjectTypeName = 'Comment' - - # Even for PR comments, you can use the same endpoint as issue comments. - $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/comments/$targetObjectNumber/reactions" - } $description = "Setting reaction $ReactionType for $targetObjectTypeName $targetObjectNumber in $RepositoryName" @@ -515,9 +437,6 @@ filter Remove-GitHubReaction .PARAMETER PullRequest The pull request number. - .PARAMETER Comment - The comment ID. - .PARAMETER ReactionId The Id of the reaction. You can get this from using Get-GitHubReaction. @@ -572,7 +491,7 @@ filter Remove-GitHubReaction Gets a reaction using Get-GitHubReaction and pipes it into Remove-GitHubReaction. .NOTES - Currently, commit comments are not supported. + Currently, issue comments, pull request comments and commit comments are not supported. #> [CmdletBinding( SupportsShouldProcess, @@ -587,9 +506,6 @@ filter Remove-GitHubReaction [Parameter( Mandatory, ParameterSetName='ElementsPullRequest')] - [Parameter( - Mandatory, - ParameterSetName='ElementsComment')] [string] $OwnerName, [Parameter( @@ -598,9 +514,6 @@ filter Remove-GitHubReaction [Parameter( Mandatory, ParameterSetName='ElementsPullRequest')] - [Parameter( - Mandatory, - ParameterSetName='ElementsComment')] [string] $RepositoryName, [Parameter( @@ -611,10 +524,6 @@ filter Remove-GitHubReaction Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='UriPullRequest')] - [Parameter( - Mandatory, - ValueFromPipelineByPropertyName, - ParameterSetName='UriComment')] [Alias('RepositoryUrl')] [string] $Uri, @@ -640,17 +549,6 @@ filter Remove-GitHubReaction [Alias('PullRequestNumber')] [int64] $PullRequest, - [Parameter( - Mandatory, - ValueFromPipelineByPropertyName, - ParameterSetName='ElementsComment')] - [Parameter( - Mandatory, - ValueFromPipelineByPropertyName, - ParameterSetName='UriComment')] - [Alias('CommentId')] - [int64] $Comment, - [Parameter( Mandatory, ValueFromPipelineByPropertyName, @@ -682,21 +580,13 @@ filter Remove-GitHubReaction $targetObjectTypeName = 'Issue' $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions/$ReactionId" } - elseif ($PullRequest) + else { + # Pull request $targetObjectNumber = $PullRequest $targetObjectTypeName = 'Pull Request' $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions/$ReactionId" } - else - { - # Comments - $targetObjectNumber = $Comment - $targetObjectTypeName = 'Comment' - - # Even for PR comments, you can use the same endpoint as issue comments. - $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/comments/$targetObjectNumber/reactions/$ReactionId" - } $description = "Removing reaction $ReactionId for $targetObjectTypeName $targetObjectNumber in $RepositoryName" @@ -748,9 +638,6 @@ filter Add-GitHubReactionAdditionalProperties .PARAMETER PullRequest The pull request number. - .PARAMETER Comment - The comment ID. - .INPUTS [PSCustomObject] @@ -786,13 +673,7 @@ filter Add-GitHubReactionAdditionalProperties Mandatory, ParameterSetName='PullRequest')] [Alias('PullRequestNumber')] - [int64] $PullRequest, - - [Parameter( - Mandatory, - ParameterSetName='Comment')] - [Alias('CommentId')] - [int64] $Comment + [int64] $PullRequest ) foreach ($item in $InputObject) @@ -809,14 +690,10 @@ filter Add-GitHubReactionAdditionalProperties { Add-Member -InputObject $item -Name 'PullRequestNumber' -Value $PullRequest -MemberType NoteProperty -Force } - elseif ($Issue) - { - Add-Member -InputObject $item -Name 'IssueNumber' -Value $Issue -MemberType NoteProperty -Force - } else { - # Comment - Add-Member -InputObject $item -Name 'CommentId' -Value $Comment -MemberType NoteProperty -Force + # Issue + Add-Member -InputObject $item -Name 'IssueNumber' -Value $Issue -MemberType NoteProperty -Force } @('assignee', 'assignees', 'user') | diff --git a/Tests/GitHubReactions.Tests.ps1 b/Tests/GitHubReactions.Tests.ps1 index 6b09a46f..703b7f43 100644 --- a/Tests/GitHubReactions.Tests.ps1 +++ b/Tests/GitHubReactions.Tests.ps1 @@ -27,7 +27,7 @@ try Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value } - Describe 'Creating, modifying and deleting comments' { + Describe 'Creating, modifying and deleting reactions' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit $issue = New-GitHubIssue -Uri $repo.svn_url -Title $defaultIssueTitle @@ -85,26 +85,6 @@ try } } - Context 'For getting reactions from an issue comment' { - Set-GitHubReaction -Uri $repo.svn_url -Comment $issueComment.CommentId -ReactionType $defaultReactionType - $issueComment | Set-GitHubReaction -ReactionType $otherReactionType - $allReactions = Get-GitHubReaction -Uri $repo.svn_url -Comment $issueComment.CommentId - $specificReactions = Get-GitHubReaction -Uri $repo.svn_url -Comment $issueComment.CommentId -ReactionType $otherReactionType - - It 'Should have the expected number of reactions' { - $allReactions.Count | Should -Be 2 - $specificReactions | Measure-Object | Select-Object -ExpandProperty Count | Should -Be 1 - } - - It 'Should have the expected reaction content' { - $specificReactions.content | Should -Be $otherReactionType - $specificReactions.RepositoryUrl | Should -Be $repo.RepositoryUrl - $specificReactions.CommentId | Should -Be $issueComment.CommentId - $specificReactions.ReactionId | Should -Be $specificReactions.id - $specificReactions.PSObject.TypeNames[0] | Should -Be 'GitHub.Reaction' - } - } - Context 'For getting reactions from an Issue and deleting them' { $existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number) From 7f4eb9b673ea610e15d9b9e639b2aa63586c3a45 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 16 Jul 2020 10:59:41 -0700 Subject: [PATCH 18/18] LF to CRLF --- PowerShellForGitHub.psd1 | 468 +++++++++++++++++++-------------------- 1 file changed, 234 insertions(+), 234 deletions(-) diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index 84d0f780..1b2eadfe 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -1,234 +1,234 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -@{ - GUID = '9e8dfd44-f782-445a-883c-70614f71519c' - Author = 'Microsoft Corporation' - CompanyName = 'Microsoft Corporation' - Copyright = 'Copyright (C) Microsoft Corporation. All rights reserved.' - - ModuleVersion = '0.14.0' - Description = 'PowerShell wrapper for GitHub API' - - # Script module or binary module file associated with this manifest. - RootModule = 'PowerShellForGitHub.psm1' - - # Format files (.ps1xml) to be loaded when importing this module - FormatsToProcess = @( - 'Formatters/GitHubRepositories.Format.ps1xml' - ) - - # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess - NestedModules = @( - # Ideally this list would be kept completely alphabetical, but other scripts (like - # GitHubConfiguration.ps1) depend on some of the code in Helpers being around at load time. - 'Helpers.ps1', - 'GitHubConfiguration.ps1', - - 'GitHubAnalytics.ps1', - 'GitHubAssignees.ps1', - 'GitHubBranches.ps1', - 'GitHubCore.ps1', - 'GitHubContents.ps1', - 'GitHubEvents.ps1', - 'GitHubIssueComments.ps1', - 'GitHubIssues.ps1', - 'GitHubLabels.ps1', - 'GitHubMilestones.ps1', - 'GitHubMiscellaneous.ps1', - 'GitHubOrganizations.ps1', - 'GitHubProjects.ps1', - 'GitHubProjectCards.ps1', - 'GitHubProjectColumns.ps1', - 'GitHubPullRequests.ps1', - 'GitHubReactions.ps1', - 'GitHubReleases.ps1', - 'GitHubRepositories.ps1', - 'GitHubRepositoryForks.ps1', - 'GitHubRepositoryTraffic.ps1', - 'GitHubTeams.ps1', - 'GitHubUsers.ps1', - 'Telemetry.ps1', - 'UpdateCheck.ps1') - - # Minimum version of the Windows PowerShell engine required by this module - PowerShellVersion = '4.0' - - # Functions to export from this module - FunctionsToExport = @( - 'Add-GitHubAssignee', - 'Add-GitHubIssueLabel', - 'Backup-GitHubConfiguration', - 'Clear-GitHubAuthentication', - 'ConvertFrom-GitHubMarkdown', - 'Disable-GitHubRepositorySecurityFix', - 'Disable-GitHubRepositoryVulnerabilityAlert', - 'Enable-GitHubRepositorySecurityFix', - 'Enable-GitHubRepositoryVulnerabilityAlert', - 'Get-GitHubAssignee', - 'Get-GitHubCloneTraffic', - 'Get-GitHubCodeOfConduct', - 'Get-GitHubConfiguration', - 'Get-GitHubContent', - 'Get-GitHubEmoji', - 'Get-GitHubEvent', - 'Get-GitHubGitIgnore', - 'Get-GitHubIssue', - 'Get-GitHubIssueComment', - 'Get-GitHubIssueTimeline', - 'Get-GitHubLabel', - 'Get-GitHubLicense', - 'Get-GitHubMilestone', - 'Get-GitHubOrganizationMember', - 'Get-GitHubPathTraffic', - 'Get-GitHubProject', - 'Get-GitHubProjectCard', - 'Get-GitHubProjectColumn', - 'Get-GitHubPullRequest', - 'Get-GitHubRateLimit', - 'Get-GitHubReaction', - 'Get-GitHubReferrerTraffic', - 'Get-GitHubRelease', - 'Get-GitHubRepository', - 'Get-GitHubRepositoryBranch', - 'Get-GitHubRepositoryCollaborator', - 'Get-GitHubRepositoryContributor', - 'Get-GitHubRepositoryFork', - 'Get-GitHubRepositoryLanguage', - 'Get-GitHubRepositoryTag', - 'Get-GitHubRepositoryTopic', - 'Get-GitHubRepositoryUniqueContributor', - 'Get-GitHubTeam', - 'Get-GitHubTeamMember', - 'Get-GitHubUser', - 'Get-GitHubUserContextualInformation', - 'Get-GitHubViewTraffic', - 'Group-GitHubIssue', - 'Group-GitHubPullRequest', - 'Initialize-GitHubLabel', - 'Invoke-GHRestMethod', - 'Invoke-GHRestMethodMultipleResult', - 'Join-GitHubUri', - 'Lock-GitHubIssue', - 'Move-GitHubProjectCard', - 'Move-GitHubProjectColumn', - 'Move-GitHubRepositoryOwnership', - 'New-GitHubIssue', - 'New-GitHubIssueComment', - 'New-GitHubLabel', - 'New-GitHubMilestone', - 'New-GitHubProject', - 'New-GitHubProjectCard', - 'New-GitHubProjectColumn', - 'New-GitHubPullRequest', - 'New-GitHubRepository', - 'New-GitHubRepositoryFromTemplate', - 'New-GitHubRepositoryFork', - 'Remove-GitHubAssignee', - 'Remove-GitHubIssueComment', - 'Remove-GitHubIssueLabel', - 'Remove-GitHubLabel', - 'Remove-GitHubMilestone', - 'Remove-GitHubProject', - 'Remove-GitHubProjectCard', - 'Remove-GitHubProjectColumn', - 'Remove-GitHubReaction', - 'Remove-GitHubRepository', - 'Rename-GitHubRepository', - 'Reset-GitHubConfiguration', - 'Restore-GitHubConfiguration', - 'Set-GitHubAuthentication', - 'Set-GitHubConfiguration', - 'Set-GitHubContent', - 'Set-GitHubIssue', - 'Set-GitHubIssueComment', - 'Set-GitHubIssueLabel', - 'Set-GitHubLabel', - 'Set-GitHubMilestone', - 'Set-GitHubProfile', - 'Set-GitHubProject', - 'Set-GitHubProjectCard', - 'Set-GitHubProjectColumn', - 'Set-GitHubReaction', - 'Set-GitHubRepository', - 'Set-GitHubRepositoryTopic', - 'Split-GitHubUri', - 'Test-GitHubAssignee', - 'Test-GitHubAuthenticationConfigured', - 'Test-GitHubOrganizationMember', - 'Test-GitHubRepositoryVulnerabilityAlert', - 'Unlock-GitHubIssue' - ) - - AliasesToExport = @( - 'Delete-GitHubComment', - 'Delete-GitHubIssueComment', - 'Delete-GitHubLabel', - 'Delete-GitHubMilestone', - 'Delete-GitHubProject', - 'Delete-GitHubProjectCard', - 'Delete-GitHubProjectColumn', - 'Delete-GitHubReaction', - 'Delete-GitHubRepository', - 'Get-GitHubBranch', - 'Get-GitHubComment', - 'New-GitHubAssignee', - 'New-GitHubComment', - 'Remove-GitHubComment', - 'Set-GitHubComment', - 'Transfer-GitHubRepositoryOwnership' - 'Update-GitHubIssue', - 'Update-GitHubLabel', - 'Update-GitHubCurrentUser', - 'Update-GitHubRepository' - ) - - # Cmdlets to export from this module - # CmdletsToExport = '*' - - # Variables to export from this module - # VariablesToExport = '*' - - # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. - PrivateData = @{ - - PSData = @{ - - # Tags applied to this module. These help with module discovery in online galleries. - Tags = @('GitHub', 'API', 'PowerShell') - - # A URL to the license for this module. - LicenseUri = 'https://aka.ms/PowerShellForGitHub_License' - - # A URL to the main website for this project. - ProjectUri = 'https://aka.ms/PowerShellForGitHub' - - # A URL to an icon representing this module. - # IconUri = '' - - # ReleaseNotes of this module - ReleaseNotes = 'https://github.com/microsoft/PowerShellForGitHub/blob/master/CHANGELOG.md' - } - } - - # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. - # DefaultCommandPrefix = 'GH' - - # Modules that must be imported into the global environment prior to importing this module - # RequiredModules = @() - - # Assemblies that must be loaded prior to importing this module - # RequiredAssemblies = @() - - # Script files (.ps1) that are run in the caller's environment prior to importing this module. - # ScriptsToProcess = @() - - # List of all modules packaged with this module - # ModuleList = @() - - # List of all files packaged with this module - # FileList = @() - - # HelpInfo URI of this module - # HelpInfoURI = '' -} +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +@{ + GUID = '9e8dfd44-f782-445a-883c-70614f71519c' + Author = 'Microsoft Corporation' + CompanyName = 'Microsoft Corporation' + Copyright = 'Copyright (C) Microsoft Corporation. All rights reserved.' + + ModuleVersion = '0.14.0' + Description = 'PowerShell wrapper for GitHub API' + + # Script module or binary module file associated with this manifest. + RootModule = 'PowerShellForGitHub.psm1' + + # Format files (.ps1xml) to be loaded when importing this module + FormatsToProcess = @( + 'Formatters/GitHubRepositories.Format.ps1xml' + ) + + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess + NestedModules = @( + # Ideally this list would be kept completely alphabetical, but other scripts (like + # GitHubConfiguration.ps1) depend on some of the code in Helpers being around at load time. + 'Helpers.ps1', + 'GitHubConfiguration.ps1', + + 'GitHubAnalytics.ps1', + 'GitHubAssignees.ps1', + 'GitHubBranches.ps1', + 'GitHubCore.ps1', + 'GitHubContents.ps1', + 'GitHubEvents.ps1', + 'GitHubIssueComments.ps1', + 'GitHubIssues.ps1', + 'GitHubLabels.ps1', + 'GitHubMilestones.ps1', + 'GitHubMiscellaneous.ps1', + 'GitHubOrganizations.ps1', + 'GitHubProjects.ps1', + 'GitHubProjectCards.ps1', + 'GitHubProjectColumns.ps1', + 'GitHubPullRequests.ps1', + 'GitHubReactions.ps1', + 'GitHubReleases.ps1', + 'GitHubRepositories.ps1', + 'GitHubRepositoryForks.ps1', + 'GitHubRepositoryTraffic.ps1', + 'GitHubTeams.ps1', + 'GitHubUsers.ps1', + 'Telemetry.ps1', + 'UpdateCheck.ps1') + + # Minimum version of the Windows PowerShell engine required by this module + PowerShellVersion = '4.0' + + # Functions to export from this module + FunctionsToExport = @( + 'Add-GitHubAssignee', + 'Add-GitHubIssueLabel', + 'Backup-GitHubConfiguration', + 'Clear-GitHubAuthentication', + 'ConvertFrom-GitHubMarkdown', + 'Disable-GitHubRepositorySecurityFix', + 'Disable-GitHubRepositoryVulnerabilityAlert', + 'Enable-GitHubRepositorySecurityFix', + 'Enable-GitHubRepositoryVulnerabilityAlert', + 'Get-GitHubAssignee', + 'Get-GitHubCloneTraffic', + 'Get-GitHubCodeOfConduct', + 'Get-GitHubConfiguration', + 'Get-GitHubContent', + 'Get-GitHubEmoji', + 'Get-GitHubEvent', + 'Get-GitHubGitIgnore', + 'Get-GitHubIssue', + 'Get-GitHubIssueComment', + 'Get-GitHubIssueTimeline', + 'Get-GitHubLabel', + 'Get-GitHubLicense', + 'Get-GitHubMilestone', + 'Get-GitHubOrganizationMember', + 'Get-GitHubPathTraffic', + 'Get-GitHubProject', + 'Get-GitHubProjectCard', + 'Get-GitHubProjectColumn', + 'Get-GitHubPullRequest', + 'Get-GitHubRateLimit', + 'Get-GitHubReaction', + 'Get-GitHubReferrerTraffic', + 'Get-GitHubRelease', + 'Get-GitHubRepository', + 'Get-GitHubRepositoryBranch', + 'Get-GitHubRepositoryCollaborator', + 'Get-GitHubRepositoryContributor', + 'Get-GitHubRepositoryFork', + 'Get-GitHubRepositoryLanguage', + 'Get-GitHubRepositoryTag', + 'Get-GitHubRepositoryTopic', + 'Get-GitHubRepositoryUniqueContributor', + 'Get-GitHubTeam', + 'Get-GitHubTeamMember', + 'Get-GitHubUser', + 'Get-GitHubUserContextualInformation', + 'Get-GitHubViewTraffic', + 'Group-GitHubIssue', + 'Group-GitHubPullRequest', + 'Initialize-GitHubLabel', + 'Invoke-GHRestMethod', + 'Invoke-GHRestMethodMultipleResult', + 'Join-GitHubUri', + 'Lock-GitHubIssue', + 'Move-GitHubProjectCard', + 'Move-GitHubProjectColumn', + 'Move-GitHubRepositoryOwnership', + 'New-GitHubIssue', + 'New-GitHubIssueComment', + 'New-GitHubLabel', + 'New-GitHubMilestone', + 'New-GitHubProject', + 'New-GitHubProjectCard', + 'New-GitHubProjectColumn', + 'New-GitHubPullRequest', + 'New-GitHubRepository', + 'New-GitHubRepositoryFromTemplate', + 'New-GitHubRepositoryFork', + 'Remove-GitHubAssignee', + 'Remove-GitHubIssueComment', + 'Remove-GitHubIssueLabel', + 'Remove-GitHubLabel', + 'Remove-GitHubMilestone', + 'Remove-GitHubProject', + 'Remove-GitHubProjectCard', + 'Remove-GitHubProjectColumn', + 'Remove-GitHubReaction', + 'Remove-GitHubRepository', + 'Rename-GitHubRepository', + 'Reset-GitHubConfiguration', + 'Restore-GitHubConfiguration', + 'Set-GitHubAuthentication', + 'Set-GitHubConfiguration', + 'Set-GitHubContent', + 'Set-GitHubIssue', + 'Set-GitHubIssueComment', + 'Set-GitHubIssueLabel', + 'Set-GitHubLabel', + 'Set-GitHubMilestone', + 'Set-GitHubProfile', + 'Set-GitHubProject', + 'Set-GitHubProjectCard', + 'Set-GitHubProjectColumn', + 'Set-GitHubReaction', + 'Set-GitHubRepository', + 'Set-GitHubRepositoryTopic', + 'Split-GitHubUri', + 'Test-GitHubAssignee', + 'Test-GitHubAuthenticationConfigured', + 'Test-GitHubOrganizationMember', + 'Test-GitHubRepositoryVulnerabilityAlert', + 'Unlock-GitHubIssue' + ) + + AliasesToExport = @( + 'Delete-GitHubComment', + 'Delete-GitHubIssueComment', + 'Delete-GitHubLabel', + 'Delete-GitHubMilestone', + 'Delete-GitHubProject', + 'Delete-GitHubProjectCard', + 'Delete-GitHubProjectColumn', + 'Delete-GitHubReaction', + 'Delete-GitHubRepository', + 'Get-GitHubBranch', + 'Get-GitHubComment', + 'New-GitHubAssignee', + 'New-GitHubComment', + 'Remove-GitHubComment', + 'Set-GitHubComment', + 'Transfer-GitHubRepositoryOwnership' + 'Update-GitHubIssue', + 'Update-GitHubLabel', + 'Update-GitHubCurrentUser', + 'Update-GitHubRepository' + ) + + # Cmdlets to export from this module + # CmdletsToExport = '*' + + # Variables to export from this module + # VariablesToExport = '*' + + # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. + PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + Tags = @('GitHub', 'API', 'PowerShell') + + # A URL to the license for this module. + LicenseUri = 'https://aka.ms/PowerShellForGitHub_License' + + # A URL to the main website for this project. + ProjectUri = 'https://aka.ms/PowerShellForGitHub' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + ReleaseNotes = 'https://github.com/microsoft/PowerShellForGitHub/blob/master/CHANGELOG.md' + } + } + + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + # DefaultCommandPrefix = 'GH' + + # Modules that must be imported into the global environment prior to importing this module + # RequiredModules = @() + + # Assemblies that must be loaded prior to importing this module + # RequiredAssemblies = @() + + # Script files (.ps1) that are run in the caller's environment prior to importing this module. + # ScriptsToProcess = @() + + # List of all modules packaged with this module + # ModuleList = @() + + # List of all files packaged with this module + # FileList = @() + + # HelpInfo URI of this module + # HelpInfoURI = '' +}