From efcc6e68401301ccca6937d0274b739eaedb1d1e Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Thu, 4 Jun 2020 01:05:10 -0700 Subject: [PATCH 01/80] Initial thinking on pipelining --- GitHubCore.ps1 | 35 ++++++++++++++++++ GitHubRepositories.ps1 | 84 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 111 insertions(+), 8 deletions(-) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 4a095b65..21d42f1d 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -782,6 +782,41 @@ function Split-GitHubUri } } +function Join-GitHubUri +{ +<# + .SYNOPSIS + Combines the provided repository elements into a repository URL. + + .DESCRIPTION + Combines the provided repository elements into a repository URL. + + The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub + + .PARAMETER OwnerName + Owner of the repository. + + .PARAMETER RepositoryName + Name of the repository. + + .OUTPUTS + [String] - The repository URL. +#> + [CmdletBinding()] + param + ( + [Parameter(Mandatory)] + [string] $OwnerName, + + [Parameter(Mandatory)] + [string] $RepositoryName + ) + + + $hostName = (Get-GitHubConfiguration -Name 'ApiHostName') + return "https://$hostName/$OwnerName/$RepositoryName" +} + function Resolve-RepositoryElements { <# diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index f962d1d4..0ac8501c 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -188,7 +188,12 @@ function New-GitHubRepository 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + $result = Invoke-GHRestMethod @params + + # Add additional property to ease pipelining + Add-Member -InputObject $result -Name 'RepositoryUrl' -Value $result.html_url -MemberType NoteProperty -Force + + return $result } function Remove-GitHubRepository @@ -258,7 +263,9 @@ function Remove-GitHubRepository [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [switch] $Force, @@ -409,7 +416,9 @@ function Get-GitHubRepository [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter(ParameterSetName='Organization')] @@ -601,7 +610,15 @@ function Get-GitHubRepository 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + $multipleResult = Invoke-GHRestMethodMultipleResult @params + + # Add additional property to ease pipelining + foreach ($result in $multipleResult) + { + Add-Member -InputObject $result -Name 'RepositoryUrl' -Value $result.html_url -MemberType NoteProperty -Force + } + + return $multipleResult } function Rename-GitHubRepository @@ -689,10 +706,11 @@ function Rename-GitHubRepository Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='Uri')] - [Alias("html_url")] + [Alias("RepositoryUrl")] [string] $Uri, - [parameter(Mandatory)][String]$NewName, + [parameter(Mandatory)] + [String]$NewName, [switch] $Force, @@ -733,7 +751,12 @@ function Rename-GitHubRepository 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + $result = Invoke-GHRestMethod @params + + # Add additional property to ease pipelining + Add-Member -InputObject $result -Name 'RepositoryUrl' -Value $result.html_url -MemberType NoteProperty -Force + + return $result } } } @@ -841,7 +864,9 @@ function Update-GitHubRepository [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [string] $Description, @@ -916,7 +941,12 @@ function Update-GitHubRepository 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + $result = Invoke-GHRestMethod @params + + # Add additional property to ease pipelining + Add-Member -InputObject $result -Name 'RepositoryUrl' -Value $result.html_url -MemberType NoteProperty -Force + + return $result } function Get-GitHubRepositoryTopic @@ -972,7 +1002,9 @@ function Get-GitHubRepositoryTopic [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [string] $AccessToken, @@ -1003,6 +1035,11 @@ function Get-GitHubRepositoryTopic } return Invoke-GHRestMethod @params + + # Add additional property to ease pipelining + Add-Member -InputObject $result -Name 'RepositoryUrl' -Value (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) -MemberType NoteProperty -Force + + return $result } function Set-GitHubRepositoryTopic @@ -1066,10 +1103,13 @@ function Set-GitHubRepositoryTopic [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='UriName')] [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='UriClear')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter( @@ -1132,6 +1172,11 @@ function Set-GitHubRepositoryTopic } return Invoke-GHRestMethod @params + + # Add additional property to ease pipelining + Add-Member -InputObject $result -Name 'RepositoryUrl' -Value (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) -MemberType NoteProperty -Force + + return $result } function Get-GitHubRepositoryContributor @@ -1203,7 +1248,9 @@ function Get-GitHubRepositoryContributor [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [switch] $IncludeAnonymousContributors, @@ -1302,7 +1349,9 @@ function Get-GitHubRepositoryCollaborator [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [string] $AccessToken, @@ -1390,7 +1439,9 @@ function Get-GitHubRepositoryLanguage [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [string] $AccessToken, @@ -1474,7 +1525,9 @@ function Get-GitHubRepositoryTag [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [string] $AccessToken, @@ -1502,7 +1555,15 @@ function Get-GitHubRepositoryTag 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + $multipleResult = Invoke-GHRestMethodMultipleResult @params + + # Add additional property to ease pipelining + foreach ($result in $multipleResult) + { + Add-Member -InputObject $result -Name 'RepositoryUrl' -Value (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) -MemberType NoteProperty -Force + } + + return $multipleResult } function Move-GitHubRepositoryOwnership @@ -1563,7 +1624,9 @@ function Move-GitHubRepositoryOwnership [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter(Mandatory)] @@ -1605,5 +1668,10 @@ function Move-GitHubRepositoryOwnership 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + $result = Invoke-GHRestMethod @params + + # Add additional property to ease pipelining + Add-Member -InputObject $result -Name 'RepositoryUrl' -Value (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) -MemberType NoteProperty -Force + + return $result } From 85cfcf88640f734d3f42e80875291b9ec08159ff Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Thu, 4 Jun 2020 17:14:18 -0700 Subject: [PATCH 02/80] More WIP --- GitHubConfiguration.ps1 | 11 +++++++ GitHubRepositories.ps1 | 66 ++++++++++++++++++++++++++++++++++++++++ GitHubUsers.ps1 | 50 +++++++++++++++++++++++++++--- PowerShellForGitHub.psd1 | 5 +++ 4 files changed, 128 insertions(+), 4 deletions(-) diff --git a/GitHubConfiguration.ps1 b/GitHubConfiguration.ps1 index c66c4b77..308ebe8e 100644 --- a/GitHubConfiguration.ps1 +++ b/GitHubConfiguration.ps1 @@ -95,6 +95,13 @@ function Set-GitHubConfiguration Specify this switch to disable the hashing of potential PII data prior to submitting the data to telemetry (if telemetry hasn't been disabled via DisableTelemetry). + .PARAMETER DisablePipelineSupport + By default, this module will modify all objects returned by the API calls by adding + additional, consistent properties to those objects which ease pipelining those objects + into other functions. This is highly convenient functionality. You would only want to + disable this functionality if you are experiencing some edge case problems and are awaiting + a proper fix. + .PARAMETER DisableSmarterObjects By default, this module will modify all objects returned by the API calls to update any properties that can be converted to objects (like strings for Date/Time's being @@ -189,6 +196,8 @@ function Set-GitHubConfiguration [switch] $DisablePiiProtection, + [switch] $DisablePipelineSupport, + [switch] $DisableSmarterObjects, [switch] $DisableTelemetry, @@ -279,6 +288,7 @@ function Get-GitHubConfiguration 'DefaultRepositoryName', 'DisableLogging', 'DisablePiiProtection', + 'DisablePipelineSupport', 'DisableSmarterObjects', 'DisableTelemetry', 'DisableUpdateCheck', @@ -613,6 +623,7 @@ function Import-GitHubConfiguration 'applicationInsightsKey' = '66d83c52-3070-489b-886b-09860e05e78a' 'disableLogging' = ([String]::IsNullOrEmpty($logPath)) 'disablePiiProtection' = $false + 'disablePipelineSupport' = $false 'disableSmarterObjects' = $false 'disableTelemetry' = $false 'disableUpdateCheck' = $false diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 0ac8501c..fb68157b 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -1,6 +1,18 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +@{ + GitHubRepositoryTypeName = 'GitHub.Repository' + GitHubRepositoryTopicTypeName = 'GitHub.RepositoryTopic' + GitHubRepositoryContributorTypeName = 'GitHub.RepositoryContributor' + GitHubRepositoryCollaboratorTypeName = 'GitHub.RepositoryCollaborator' + GitHubRepositoryLanguageTypeName = 'GitHub.RepositoryLanguage' + GitHubRepositoryTagTypeName = 'GitHub.RepositoryTag' + + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + function New-GitHubRepository { <# @@ -92,6 +104,7 @@ function New-GitHubRepository New-GitHubRepository -RepositoryName MyNewRepo -Organization MyOrg -DisallowRebaseMerge #> [CmdletBinding(SupportsShouldProcess)] + #[OutputType({$script:GitHubRepositoryTypeName})] [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)] @@ -1675,3 +1688,56 @@ function Move-GitHubRepositoryOwnership return $result } + +filter Set-GitHubRepositoryAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Repository objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER OwnerName + Owner of the repository. This information might be obtainable from InputObject, so this + is option based on what InputObject contains. + + .PARAMETER RepositoryName + Name of the repository. This information might be obtainable from InputObject, so this + is option based on what InputObject contains. +#> + [CmdletBinding()] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [PSCustomObject[]] $InputObject, + + [string] $OwnerName, + + [string] $RepositoryName + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $script:GitHubRepositoryTypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + $repositoryUrl = $item.html_url + if (-not [String]::IsNullOrEmpty($repositoryUrl)) + { + $repositoryUrl = (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) + } + + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + } + + if ($null -ne $item.owner) + { + Set-GitHubUserAdditionalProperties -InputObject $item.owner + } + + Write-Output $item + } +} diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 3a77bca4..c80db955 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -1,7 +1,14 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubUser +@{ + GitHubUserTypeName = 'GitHub.User' + + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + + function Get-GitHubUser { <# .SYNOPSIS @@ -80,15 +87,18 @@ function Get-GitHubUser if ($Current) { - return Invoke-GHRestMethod -UriFragment "user" -Description "Getting current authenticated user" -Method 'Get' @params + return (Invoke-GHRestMethod -UriFragment "user" -Description "Getting current authenticated user" -Method 'Get' @params | + Set-GitHubUserAdditionalProperties) } elseif ([String]::IsNullOrEmpty($User)) { - return Invoke-GHRestMethodMultipleResult -UriFragment 'users' -Description 'Getting all users' @params + return (Invoke-GHRestMethodMultipleResult -UriFragment 'users' -Description 'Getting all users' @params | + Set-GitHubUserAdditionalProperties) } else { - return Invoke-GHRestMethod -UriFragment "users/$User" -Description "Getting user $User" -Method 'Get' @params + return (Invoke-GHRestMethod -UriFragment "users/$User" -Description "Getting user $User" -Method 'Get' @params | + Set-GitHubUserAdditionalProperties) } } @@ -277,3 +287,35 @@ function Update-GitHubCurrentUser return Invoke-GHRestMethod @params } + +filter Set-GitHubUserAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub User objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. +#> + [CmdletBinding()] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [PSCustomObject[]] $InputObject + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $script:GitHubUserTypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + Add-Member -InputObject $item -Name 'OwnerName' -Value $item.login -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'UserName' -Value $item.login -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'UserId' -Value $item.id -MemberType NoteProperty -Force + } + + Write-Output $item + } +} diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index 5ef27773..9bfd4871 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -50,6 +50,11 @@ # Functions to export from this module FunctionsToExport = @( + 'Set-GitHubUserAdditionalProperties', + + + + 'Add-GitHubIssueLabel', 'Backup-GitHubConfiguration', 'Clear-GitHubAuthentication', From c8fc4d804a2eae7c22ef665e9a2b66152f3b660d Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 5 Jun 2020 11:50:19 -0700 Subject: [PATCH 03/80] Completing work for GitHubUser.ps1 and GitHubRepositories.ps1 --- GitHubCore.ps1 | 1 + GitHubRepositories.ps1 | 240 +++++++++++++++++++++-------------------- GitHubUsers.ps1 | 67 ++++++++++-- 3 files changed, 183 insertions(+), 125 deletions(-) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 21d42f1d..98175419 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -803,6 +803,7 @@ function Join-GitHubUri [String] - The repository URL. #> [CmdletBinding()] + [OutputType([String])] param ( [Parameter(Mandatory)] diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index fb68157b..c79b8b26 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -8,12 +8,11 @@ GitHubRepositoryCollaboratorTypeName = 'GitHub.RepositoryCollaborator' GitHubRepositoryLanguageTypeName = 'GitHub.RepositoryLanguage' GitHubRepositoryTagTypeName = 'GitHub.RepositoryTag' - }.GetEnumerator() | ForEach-Object { Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value } -function New-GitHubRepository +filter New-GitHubRepository { <# .SYNOPSIS @@ -97,6 +96,9 @@ function New-GitHubRepository the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Repository + .EXAMPLE New-GitHubRepository -RepositoryName MyNewRepo -AutoInit @@ -104,10 +106,12 @@ function New-GitHubRepository New-GitHubRepository -RepositoryName MyNewRepo -Organization MyOrg -DisallowRebaseMerge #> [CmdletBinding(SupportsShouldProcess)] - #[OutputType({$script:GitHubRepositoryTypeName})] + [OutputType({$script:GitHubRepositoryTypeName})] [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)] + [Parameter( + Mandatory, + ValueFromPipeline)] [ValidateNotNullOrEmpty()] [string] $RepositoryName, @@ -201,15 +205,11 @@ function New-GitHubRepository 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - $result = Invoke-GHRestMethod @params - - # Add additional property to ease pipelining - Add-Member -InputObject $result -Name 'RepositoryUrl' -Value $result.html_url -MemberType NoteProperty -Force - - return $result + return (Invoke-GHRestMethod @params | + Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) } -function Remove-GitHubRepository +filter Remove-GitHubRepository { <# .SYNOPSIS @@ -320,7 +320,7 @@ function Remove-GitHubRepository } } -function Get-GitHubRepository +filter Get-GitHubRepository { <# .SYNOPSIS @@ -390,6 +390,9 @@ function Get-GitHubRepository the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Repository + .EXAMPLE Get-GitHubRepository @@ -418,10 +421,13 @@ function Get-GitHubRepository [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='AuthenticatedUser')] + [OutputType({$script:GitHubRepositoryTypeName})] [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(ParameterSetName='ElementsOrUser')] + [Parameter( + ValueFromPipelineByPropertyName, + ParameterSetName='ElementsOrUser')] [string] $OwnerName, [Parameter(ParameterSetName='ElementsOrUser')] @@ -434,7 +440,9 @@ function Get-GitHubRepository [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(ParameterSetName='Organization')] + [Parameter( + ValueFromPipelineByPropertyName, + ParameterSetName='Organization')] [string] $OrganizationName, [ValidateSet('All', 'Public', 'Private')] @@ -543,7 +551,6 @@ function Get-GitHubRepository } 'Organization' { - $telemetryProperties['OrganizationName'] = Get-PiiSafeString -PlainText $OrganizationName $uriFragment = "orgs/$OrganizationName/repos" @@ -623,18 +630,11 @@ function Get-GitHubRepository 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - $multipleResult = Invoke-GHRestMethodMultipleResult @params - - # Add additional property to ease pipelining - foreach ($result in $multipleResult) - { - Add-Member -InputObject $result -Name 'RepositoryUrl' -Value $result.html_url -MemberType NoteProperty -Force - } - - return $multipleResult + return (Invoke-GHRestMethodMultipleResult @params | + Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) } -function Rename-GitHubRepository +filter Rename-GitHubRepository { <# .SYNOPSIS @@ -673,6 +673,9 @@ function Rename-GitHubRepository the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Repository + .EXAMPLE Get-GitHubRepository -Owner octocat -RepositoryName hello-world | Rename-GitHubRepository -NewName hello-again-world @@ -707,6 +710,7 @@ function Rename-GitHubRepository SupportsShouldProcess, DefaultParameterSetName='Uri', ConfirmImpact="High")] + [OutputType({$script:GitHubRepositoryTypeName})] [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=$true, ParameterSetName='Elements')] @@ -732,49 +736,41 @@ function Rename-GitHubRepository [switch] $NoStatus ) - process + if ($Force -and (-not $Confirm)) { - $repositoryInfoForDisplayMessage = if ($PSCmdlet.ParameterSetName -eq "Uri") { $Uri } else { $OwnerName, $RepositoryName -join "/" } + $ConfirmPreference = 'None' + } - if ($Force -and (-not $Confirm)) - { - $ConfirmPreference = 'None' + $repositoryInfoForDisplayMessage = if ($PSCmdlet.ParameterSetName -eq "Uri") { $Uri } else { $OwnerName, $RepositoryName -join "/" } + if ($PSCmdlet.ShouldProcess($repositoryInfoForDisplayMessage, "Rename repository to '$NewName'")) + { + Write-InvocationLog -Invocation $MyInvocation + $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters + $OwnerName = $elements.ownerName + $RepositoryName = $elements.repositoryName + + $telemetryProperties = @{ + 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) + 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - if ($PSCmdlet.ShouldProcess($repositoryInfoForDisplayMessage, "Rename repository to '$NewName'")) - { - Write-InvocationLog -Invocation $MyInvocation - $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters - $OwnerName = $elements.ownerName - $RepositoryName = $elements.repositoryName - - $telemetryProperties = @{ - 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) - 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) - } - - $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName" - 'Method' = 'Patch' - Body = ConvertTo-Json -InputObject @{name = $NewName} - 'Description' = "Renaming repository at '$repositoryInfoForDisplayMessage' to '$NewName'" - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) - } - - $result = Invoke-GHRestMethod @params - - # Add additional property to ease pipelining - Add-Member -InputObject $result -Name 'RepositoryUrl' -Value $result.html_url -MemberType NoteProperty -Force - - return $result + $params = @{ + 'UriFragment' = "repos/$OwnerName/$RepositoryName" + 'Method' = 'Patch' + Body = ConvertTo-Json -InputObject @{name = $NewName} + 'Description' = "Renaming repository at '$repositoryInfoForDisplayMessage' to '$NewName'" + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } + + return (Invoke-GHRestMethod @params | + Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) } } -function Update-GitHubRepository +filter Update-GitHubRepository { <# .SYNOPSIS @@ -854,6 +850,9 @@ function Update-GitHubRepository the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Repository + .EXAMPLE Update-GitHubRepository -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Description 'The best way to automate your GitHub interactions' @@ -867,6 +866,7 @@ function Update-GitHubRepository [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubRepositoryTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -954,15 +954,11 @@ function Update-GitHubRepository 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - $result = Invoke-GHRestMethod @params - - # Add additional property to ease pipelining - Add-Member -InputObject $result -Name 'RepositoryUrl' -Value $result.html_url -MemberType NoteProperty -Force - - return $result + return (Invoke-GHRestMethod @params | + Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) } -function Get-GitHubRepositoryTopic +filter Get-GitHubRepositoryTopic { <# .SYNOPSIS @@ -996,6 +992,9 @@ function Get-GitHubRepositoryTopic the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.RepositoryTopic + .EXAMPLE Get-GitHubRepositoryTopic -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -1005,6 +1004,7 @@ function Get-GitHubRepositoryTopic [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubRepositoryTopicTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -1047,15 +1047,11 @@ function Get-GitHubRepositoryTopic 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params - - # Add additional property to ease pipelining - Add-Member -InputObject $result -Name 'RepositoryUrl' -Value (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) -MemberType NoteProperty -Force - - return $result + return (Invoke-GHRestMethod @params | + Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTopicTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } -function Set-GitHubRepositoryTopic +filter Set-GitHubRepositoryTopic { <# .SYNOPSIS @@ -1095,6 +1091,9 @@ function Set-GitHubRepositoryTopic the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.RepositoryTopic + .EXAMPLE Set-GitHubRepositoryTopic -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Clear @@ -1104,6 +1103,7 @@ function Set-GitHubRepositoryTopic [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='ElementsName')] + [OutputType({$script:GitHubRepositoryTopicTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='ElementsName')] @@ -1184,15 +1184,11 @@ function Set-GitHubRepositoryTopic 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params - - # Add additional property to ease pipelining - Add-Member -InputObject $result -Name 'RepositoryUrl' -Value (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) -MemberType NoteProperty -Force - - return $result + return (Invoke-GHRestMethod @params | + Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTopicTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } -function Get-GitHubRepositoryContributor +filter Get-GitHubRepositoryContributor { <# .SYNOPSIS @@ -1240,7 +1236,7 @@ function Get-GitHubRepositoryContributor If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - [PSCustomObject[]] List of contributors for the repository. + GitHub.User .EXAMPLE Get-GitHubRepositoryContributor -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -1251,6 +1247,7 @@ function Get-GitHubRepositoryContributor [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubUserTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -1303,10 +1300,10 @@ function Get-GitHubRepositoryContributor 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | Set-GitHubUserAdditionalProperties) } -function Get-GitHubRepositoryCollaborator +filter Get-GitHubRepositoryCollaborator { <# .SYNOPSIS @@ -1341,7 +1338,7 @@ function Get-GitHubRepositoryCollaborator If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - [PSCustomObject[]] List of collaborators for the repository. + GitHub.User .EXAMPLE Get-GitHubRepositoryCollaborator -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -1352,7 +1349,8 @@ function Get-GitHubRepositoryCollaborator [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.")] + [OutputType({$script:GitHubUserTypeName})] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -1392,10 +1390,10 @@ function Get-GitHubRepositoryCollaborator 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | Set-GitHubUserAdditionalProperties) } -function Get-GitHubRepositoryLanguage +filter Get-GitHubRepositoryLanguage { <# .SYNOPSIS @@ -1430,8 +1428,8 @@ function Get-GitHubRepositoryLanguage If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - [PSCustomObject[]] List of languages for the specified repository. The value shown - for each language is the number of bytes of code written in that language. + GitHub.RepositoryLanguage - The value shown for each language is the number + of bytes of code written in that language. .EXAMPLE Get-GitHubRepositoryLanguage -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -1442,6 +1440,7 @@ function Get-GitHubRepositoryLanguage [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubRepositoryLanguageTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -1482,10 +1481,11 @@ function Get-GitHubRepositoryLanguage 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | + Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryLanguageTypeName) } -function Get-GitHubRepositoryTag +filter Get-GitHubRepositoryTag { <# .SYNOPSIS @@ -1519,6 +1519,9 @@ function Get-GitHubRepositoryTag the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.RepositoryTag + .EXAMPLE Get-GitHubRepositoryTag -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -1568,18 +1571,11 @@ function Get-GitHubRepositoryTag 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - $multipleResult = Invoke-GHRestMethodMultipleResult @params - - # Add additional property to ease pipelining - foreach ($result in $multipleResult) - { - Add-Member -InputObject $result -Name 'RepositoryUrl' -Value (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) -MemberType NoteProperty -Force - } - - return $multipleResult + return (Invoke-GHRestMethodMultipleResult @params | + Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTagTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } -function Move-GitHubRepositoryOwnership +filter Move-GitHubRepositoryOwnership { <# .SYNOPSIS @@ -1620,12 +1616,16 @@ function Move-GitHubRepositoryOwnership the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.RepositoryTopic + .EXAMPLE Move-GitHubRepositoryOwnership -OwnerName Microsoft -RepositoryName PowerShellForGitHub -NewOwnerName OctoCat #> [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubRepositoryTypeName})] [Alias('Transfer-GitHubRepositoryOwnership')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( @@ -1681,12 +1681,8 @@ function Move-GitHubRepositoryOwnership 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - $result = Invoke-GHRestMethod @params - - # Add additional property to ease pipelining - Add-Member -InputObject $result -Name 'RepositoryUrl' -Value (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) -MemberType NoteProperty -Force - - return $result + return (Invoke-GHRestMethod @params | + Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) } filter Set-GitHubRepositoryAdditionalProperties @@ -1698,21 +1694,28 @@ filter Set-GitHubRepositoryAdditionalProperties .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. This information might be obtainable from InputObject, so this - is option based on what InputObject contains. + is optional based on what InputObject contains. .PARAMETER RepositoryName Name of the repository. This information might be obtainable from InputObject, so this - is option based on what InputObject contains. + is optional based on what InputObject contains. #> [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Justification="Internal helper that doesn't change system state.")] param( [Parameter( Mandatory, ValueFromPipeline)] [PSCustomObject[]] $InputObject, + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubRepositoryTypeName, + [string] $OwnerName, [string] $RepositoryName @@ -1720,22 +1723,25 @@ filter Set-GitHubRepositoryAdditionalProperties foreach ($item in $InputObject) { - $item.PSObject.TypeNames.Insert(0, $script:GitHubRepositoryTypeName) + $item.PSObject.TypeNames.Insert(0, $TypeName) if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { $repositoryUrl = $item.html_url - if (-not [String]::IsNullOrEmpty($repositoryUrl)) + if ([String]::IsNullOrEmpty($repositoryUrl)) { $repositoryUrl = (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) } - Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force - } + if (-not [String]::IsNullOrEmpty($repositoryUrl)) + { + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + } - if ($null -ne $item.owner) - { - Set-GitHubUserAdditionalProperties -InputObject $item.owner + if ($null -ne $item.owner) + { + Set-GitHubUserAdditionalProperties -InputObject $item.owner + } } Write-Output $item diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index c80db955..b666532b 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -3,7 +3,7 @@ @{ GitHubUserTypeName = 'GitHub.User' - + GitHubUserContextualInformationTypeName = 'GitHub.UserContextualInformation' }.GetEnumerator() | ForEach-Object { Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value } @@ -45,6 +45,9 @@ which provides an email entry for this endpoint. If the user does not set a public email address for email, then it will have a value of null. + .OUTPUTS + GitHub.User + .EXAMPLE Get-GitHubUser -User octocat @@ -63,6 +66,7 @@ [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='ListAndSearch')] + [OutputType({$script:GitHubUserTypeName})] [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( @@ -132,6 +136,9 @@ function Get-GitHubUserContextualInformation the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.UserContextualInformation + .EXAMPLE Get-GitHubUserContextualInformation -User octocat @@ -139,6 +146,7 @@ function Get-GitHubUserContextualInformation Get-GitHubUserContextualInformation -User octocat -Subject Repository -SubjectId 1300192 #> [CmdletBinding(SupportsShouldProcess)] + [OutputType({$script:GitHubUserContextualInformationTypeName})] [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( @@ -190,7 +198,7 @@ function Get-GitHubUserContextualInformation 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Set-GitHubUserAdditionalProperties -TypeName $script:GitHubUserContextualInformationTypeName -Name $User) } function Update-GitHubCurrentUser @@ -236,6 +244,9 @@ function Update-GitHubCurrentUser the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.User + .EXAMPLE Update-GitHubCurrentUser -Location 'Seattle, WA' -Hireable:$false @@ -243,6 +254,7 @@ function Update-GitHubCurrentUser are not currently hireable. #> [CmdletBinding(SupportsShouldProcess)] + [OutputType({$script:GitHubUserTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [string] $Name, @@ -285,7 +297,7 @@ function Update-GitHubCurrentUser 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Set-GitHubUserAdditionalProperties) } filter Set-GitHubUserAdditionalProperties @@ -296,24 +308,63 @@ filter Set-GitHubUserAdditionalProperties .PARAMETER InputObject The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. + + .PARAMETER Name + The name of the user. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. + + .PARAMETER Id + The ID of the user. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. #> [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Justification="Internal helper that doesn't change system state.")] param( [Parameter( Mandatory, ValueFromPipeline)] - [PSCustomObject[]] $InputObject + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubUserTypeName, + + [string] $Name, + + [int64] $Id ) foreach ($item in $InputObject) { - $item.PSObject.TypeNames.Insert(0, $script:GitHubUserTypeName) + $item.PSObject.TypeNames.Insert(0, $TypeName) if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { - Add-Member -InputObject $item -Name 'OwnerName' -Value $item.login -MemberType NoteProperty -Force - Add-Member -InputObject $item -Name 'UserName' -Value $item.login -MemberType NoteProperty -Force - Add-Member -InputObject $item -Name 'UserId' -Value $item.id -MemberType NoteProperty -Force + $userName = $item.login + if ([String]::IsNullOrEmpty($userName) -and $PSBoundParameters.ContainsKey('Name')) + { + $userName = $Name + } + + if (-not [String]::IsNullOrEmpty($userName)) + { + Add-Member -InputObject $item -Name 'OwnerName' -Value $item.login -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'UserName' -Value $item.login -MemberType NoteProperty -Force + } + + $userId = $item.id + if (($userId -eq 0) -and $PSBoundParameters.ContainsKey('Id')) + { + $userId = $Id + } + + if ($userId -ne 0) + { + Add-Member -InputObject $item -Name 'UserId' -Value $item.id -MemberType NoteProperty -Force + } + } Write-Output $item From e1d3c6734abcbbcc852269758b3b5afd030486b2 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 5 Jun 2020 12:00:20 -0700 Subject: [PATCH 04/80] Repo fix (helps Get-GitHubRepositoryLanguage) --- GitHubRepositories.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index c79b8b26..5bd6e90c 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -1728,7 +1728,9 @@ filter Set-GitHubRepositoryAdditionalProperties if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { $repositoryUrl = $item.html_url - if ([String]::IsNullOrEmpty($repositoryUrl)) + if ([String]::IsNullOrEmpty($repositoryUrl) -and + $PSBoundParameters.ContainsKey('OwnerName') -and + $PSBoundParameters.ContainsKey('RepositoryName')) { $repositoryUrl = (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) } From 0747e6c94678b6f9a01089fc21a286513bfb1da1 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 5 Jun 2020 12:12:02 -0700 Subject: [PATCH 05/80] Additional User fixes --- GitHubUsers.ps1 | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index b666532b..cb7ea779 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -8,7 +8,7 @@ Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value } - function Get-GitHubUser +filter Get-GitHubUser { <# .SYNOPSIS @@ -70,7 +70,11 @@ [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(ParameterSetName='ListAndSearch')] + [Parameter( + ValueFromPipeline, + ValueFromPipelineByPropertyName, + ParameterSetName='ListAndSearch')] + [Alias('UserName')] [string] $User, [Parameter(ParameterSetName='Current')] @@ -106,7 +110,7 @@ } } -function Get-GitHubUserContextualInformation +filter Get-GitHubUserContextualInformation { <# .SYNOPSIS @@ -150,7 +154,11 @@ function Get-GitHubUserContextualInformation [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)] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName)] + [Alias('UserName')] [string] $User, [ValidateSet('Organization', 'Repository', 'Issue', 'PullRequest')] @@ -198,7 +206,8 @@ function Get-GitHubUserContextualInformation 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethod @params | Set-GitHubUserAdditionalProperties -TypeName $script:GitHubUserContextualInformationTypeName -Name $User) + return (Invoke-GHRestMethod @params | + Set-GitHubUserAdditionalProperties -TypeName $script:GitHubUserContextualInformationTypeName -Name $User) } function Update-GitHubCurrentUser From 17cb1b168d5654657b3682ae77a4534a85abae1f Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 5 Jun 2020 12:34:02 -0700 Subject: [PATCH 06/80] Additional user fixes --- GitHubUsers.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index cb7ea779..7f3aee84 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -359,8 +359,8 @@ filter Set-GitHubUserAdditionalProperties if (-not [String]::IsNullOrEmpty($userName)) { - Add-Member -InputObject $item -Name 'OwnerName' -Value $item.login -MemberType NoteProperty -Force - Add-Member -InputObject $item -Name 'UserName' -Value $item.login -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'OwnerName' -Value $userName -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'UserName' -Value $userName -MemberType NoteProperty -Force } $userId = $item.id @@ -371,7 +371,7 @@ filter Set-GitHubUserAdditionalProperties if ($userId -ne 0) { - Add-Member -InputObject $item -Name 'UserId' -Value $item.id -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'UserId' -Value $userId -MemberType NoteProperty -Force } } From eefb3e3aa3a9143dbdbcbfdc88f526f28cab09bb Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 5 Jun 2020 13:05:15 -0700 Subject: [PATCH 07/80] Add Teams support --- GitHubOrganizations.ps1 | 78 +++++++++++++++++++++++++++- GitHubRepositories.ps1 | 8 ++- GitHubTeams.ps1 | 112 ++++++++++++++++++++++++++++++++++++---- GitHubUsers.ps1 | 2 - 4 files changed, 186 insertions(+), 14 deletions(-) diff --git a/GitHubOrganizations.ps1 b/GitHubOrganizations.ps1 index db2073ba..a7bdfb84 100644 --- a/GitHubOrganizations.ps1 +++ b/GitHubOrganizations.ps1 @@ -1,7 +1,13 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubOrganizationMember +@{ + GitHubOrganizationTypeName = 'GitHub.Organization' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + + function Get-GitHubOrganizationMember { <# .SYNOPSIS @@ -142,3 +148,73 @@ function Test-GitHubOrganizationMember return $false } } + + +filter Set-GitHubOrganizationAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Organization objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. + + .PARAMETER Name + The name of the organization. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. + + .PARAMETER Id + The ID of the organization. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. +#> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Justification="Internal helper that doesn't change system state.")] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubOrganizationTypeName, + + [string] $Name, + + [int64] $Id + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + $organizationName = $item.login + if ([String]::IsNullOrEmpty($organizationName) -and $PSBoundParameters.ContainsKey('Name')) + { + $organizationName = $Name + } + + if (-not [String]::IsNullOrEmpty($organizationName)) + { + Add-Member -InputObject $item -Name 'OrganizationName' -Value $organizationName -MemberType NoteProperty -Force + } + + $organizationId = $item.id + if (($organizationId -eq 0) -and $PSBoundParameters.ContainsKey('Id')) + { + $organizationId = $Id + } + + if ($organizationId -ne 0) + { + Add-Member -InputObject $item -Name 'OrganizationId' -Value $organizationId -MemberType NoteProperty -Force + } + } + + Write-Output $item + } +} diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 5bd6e90c..2df4375b 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -428,6 +428,7 @@ filter Get-GitHubRepository [Parameter( ValueFromPipelineByPropertyName, ParameterSetName='ElementsOrUser')] + [Alias('UserName')] [string] $OwnerName, [Parameter(ParameterSetName='ElementsOrUser')] @@ -1742,7 +1743,12 @@ filter Set-GitHubRepositoryAdditionalProperties if ($null -ne $item.owner) { - Set-GitHubUserAdditionalProperties -InputObject $item.owner + $null = Set-GitHubUserAdditionalProperties -InputObject $item.owner + } + + if ($null -ne $item.organization) + { + $null = Set-GitHubOrganizationAdditionalProperties -InputObject $item.organization } } diff --git a/GitHubTeams.ps1 b/GitHubTeams.ps1 index 6c27c294..ca66d72b 100644 --- a/GitHubTeams.ps1 +++ b/GitHubTeams.ps1 @@ -1,7 +1,13 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubTeam +@{ + GitHubTeamTypeName = 'GitHub.Team' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + +filter Get-GitHubTeam { <# .SYNOPSIS @@ -42,16 +48,17 @@ function Get-GitHubTeam If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - [PSCustomObject[]] The team(s) that match the user's request. + GitHub.Team .EXAMPLE Get-GitHubTeam -OrganizationName PowerShell #> - [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.")] [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubTeamTypeName})] + [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(ParameterSetName='Elements')] @@ -62,17 +69,21 @@ function Get-GitHubTeam [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Organization')] [ValidateNotNullOrEmpty()] [string] $OrganizationName, [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Single')] [ValidateNotNullOrEmpty()] [string] $TeamId, @@ -125,10 +136,11 @@ function Get-GitHubTeam 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | + Set-GitHubTeamAdditionalProperties) } -function Get-GitHubTeamMember +filter Get-GitHubTeamMember { <# .SYNOPSIS @@ -159,29 +171,34 @@ function Get-GitHubTeamMember If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - [PSCustomObject[]] List of members on the team within the organization. + GitHub.User .EXAMPLE $members = Get-GitHubTeamMember -Organization PowerShell -TeamName Everybody #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='ID')] + [OutputType({$script:GitHubUserTypeName})] + [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)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [String] $OrganizationName, [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Name')] [ValidateNotNullOrEmpty()] [String] $TeamName, [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='ID')] [int64] $TeamId, @@ -223,5 +240,80 @@ function Get-GitHubTeamMember 'NoStatus' = $NoStatus } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | Set-GitHubUserAdditionalProperties) +} + +filter Set-GitHubTeamAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Team objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. + + .PARAMETER Name + The name of the team. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. + + .PARAMETER Id + The ID of the team. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. +#> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Justification="Internal helper that doesn't change system state.")] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubTeamTypeName, + + [string] $Name, + + [int64] $Id + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + $teamName = $item.name + if ([String]::IsNullOrEmpty($teamName) -and $PSBoundParameters.ContainsKey('Name')) + { + $teamName = $Name + } + + if (-not [String]::IsNullOrEmpty($teamName)) + { + Add-Member -InputObject $item -Name 'TeamName' -Value $teamName -MemberType NoteProperty -Force + } + + $teamId = $item.id + if (($teamId -eq 0) -and $PSBoundParameters.ContainsKey('Id')) + { + $teamId = $Id + } + + if ($teamId -ne 0) + { + Add-Member -InputObject $item -Name 'TeamId' -Value $teamId -MemberType NoteProperty -Force + } + + # Apply these properties to any embedded parent teams as well. + if ($null -ne $item.parent) + { + $null = Set-GitHubTeamAdditionalProperties -InputObject $item.parent + } + } + + Write-Output $item + } } diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 7f3aee84..681b9351 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -359,7 +359,6 @@ filter Set-GitHubUserAdditionalProperties if (-not [String]::IsNullOrEmpty($userName)) { - Add-Member -InputObject $item -Name 'OwnerName' -Value $userName -MemberType NoteProperty -Force Add-Member -InputObject $item -Name 'UserName' -Value $userName -MemberType NoteProperty -Force } @@ -373,7 +372,6 @@ filter Set-GitHubUserAdditionalProperties { Add-Member -InputObject $item -Name 'UserId' -Value $userId -MemberType NoteProperty -Force } - } Write-Output $item From 7360b07e29cc164b2d3622cd56eff4571cfbf546 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 5 Jun 2020 15:06:52 -0700 Subject: [PATCH 08/80] Add traffic support --- GitHubRepositoryTraffic.ps1 | 57 +++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/GitHubRepositoryTraffic.ps1 b/GitHubRepositoryTraffic.ps1 index c27ab1be..7f7b264a 100644 --- a/GitHubRepositoryTraffic.ps1 +++ b/GitHubRepositoryTraffic.ps1 @@ -1,7 +1,16 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubReferrerTraffic +@{ + GitHubReferrerTrafficTypeName = 'GitHub.ReferrerTraffic' + GitHubPathTrafficTypeName = 'GitHub.PathTraffic' + GitHubViewTrafficTypeName = 'GitHub.ViewTraffic' + GitHubCloneTrafficTypeName = 'GitHub.CloneTraffic' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + +filter Get-GitHubReferrerTraffic { <# .SYNOPSIS @@ -35,6 +44,9 @@ function Get-GitHubReferrerTraffic the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.ReferrerTraffic + .EXAMPLE Get-GitHubReferrerTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -43,6 +55,7 @@ function Get-GitHubReferrerTraffic [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubReferrerTrafficTypeName})] [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( @@ -54,7 +67,9 @@ function Get-GitHubReferrerTraffic [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [string] $AccessToken, @@ -83,10 +98,12 @@ function Get-GitHubReferrerTraffic 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + $result = Invoke-GHRestMethod @params + $result.PSObject.TypeNames.Insert(0, $script:GitHubReferrerTrafficTypeName) + return $result } -function Get-GitHubPathTraffic +filter Get-GitHubPathTraffic { <# .SYNOPSIS @@ -120,6 +137,9 @@ function Get-GitHubPathTraffic the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.PathTraffic + .EXAMPLE Get-GitHubPathTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -128,6 +148,7 @@ function Get-GitHubPathTraffic [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubPathTrafficTypeName})] [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( @@ -139,7 +160,9 @@ function Get-GitHubPathTraffic [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [string] $AccessToken, @@ -168,10 +191,12 @@ function Get-GitHubPathTraffic 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + $result = Invoke-GHRestMethod @params + $result.PSObject.TypeNames.Insert(0, $script:GitHubPathTrafficTypeName) + return $result } -function Get-GitHubViewTraffic +filter Get-GitHubViewTraffic { <# .SYNOPSIS @@ -209,6 +234,9 @@ function Get-GitHubViewTraffic the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.ViewTraffic + .EXAMPLE Get-GitHubViewTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -217,6 +245,7 @@ function Get-GitHubViewTraffic [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubViewTrafficTypeName})] [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( @@ -228,7 +257,9 @@ function Get-GitHubViewTraffic [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [ValidateSet('Day', 'Week')] @@ -261,10 +292,12 @@ function Get-GitHubViewTraffic 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + $result = Invoke-GHRestMethod @params + $result.PSObject.TypeNames.Insert(0, $script:GitHubViewTrafficTypeName) + return $result } -function Get-GitHubCloneTraffic +filter Get-GitHubCloneTraffic { <# .SYNOPSIS @@ -302,6 +335,9 @@ function Get-GitHubCloneTraffic the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.CloneTraffic + .EXAMPLE Get-GitHubCloneTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -310,6 +346,7 @@ function Get-GitHubCloneTraffic [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubCloneTrafficTypeName})] [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( @@ -321,7 +358,9 @@ function Get-GitHubCloneTraffic [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [ValidateSet('Day', 'Week')] @@ -354,5 +393,7 @@ function Get-GitHubCloneTraffic 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + $result = Invoke-GHRestMethod @params + $result.PSObject.TypeNames.Insert(0, $script:GitHubCloneTrafficTypeName) + return $result } From f41864d9a6bd2832b5650f1ceb28a21007534085 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 5 Jun 2020 15:11:03 -0700 Subject: [PATCH 09/80] Add fork support --- GitHubRepositoryForks.ps1 | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/GitHubRepositoryForks.ps1 b/GitHubRepositoryForks.ps1 index f50b2af9..e89f9665 100644 --- a/GitHubRepositoryForks.ps1 +++ b/GitHubRepositoryForks.ps1 @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubRepositoryFork +filter Get-GitHubRepositoryFork { <# .SYNOPSIS @@ -38,6 +38,9 @@ function Get-GitHubRepositoryFork the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Repository + .EXAMPLE Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -46,6 +49,7 @@ function Get-GitHubRepositoryFork [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubRepositoryTypeName})] [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( @@ -57,7 +61,9 @@ function Get-GitHubRepositoryFork [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [ValidateSet('Newest', 'Oldest', 'Stargazers')] @@ -93,10 +99,11 @@ function Get-GitHubRepositoryFork 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | + Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) } -function New-GitHubRepositoryFork +filter New-GitHubRepositoryFork { <# .SYNOPSIS @@ -134,6 +141,9 @@ function New-GitHubRepositoryFork the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Repository + .EXAMPLE New-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -147,6 +157,7 @@ function New-GitHubRepositoryFork [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubRepositoryTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -157,7 +168,9 @@ function New-GitHubRepositoryFork [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [string] $OrganizationName, @@ -196,7 +209,8 @@ function New-GitHubRepositoryFork 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - $result = Invoke-GHRestMethod @params + $result = (Invoke-GHRestMethod @params | + Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) Write-Log -Message 'Forking a repository happens asynchronously. You may have to wait a short period of time (up to 5 minutes) before you can access the git objects.' -Level Warning return $result From bce71e10efc6c1437a16afbdbe9754ec9a20378f Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 5 Jun 2020 15:20:23 -0700 Subject: [PATCH 10/80] Add releases support --- GitHubReleases.ps1 | 73 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index e7eb49a2..aacc59ff 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -1,7 +1,13 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubRelease +@{ + GitHubReleaseTypeName = 'GitHub.Release' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + +filter Get-GitHubRelease { <# .SYNOPSIS @@ -47,6 +53,9 @@ function Get-GitHubRelease the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Release + .EXAMPLE Get-GitHubRelease @@ -84,6 +93,7 @@ function Get-GitHubRelease [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubReleaseTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( @@ -108,23 +118,30 @@ function Get-GitHubRelease [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName="Uri-ReleaseId")] [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName="Uri-Latest")] [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName="Uri-Tag")] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName="Elements-ReleaseId")] [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName="Uri-ReleaseId")] [string] $ReleaseId, @@ -196,5 +213,57 @@ function Get-GitHubRelease 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | + Set-GitHubReleaseAdditionalProperties -TypeName $script:GitHubReleaseTypeName) +} + + +filter Set-GitHubRepositoryAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Release objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. +#> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Justification="Internal helper that doesn't change system state.")] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubReleaseTypeName + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + if (-not [String]::IsNullOrEmpty($item.html_url)) + { + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $item.html_url -MemberType NoteProperty -Force + } + + if (-not [String]::IsNullOrEmpty($item.id)) + { + Add-Member -InputObject $item -Name 'ReleaseId' -Value $item.id -MemberType NoteProperty -Force + } + + if ($null -ne $item.author) + { + $null = Set-GitHubUserAdditionalProperties -InputObject $item.author + } + } + + Write-Output $item + } } From c42d67c586cff782f33fd8fff9e956dec5d8b990 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 5 Jun 2020 17:29:09 -0700 Subject: [PATCH 11/80] Pull request, labels and milestone --- GitHubLabels.ps1 | 162 ++++++++++++++++++++++++++++++++------ GitHubMilestones.ps1 | 132 +++++++++++++++++++++++++++---- GitHubOrganizations.ps1 | 2 +- GitHubPullRequests.ps1 | 113 ++++++++++++++++++++++++-- GitHubReleases.ps1 | 6 +- GitHubRepositories.ps1 | 28 +++---- GitHubRepositoryForks.ps1 | 4 +- GitHubTeams.ps1 | 8 +- GitHubUsers.ps1 | 12 +-- PowerShellForGitHub.psd1 | 5 -- 10 files changed, 387 insertions(+), 85 deletions(-) diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index a134e08e..dfbcf618 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -1,7 +1,13 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubLabel +@{ + GitHubLabelTypeName = 'GitHub.Label' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + +filter Get-GitHubLabel { <# .SYNOPSIS @@ -45,6 +51,9 @@ function Get-GitHubLabel the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Label + .EXAMPLE Get-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -59,6 +68,7 @@ function Get-GitHubLabel [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubLabelTypeName})] [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')] @@ -73,10 +83,11 @@ function Get-GitHubLabel [Parameter(Mandatory, ParameterSetName='MilestoneElements')] [string] $RepositoryName, - [Parameter(Mandatory, ParameterSetName='Uri')] - [Parameter(Mandatory, ParameterSetName='NameUri')] - [Parameter(Mandatory, ParameterSetName='IssueUri')] - [Parameter(Mandatory, ParameterSetName='MilestoneUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='NameUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='MilestoneUri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter(Mandatory, ParameterSetName='NameUri')] @@ -84,12 +95,14 @@ function Get-GitHubLabel [Alias('LabelName')] [string] $Name, - [Parameter(Mandatory, ParameterSetName='IssueUri')] - [Parameter(Mandatory, ParameterSetName='IssueElements')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueElements')] + [Alias('IssueId')] [int64] $Issue, - [Parameter(Mandatory, ParameterSetName='MilestoneUri')] - [Parameter(Mandatory, ParameterSetName='MilestoneElements')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='MilestoneUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='MilestoneElements')] + [Alias('MilestoneId')] [int64] $Milestone, [string] $AccessToken, @@ -150,10 +163,11 @@ function Get-GitHubLabel $params["Description"] = "Getting label $Name for $RepositoryName" } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | + Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } -function New-GitHubLabel +filter New-GitHubLabel { <# .SYNOPSIS @@ -197,6 +211,9 @@ function New-GitHubLabel the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Label + .EXAMPLE New-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -Color BBBBBB @@ -205,6 +222,7 @@ function New-GitHubLabel [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubLabelTypeName})] [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( @@ -216,7 +234,9 @@ function New-GitHubLabel [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter(Mandatory)] @@ -224,8 +244,8 @@ function New-GitHubLabel [string] $Name, [Parameter(Mandatory)] - [Alias('LabelColor')] [ValidateScript({if ($_ -match '^#?[ABCDEF0-9]{6}$') { $true } else { throw "Color must be provided in hex." }})] + [Alias('LabelColor')] [string] $Color = "EEEEEE", [string] $Description, @@ -271,10 +291,11 @@ function New-GitHubLabel 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | + Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } -function Remove-GitHubLabel +filter Remove-GitHubLabel { <# .SYNOPSIS @@ -345,7 +366,9 @@ function Remove-GitHubLabel [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter(Mandatory)] @@ -393,7 +416,7 @@ function Remove-GitHubLabel } } -function Update-GitHubLabel +filter Update-GitHubLabel { <# .SYNOPSIS @@ -441,6 +464,9 @@ function Update-GitHubLabel the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Label + .EXAMPLE Update-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -NewName NewTestLabel -LabelColor BBBB00 @@ -450,6 +476,7 @@ function Update-GitHubLabel [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubLabelTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -460,7 +487,9 @@ function Update-GitHubLabel [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter(Mandatory)] @@ -511,10 +540,11 @@ function Update-GitHubLabel 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | + Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } -function Set-GitHubLabel +filter Set-GitHubLabel { <# .SYNOPSIS @@ -560,7 +590,7 @@ function Set-GitHubLabel .NOTES This method does not rename any existing labels, as it doesn't have any context regarding - which Issue the new name is for. Therefore, it is possible that by running this function + which Label the new name is for. Therefore, it is possible that by running this function on a repository with Issues that have already been assigned Labels, you may experience data loss as a minor correction to you (maybe fixing a typo) will result in the old Label being removed (and thus unassigned from existing Issues) and then the new one created. @@ -586,7 +616,9 @@ function Set-GitHubLabel [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [object[]] $Label, @@ -642,7 +674,7 @@ function Set-GitHubLabel } } -function Add-GitHubIssueLabel +filter Add-GitHubIssueLabel { <# .DESCRIPTION @@ -679,6 +711,9 @@ function Add-GitHubIssueLabel the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Label + .EXAMPLE Add-GitHubIssueLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Name $labels @@ -687,6 +722,7 @@ function Add-GitHubIssueLabel [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubLabelTypeName})] [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( @@ -698,7 +734,9 @@ function Add-GitHubIssueLabel [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter(Mandatory)] @@ -741,10 +779,11 @@ function Add-GitHubIssueLabel 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | + Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } -function Set-GitHubIssueLabel +filter Set-GitHubIssueLabel { <# .DESCRIPTION @@ -781,6 +820,9 @@ function Set-GitHubIssueLabel the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Label + .EXAMPLE Set-GitHubIssueLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 1 -LabelName $labels @@ -789,6 +831,7 @@ function Set-GitHubIssueLabel [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubLabelTypeName})] [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( @@ -800,7 +843,9 @@ function Set-GitHubIssueLabel [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter(Mandatory)] @@ -843,10 +888,11 @@ function Set-GitHubIssueLabel 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | + Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } -function Remove-GitHubIssueLabel +filter Remove-GitHubIssueLabel { <# .DESCRIPTION @@ -908,13 +954,21 @@ function Remove-GitHubIssueLabel ConfirmImpact="High")] [Alias('Delete-GitHubLabel')] 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')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter(Mandatory)] @@ -975,6 +1029,62 @@ function Remove-GitHubIssueLabel } } +filter Add-GitHubLabelAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Label 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. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. + + .PARAMETER RepositoryName + Name of the repository. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. +#> + [CmdletBinding()] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubLabelTypeName, + + [string] $OwnerName, + + [string] $RepositoryName + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + if ($PSBoundParameters.ContainsKey('OwnerName') -and + $PSBoundParameters.ContainsKey('RepositoryName')) + { + $repositoryUrl = (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + } + + Add-Member -InputObject $item -Name 'LabelId' -Value $item.id -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'LabelName' -Value $item.name -MemberType NoteProperty -Force + } + + Write-Output $item + } +} + # A set of labels that a project might want to initially populate their repository with # Used by Set-GitHubLabel when no Label list is provided by the user. # This list exists to support v0.1.0 users. diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index 96f5946e..cc7f70a5 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -1,11 +1,17 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -# For more information refer to" +@{ + GitHubMilestoneTypeName = 'GitHub.Milestone' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + +# For more information refer to: # https://github.community/t5/How-to-use-Git-and-GitHub/Milestone-quot-Due-On-quot-field-defaults-to-7-00-when-set-by-v3/m-p/6901 $script:minimumHoursToEnsureDesiredDateInPacificTime = 9 -function Get-GitHubMilestone +filter Get-GitHubMilestone { <# .DESCRIPTION @@ -48,6 +54,9 @@ function Get-GitHubMilestone the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Milestone + .EXAMPLE Get-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub Get the milestones for the Microsoft\PowerShellForGitHub project. @@ -69,12 +78,14 @@ function Get-GitHubMilestone [Parameter(Mandatory, ParameterSetName='RepositoryElements')] [string] $RepositoryName, - [Parameter(Mandatory, ParameterSetName='MilestoneUri')] - [Parameter(Mandatory, ParameterSetName='RepositoryUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='MilestoneUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='RepositoryUri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName='MilestoneUri')] - [Parameter(Mandatory, ParameterSetName='MilestoneElements')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='MilestoneUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='MilestoneElements')] + [Alias('MilestoneNumber')] [int64] $Milestone, [Parameter(ParameterSetName='RepositoryUri')] @@ -162,7 +173,7 @@ function Get-GitHubMilestone return Invoke-GHRestMethodMultipleResult @params } -function New-GitHubMilestone +filter New-GitHubMilestone { <# .DESCRIPTION @@ -207,6 +218,9 @@ function New-GitHubMilestone the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Milestone + .EXAMPLE New-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Title "Testing this API" @@ -235,7 +249,11 @@ function New-GitHubMilestone [Parameter(Mandatory, ParameterSetName='Elements')] [string] $RepositoryName, - [Parameter(Mandatory, ParameterSetName='Uri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter(Mandatory, ParameterSetName='Uri')] @@ -308,7 +326,7 @@ function New-GitHubMilestone return Invoke-GHRestMethod @params } -function Set-GitHubMilestone +filter Set-GitHubMilestone { <# .DESCRIPTION @@ -356,6 +374,9 @@ function Set-GitHubMilestone the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Milestone + .EXAMPLE Set-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Title "Testing this API" @@ -384,11 +405,22 @@ function Set-GitHubMilestone [Parameter(Mandatory, ParameterSetName='Elements')] [string] $RepositoryName, - [Parameter(Mandatory, ParameterSetName='Uri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName='Uri')] - [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Uri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Elements')] + [Alias('MilestoneNumber')] [int64] $Milestone, [Parameter(Mandatory, ParameterSetName='Uri')] @@ -462,7 +494,7 @@ function Set-GitHubMilestone return Invoke-GHRestMethod @params } -function Remove-GitHubMilestone +filter Remove-GitHubMilestone { <# .DESCRIPTION @@ -527,12 +559,17 @@ function Remove-GitHubMilestone [Parameter(Mandatory, ParameterSetName='Elements')] [string] $RepositoryName, - [Parameter(Mandatory, ParameterSetName='Uri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName='Uri')] - [Parameter(Mandatory, ParameterSetName='Elements')] - [string] $Milestone, + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='Elements')] + [Alias('MilestoneNumber')] + [int64] $Milestone, [switch] $Force, @@ -573,3 +610,64 @@ function Remove-GitHubMilestone return Invoke-GHRestMethod @params } } + +filter Add-GitHubMilestoneAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Milestone 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. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. + + .PARAMETER RepositoryName + Name of the repository. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. +#> + [CmdletBinding()] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubMilestoneTypeName, + + [string] $OwnerName, + + [string] $RepositoryName + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + if ($PSBoundParameters.ContainsKey('OwnerName') -and + $PSBoundParameters.ContainsKey('RepositoryName')) + { + $repositoryUrl = (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + } + + Add-Member -InputObject $item -Name 'MilestoneId' -Value $item.id -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'MilestoneNumber' -Value $item.number -MemberType NoteProperty -Force + + if ($null -ne $item.creator) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.creator + } + } + + Write-Output $item + } +} diff --git a/GitHubOrganizations.ps1 b/GitHubOrganizations.ps1 index a7bdfb84..33afac9e 100644 --- a/GitHubOrganizations.ps1 +++ b/GitHubOrganizations.ps1 @@ -150,7 +150,7 @@ function Test-GitHubOrganizationMember } -filter Set-GitHubOrganizationAdditionalProperties +filter Add-GitHubOrganizationAdditionalProperties { <# .SYNOPSIS diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index d2d99337..aad6879b 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -1,7 +1,13 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubPullRequest +@{ + GitHubPullRequestTypeName = 'GitHub.PullRequest' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + +filter Get-GitHubPullRequest { <# .SYNOPSIS @@ -59,7 +65,7 @@ function Get-GitHubPullRequest If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - [PSCustomObject[]] List of Pull Requests that match the specified criteria. + GitHub.Repository .EXAMPLE $pullRequests = Get-GitHubPullRequest -Uri 'https://github.com/PowerShell/PowerShellForGitHub' @@ -80,10 +86,14 @@ function Get-GitHubPullRequest [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [string] $PullRequest, + [Parameter(ValueFromPipelineByPropertyName)] + [Alias('PullRequestId')] + [int64] $PullRequest, [ValidateSet('Open', 'Closed', 'All')] [string] $State = 'Open', @@ -161,10 +171,11 @@ function Get-GitHubPullRequest 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | + Add-GitHubPullRequestAdditionalProperties -TypeName $script:GitHubPullRequestTypeName) } -function New-GitHubPullRequest +filter New-GitHubPullRequest { <# .SYNOPSIS @@ -232,7 +243,7 @@ function New-GitHubPullRequest If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - [PSCustomObject] An object describing the created pull request. + GitHub.Repository .EXAMPLE $prParams = @{ @@ -266,10 +277,13 @@ function New-GitHubPullRequest [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri_Title')] [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri_Issue')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter( @@ -287,10 +301,13 @@ function New-GitHubPullRequest [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Elements_Issue')] [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri_Issue')] + [Alias('IssueId')] [int] $Issue, [Parameter(Mandatory)] @@ -387,5 +404,87 @@ function New-GitHubPullRequest $restParams['AcceptHeader'] = $acceptHeader } - return Invoke-GHRestMethod @restParams + return (Invoke-GHRestMethod @restParams | + Add-GitHubPullRequestAdditionalProperties -TypeName $script:GitHubPullRequestTypeName) +} + +filter Add-GitHubPullRequestAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Repository objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. +#> + [CmdletBinding()] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubPullRequestTypeName + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + if (-not [String]::IsNullOrEmpty($item.html_url)) + { + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $item.html_url -MemberType NoteProperty -Force + } + + if (-not [String]::IsNullOrEmpty($item.id)) + { + Add-Member -InputObject $item -Name 'PullRequestId' -Value $item.id -MemberType NoteProperty -Force + } + + if ($null -ne $item.user) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.user + } + + if ($null -ne $item.label) + { + $null = Add-GitHubLabelAdditionalProperties -InputObject $item.label + } + + if ($null -ne $item.milestone) + { + $null = Add-GitHubMilestoneAdditionalProperties -InputObject $item.milestone + } + + if ($null -ne $item.assignee) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.assignee + } + + if ($null -ne $item.assignees) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.assignees + } + + if ($null -ne $item.requested_reviewers) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.requested_reviewers + } + + if ($null -ne $item.requested_teams) + { + $null = Add-GitHubTeamAdditionalProperties -InputObject $item.requested_teams + } + + # TODO: What type are item.head and item.base? + } + + Write-Output $item + } } diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index aacc59ff..6a361e87 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -214,11 +214,11 @@ filter Get-GitHubRelease } return (Invoke-GHRestMethodMultipleResult @params | - Set-GitHubReleaseAdditionalProperties -TypeName $script:GitHubReleaseTypeName) + Add-GitHubReleaseAdditionalProperties -TypeName $script:GitHubReleaseTypeName) } -filter Set-GitHubRepositoryAdditionalProperties +filter Add-GitHubRepositoryAdditionalProperties { <# .SYNOPSIS @@ -260,7 +260,7 @@ filter Set-GitHubRepositoryAdditionalProperties if ($null -ne $item.author) { - $null = Set-GitHubUserAdditionalProperties -InputObject $item.author + $null = Add-GitHubUserAdditionalProperties -InputObject $item.author } } diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 2df4375b..680346ca 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -206,7 +206,7 @@ filter New-GitHubRepository } return (Invoke-GHRestMethod @params | - Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) + Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) } filter Remove-GitHubRepository @@ -632,7 +632,7 @@ filter Get-GitHubRepository } return (Invoke-GHRestMethodMultipleResult @params | - Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) + Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) } filter Rename-GitHubRepository @@ -767,7 +767,7 @@ filter Rename-GitHubRepository } return (Invoke-GHRestMethod @params | - Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) + Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) } } @@ -956,7 +956,7 @@ filter Update-GitHubRepository } return (Invoke-GHRestMethod @params | - Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) + Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) } filter Get-GitHubRepositoryTopic @@ -1049,7 +1049,7 @@ filter Get-GitHubRepositoryTopic } return (Invoke-GHRestMethod @params | - Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTopicTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) + Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTopicTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } filter Set-GitHubRepositoryTopic @@ -1186,7 +1186,7 @@ filter Set-GitHubRepositoryTopic } return (Invoke-GHRestMethod @params | - Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTopicTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) + Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTopicTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } filter Get-GitHubRepositoryContributor @@ -1301,7 +1301,7 @@ filter Get-GitHubRepositoryContributor 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethodMultipleResult @params | Set-GitHubUserAdditionalProperties) + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubUserAdditionalProperties) } filter Get-GitHubRepositoryCollaborator @@ -1391,7 +1391,7 @@ filter Get-GitHubRepositoryCollaborator 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethodMultipleResult @params | Set-GitHubUserAdditionalProperties) + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubUserAdditionalProperties) } filter Get-GitHubRepositoryLanguage @@ -1483,7 +1483,7 @@ filter Get-GitHubRepositoryLanguage } return (Invoke-GHRestMethodMultipleResult @params | - Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryLanguageTypeName) + Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryLanguageTypeName) } filter Get-GitHubRepositoryTag @@ -1573,7 +1573,7 @@ filter Get-GitHubRepositoryTag } return (Invoke-GHRestMethodMultipleResult @params | - Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTagTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) + Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTagTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } filter Move-GitHubRepositoryOwnership @@ -1683,10 +1683,10 @@ filter Move-GitHubRepositoryOwnership } return (Invoke-GHRestMethod @params | - Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) + Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) } -filter Set-GitHubRepositoryAdditionalProperties +filter Add-GitHubRepositoryAdditionalProperties { <# .SYNOPSIS @@ -1743,12 +1743,12 @@ filter Set-GitHubRepositoryAdditionalProperties if ($null -ne $item.owner) { - $null = Set-GitHubUserAdditionalProperties -InputObject $item.owner + $null = Add-GitHubUserAdditionalProperties -InputObject $item.owner } if ($null -ne $item.organization) { - $null = Set-GitHubOrganizationAdditionalProperties -InputObject $item.organization + $null = Add-GitHubOrganizationAdditionalProperties -InputObject $item.organization } } diff --git a/GitHubRepositoryForks.ps1 b/GitHubRepositoryForks.ps1 index e89f9665..52450631 100644 --- a/GitHubRepositoryForks.ps1 +++ b/GitHubRepositoryForks.ps1 @@ -100,7 +100,7 @@ filter Get-GitHubRepositoryFork } return (Invoke-GHRestMethodMultipleResult @params | - Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) + Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) } filter New-GitHubRepositoryFork @@ -210,7 +210,7 @@ filter New-GitHubRepositoryFork } $result = (Invoke-GHRestMethod @params | - Set-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) + Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) Write-Log -Message 'Forking a repository happens asynchronously. You may have to wait a short period of time (up to 5 minutes) before you can access the git objects.' -Level Warning return $result diff --git a/GitHubTeams.ps1 b/GitHubTeams.ps1 index ca66d72b..cd0aa2fc 100644 --- a/GitHubTeams.ps1 +++ b/GitHubTeams.ps1 @@ -137,7 +137,7 @@ filter Get-GitHubTeam } return (Invoke-GHRestMethodMultipleResult @params | - Set-GitHubTeamAdditionalProperties) + Add-GitHubTeamAdditionalProperties) } filter Get-GitHubTeamMember @@ -240,10 +240,10 @@ filter Get-GitHubTeamMember 'NoStatus' = $NoStatus } - return (Invoke-GHRestMethodMultipleResult @params | Set-GitHubUserAdditionalProperties) + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubUserAdditionalProperties) } -filter Set-GitHubTeamAdditionalProperties +filter Add-GitHubTeamAdditionalProperties { <# .SYNOPSIS @@ -310,7 +310,7 @@ filter Set-GitHubTeamAdditionalProperties # Apply these properties to any embedded parent teams as well. if ($null -ne $item.parent) { - $null = Set-GitHubTeamAdditionalProperties -InputObject $item.parent + $null = Add-GitHubTeamAdditionalProperties -InputObject $item.parent } } diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 681b9351..b77abebc 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -96,17 +96,17 @@ filter Get-GitHubUser if ($Current) { return (Invoke-GHRestMethod -UriFragment "user" -Description "Getting current authenticated user" -Method 'Get' @params | - Set-GitHubUserAdditionalProperties) + Add-GitHubUserAdditionalProperties) } elseif ([String]::IsNullOrEmpty($User)) { return (Invoke-GHRestMethodMultipleResult -UriFragment 'users' -Description 'Getting all users' @params | - Set-GitHubUserAdditionalProperties) + Add-GitHubUserAdditionalProperties) } else { return (Invoke-GHRestMethod -UriFragment "users/$User" -Description "Getting user $User" -Method 'Get' @params | - Set-GitHubUserAdditionalProperties) + Add-GitHubUserAdditionalProperties) } } @@ -207,7 +207,7 @@ filter Get-GitHubUserContextualInformation } return (Invoke-GHRestMethod @params | - Set-GitHubUserAdditionalProperties -TypeName $script:GitHubUserContextualInformationTypeName -Name $User) + Add-GitHubUserAdditionalProperties -TypeName $script:GitHubUserContextualInformationTypeName -Name $User) } function Update-GitHubCurrentUser @@ -306,10 +306,10 @@ function Update-GitHubCurrentUser 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethod @params | Set-GitHubUserAdditionalProperties) + return (Invoke-GHRestMethod @params | Add-GitHubUserAdditionalProperties) } -filter Set-GitHubUserAdditionalProperties +filter Add-GitHubUserAdditionalProperties { <# .SYNOPSIS diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index 9bfd4871..5ef27773 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -50,11 +50,6 @@ # Functions to export from this module FunctionsToExport = @( - 'Set-GitHubUserAdditionalProperties', - - - - 'Add-GitHubIssueLabel', 'Backup-GitHubConfiguration', 'Clear-GitHubAuthentication', From e8c29f25dd60cea99c796cb25a53baff35552d3f Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 6 Jun 2020 14:51:18 -0700 Subject: [PATCH 12/80] Add Misc support --- GitHubMiscellaneous.ps1 | 143 +++++++++++++++++++++++++++++++--------- 1 file changed, 112 insertions(+), 31 deletions(-) diff --git a/GitHubMiscellaneous.ps1 b/GitHubMiscellaneous.ps1 index 28e9d08d..611692d1 100644 --- a/GitHubMiscellaneous.ps1 +++ b/GitHubMiscellaneous.ps1 @@ -1,6 +1,16 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +@{ + GitHubRateLimitTypeName = 'GitHub.RateLimit' + GitHubLicenseTypeName = 'GitHub.License' + GitHubEmojiTypeName = 'GitHub.Emoji' + GitHubCodeOfConductTypeName = 'GitHub.CodeOfConduct' + GitHubGitignoreTypeName = 'GitHub.Gitignore' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + function Get-GitHubRateLimit { <# @@ -27,7 +37,7 @@ function Get-GitHubRateLimit If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - [PSCustomObject] + GitHub.RateLimit Limits returned are _per hour_. The Search API has a custom rate limit, separate from the rate limit @@ -52,6 +62,7 @@ function Get-GitHubRateLimit Get-GitHubRateLimit #> [CmdletBinding(SupportsShouldProcess)] + [OutputType({$script:GitHubRateLimitTypeName})] [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( @@ -71,7 +82,9 @@ function Get-GitHubRateLimit 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + $result = Invoke-GHRestMethod @params + $result.PSObject.TypeNames.Insert(0, $script:GitHubRateLimitTypeName) + return $result } function ConvertFrom-GitHubMarkdown @@ -119,6 +132,7 @@ function ConvertFrom-GitHubMarkdown Returns back '

Bolded Text

' #> [CmdletBinding(SupportsShouldProcess)] + [OutputType([String])] [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( @@ -177,7 +191,7 @@ function ConvertFrom-GitHubMarkdown } } -function Get-GitHubLicense +filter Get-GitHubLicense { <# .SYNOPSIS @@ -201,8 +215,8 @@ function Get-GitHubLicense The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER Name - The name of the license to retrieve the content for. If not specified, all licenses + .PARAMETER Key + The key of the license to retrieve the content for. If not specified, all licenses will be returned. .PARAMETER AccessToken @@ -215,13 +229,16 @@ function Get-GitHubLicense the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.License + .EXAMPLE Get-GitHubLicense Returns metadata about popular open source licenses .EXAMPLE - Get-GitHubLicense -Name mit + Get-GitHubLicense -Key mit Gets the content of the mit license file @@ -236,6 +253,7 @@ function Get-GitHubLicense [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($result.content)) #> [CmdletBinding(SupportsShouldProcess)] + [OutputType({$script:GitHubLicenseTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -246,13 +264,17 @@ function Get-GitHubLicense [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Individual')] - [string] $Name, + [Alias('LicenseKey')] + [string] $Key, [string] $AccessToken, @@ -269,11 +291,11 @@ function Get-GitHubLicense $uriFragment = 'licenses' $description = 'Getting all licenses' - if ($PSBoundParameters.ContainsKey('Name')) + if ($PSBoundParameters.ContainsKey('Key')) { - $telemetryProperties['Name'] = $Name - $uriFragment = "licenses/$Name" - $description = "Getting the $Name license" + $telemetryProperties['Key'] = $Name + $uriFragment = "licenses/$Key" + $description = "Getting the $Key license" } elseif ((-not [String]::IsNullOrEmpty($OwnerName)) -and (-not [String]::IsNullOrEmpty($RepositoryName))) { @@ -293,7 +315,17 @@ function Get-GitHubLicense 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + $result = Invoke-GHRestMethod @params + foreach ($item in $result) + { + $item.PSObject.TypeNames.Insert(0, $script:GitHubLicenseTypeName) + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + Add-Member -InputObject $item -Name 'LicenseKey' -Value $item.key -MemberType NoteProperty -Force + } + } + + return $result } function Get-GitHubEmoji @@ -318,13 +350,13 @@ function Get-GitHubEmoji If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - [PSCustomObject] - The emoji name and a link to its image. + Github.Emoji .EXAMPLE Get-GitHubEmoji #> [CmdletBinding(SupportsShouldProcess)] + [OutputType({$script:GitHubEmojiTypeName})] [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( @@ -344,17 +376,19 @@ function Get-GitHubEmoji 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + $result = Invoke-GHRestMethod @params + $result.PSObject.TypeNames.Insert(0, $script:GitHubEmojiTypeName) + return $result } -function Get-GitHubCodeOfConduct +filter Get-GitHubCodeOfConduct { <# .SYNOPSIS - Gets license or license content from GitHub. + Gets Codes of Conduct or a specific Code of Conduct from GitHub. .DESCRIPTION - Gets license or license content from GitHub. + Gets Codes of Conduct or a specific Code of Conduct from GitHub. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -371,9 +405,9 @@ function Get-GitHubCodeOfConduct The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER Name - The name of the license to retrieve the content for. If not specified, all licenses - will be returned. + .PARAMETER Key + The unique key of the Code of Conduct to retrieve the content for. If not specified, all + Codes of Conduct will be returned. .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the @@ -385,13 +419,16 @@ function Get-GitHubCodeOfConduct the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.CodeOfConduct + .EXAMPLE Get-GitHubCodeOfConduct Returns metadata about popular Codes of Conduct .EXAMPLE - Get-GitHubCodeOfConduct -Name citizen_code_of_conduct + Get-GitHubCodeOfConduct -Key citizen_code_of_conduct Gets the content of the 'Citizen Code of Conduct' @@ -408,6 +445,7 @@ function Get-GitHubCodeOfConduct [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($result.content)) #> [CmdletBinding(SupportsShouldProcess)] + [OutputType({$script:GitHubCodeOfConductTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -418,13 +456,17 @@ function Get-GitHubCodeOfConduct [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Individual')] - [string] $Name, + [Alias('CodeOfConductKey')] + [string] $Key, [string] $AccessToken, @@ -441,11 +483,11 @@ function Get-GitHubCodeOfConduct $uriFragment = 'codes_of_conduct' $description = 'Getting all Codes of Conduct' - if ($PSBoundParameters.ContainsKey('Name')) + if ($PSBoundParameters.ContainsKey('Key')) { - $telemetryProperties['Name'] = $Name - $uriFragment = "codes_of_conduct/$Name" - $description = "Getting the $Name Code of Conduct" + $telemetryProperties['Key'] = $Name + $uriFragment = "codes_of_conduct/$Key" + $description = "Getting the $Key Code of Conduct" } elseif ((-not [String]::IsNullOrEmpty($OwnerName)) -and (-not [String]::IsNullOrEmpty($RepositoryName))) { @@ -458,7 +500,7 @@ function Get-GitHubCodeOfConduct $params = @{ 'UriFragment' = $uriFragment 'Method' = 'Get' - 'AcceptHeader' = 'application/vnd.github.scarlet-witch-preview+json' + 'AcceptHeader' = $script:scarletWitchAcceptHeader 'Description' = $description 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name @@ -466,10 +508,20 @@ function Get-GitHubCodeOfConduct 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + $result = Invoke-GHRestMethod @params + foreach ($item in $result) + { + $item.PSObject.TypeNames.Insert(0, $script:GitHubCodeOfConductTypeName) + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + Add-Member -InputObject $item -Name 'CodeOfConductKey' -Value $item.key -MemberType NoteProperty -Force + } + } + + return $result } -function Get-GitHubGitIgnore +filter Get-GitHubGitIgnore { <# .SYNOPSIS @@ -484,6 +536,9 @@ function Get-GitHubGitIgnore The name of the .gitignore template whose content should be fetched. Not providing this will cause a list of all available templates to be returned. + .PARAMETER RawContent + If specified, the raw content of the specified .gitignore file will be returned. + .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. @@ -494,6 +549,9 @@ function Get-GitHubGitIgnore the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Gitignore + .EXAMPLE Get-GitHubGitIgnore @@ -505,10 +563,17 @@ function Get-GitHubGitIgnore Returns the content of the VisualStudio.gitignore template. #> [CmdletBinding(SupportsShouldProcess)] + [OutputType({$script:GitHubGitignoreTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( + [Parameter( + ValueFromPipeline, + ParameterSetName='Individual')] [string] $Name, + [Parameter(ParameterSetName='Individual')] + [switch] $RawContent, + [string] $AccessToken, [switch] $NoStatus @@ -537,5 +602,21 @@ function Get-GitHubGitIgnore 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + if ($RawContent) + { + $params['AcceptHeader'] = (Get-MediaAcceptHeader -MediaType 'Raw') + } + + $result = Invoke-GHRestMethod @params + if ($PSBoundParameters.ContainsKey('Name') -and (-not $RawContent)) + { + $result.PSObject.TypeNames.Insert(0, $script:GitHubGitignoreTypeName) + } + + if ($RawContent) + { + $result = [System.Text.Encoding]::UTF8.GetString($result) + } + + return $result } From 976d57ef2895f847ad0887b41ab30ff578864508 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 6 Jun 2020 15:08:16 -0700 Subject: [PATCH 13/80] Add projects support --- GitHubLabels.ps1 | 1 + GitHubMilestones.ps1 | 1 + GitHubOrganizations.ps1 | 2 +- GitHubProjects.ps1 | 99 +++++++++++++++++++++++++++++++++++------ GitHubPullRequests.ps1 | 6 +-- GitHubReleases.ps1 | 7 +-- GitHubRepositories.ps1 | 2 +- GitHubTeams.ps1 | 2 +- GitHubUsers.ps1 | 2 +- 9 files changed, 95 insertions(+), 27 deletions(-) diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index dfbcf618..7e789da6 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -1050,6 +1050,7 @@ filter Add-GitHubLabelAdditionalProperties is optional based on what InputObject contains. #> [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] param( [Parameter( Mandatory, diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index cc7f70a5..45b87827 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -632,6 +632,7 @@ filter Add-GitHubMilestoneAdditionalProperties is optional based on what InputObject contains. #> [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] param( [Parameter( Mandatory, diff --git a/GitHubOrganizations.ps1 b/GitHubOrganizations.ps1 index 33afac9e..1c541663 100644 --- a/GitHubOrganizations.ps1 +++ b/GitHubOrganizations.ps1 @@ -171,7 +171,7 @@ filter Add-GitHubOrganizationAdditionalProperties is optional based on what InputObject contains. #> [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Justification="Internal helper that doesn't change system state.")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] param( [Parameter( Mandatory, diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 6d026730..86ad863d 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -1,7 +1,13 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubProject +@{ + GitHubProjectTypeName = 'GitHub.Project' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + +filter Get-GitHubProject { <# .DESCRIPTION @@ -44,6 +50,9 @@ function Get-GitHubProject the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Project + .EXAMPLE Get-GitHubProject -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -77,6 +86,7 @@ function Get-GitHubProject [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName = 'Elements')] + [OutputType({$script:GitHubPullRequestTypeName})] [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')] @@ -85,7 +95,11 @@ function Get-GitHubProject [Parameter(Mandatory, ParameterSetName = 'Elements')] [string] $RepositoryName, - [Parameter(Mandatory, ParameterSetName = 'Uri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter(Mandatory, ParameterSetName = 'Organization')] @@ -94,7 +108,8 @@ function Get-GitHubProject [Parameter(Mandatory, ParameterSetName = 'User')] [string] $UserName, - [Parameter(Mandatory, ParameterSetName = 'Project')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'Project')] + [Alias('ProjectId')] [int64] $Project, [ValidateSet('Open', 'Closed', 'All')] @@ -165,11 +180,11 @@ function Get-GitHubProject 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubProjectAdditionalProperties) } -function New-GitHubProject +filter New-GitHubProject { <# .DESCRIPTION @@ -212,6 +227,9 @@ function New-GitHubProject the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Project + .EXAMPLE New-GitHubProject -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestProject @@ -235,6 +253,7 @@ function New-GitHubProject [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName = 'Elements')] + [OutputType({$script:GitHubPullRequestTypeName})] [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')] @@ -243,7 +262,11 @@ function New-GitHubProject [Parameter(Mandatory, ParameterSetName = 'Elements')] [string] $RepositoryName, - [Parameter(Mandatory, ParameterSetName = 'Uri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter(Mandatory, ParameterSetName = 'Organization')] @@ -317,10 +340,10 @@ function New-GitHubProject 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubProjectAdditionalProperties) } -function Set-GitHubProject +filter Set-GitHubProject { <# .DESCRIPTION @@ -357,6 +380,9 @@ function Set-GitHubProject the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Project + .EXAMPLE Set-GitHubProject -Project 999999 -State Closed @@ -369,11 +395,12 @@ function Set-GitHubProject Get the ID for the 'TestProject' project for the Microsoft\PowerShellForGitHub repository and set state to closed. #> - [CmdletBinding( - SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess)] + [OutputType({$script:GitHubPullRequestTypeName})] [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)] + [Parameter(Mandatory, ValueFromPipelineByPropertyName)] + [Alias('ProjectId')] [int64] $Project, [string] $Description, @@ -436,10 +463,10 @@ function Set-GitHubProject 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubProjectAdditionalProperties) } -function Remove-GitHubProject +filter Remove-GitHubProject { <# .DESCRIPTION @@ -491,7 +518,8 @@ function Remove-GitHubProject [Alias('Delete-GitHubProject')] [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)] + [Parameter(Mandatory, ValueFromPipelineByPropertyName)] + [Alias('ProjectId')] [int64] $Project, [switch] $Force, @@ -530,3 +558,46 @@ function Remove-GitHubProject } } + +filter Add-GitHubProjectAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Project objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. +#> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubProjectTypeName + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $item.html_url -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'ProjectId' -Value $item.id -MemberType NoteProperty -Force + + if ($null -ne $item.creator) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.creator + } + } + + Write-Output $item + } +} diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index aad6879b..5a57bc39 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -421,6 +421,7 @@ filter Add-GitHubPullRequestAdditionalProperties The type that should be assigned to the object. #> [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] param( [Parameter( Mandatory, @@ -442,10 +443,7 @@ filter Add-GitHubPullRequestAdditionalProperties Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $item.html_url -MemberType NoteProperty -Force } - if (-not [String]::IsNullOrEmpty($item.id)) - { - Add-Member -InputObject $item -Name 'PullRequestId' -Value $item.id -MemberType NoteProperty -Force - } + Add-Member -InputObject $item -Name 'PullRequestId' -Value $item.id -MemberType NoteProperty -Force if ($null -ne $item.user) { diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index 6a361e87..03330380 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -231,7 +231,7 @@ filter Add-GitHubRepositoryAdditionalProperties The type that should be assigned to the object. #> [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Justification="Internal helper that doesn't change system state.")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] param( [Parameter( Mandatory, @@ -253,10 +253,7 @@ filter Add-GitHubRepositoryAdditionalProperties Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $item.html_url -MemberType NoteProperty -Force } - if (-not [String]::IsNullOrEmpty($item.id)) - { - Add-Member -InputObject $item -Name 'ReleaseId' -Value $item.id -MemberType NoteProperty -Force - } + Add-Member -InputObject $item -Name 'ReleaseId' -Value $item.id -MemberType NoteProperty -Force if ($null -ne $item.author) { diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 680346ca..6819eb73 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -1707,7 +1707,7 @@ filter Add-GitHubRepositoryAdditionalProperties is optional based on what InputObject contains. #> [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Justification="Internal helper that doesn't change system state.")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] param( [Parameter( Mandatory, diff --git a/GitHubTeams.ps1 b/GitHubTeams.ps1 index cd0aa2fc..0458b613 100644 --- a/GitHubTeams.ps1 +++ b/GitHubTeams.ps1 @@ -264,7 +264,7 @@ filter Add-GitHubTeamAdditionalProperties is optional based on what InputObject contains. #> [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Justification="Internal helper that doesn't change system state.")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] param( [Parameter( Mandatory, diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index b77abebc..76643d70 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -330,7 +330,7 @@ filter Add-GitHubUserAdditionalProperties is optional based on what InputObject contains. #> [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Justification="Internal helper that doesn't change system state.")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] param( [Parameter( Mandatory, From ce3460ec93e9cea19b4dddee6dc4870e088f9d9f Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 6 Jun 2020 15:19:52 -0700 Subject: [PATCH 14/80] Add project column support --- GitHubProjectColumns.ps1 | 114 +++++++++++++++++++++++++++++++-------- 1 file changed, 93 insertions(+), 21 deletions(-) diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index 4e4d0e82..02b11052 100644 --- a/GitHubProjectColumns.ps1 +++ b/GitHubProjectColumns.ps1 @@ -1,7 +1,13 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubProjectColumn +@{ + GitHubProjectColumnTypeName = 'GitHub.ProjectColumn' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + +filter Get-GitHubProjectColumn { <# .DESCRIPTION @@ -25,6 +31,9 @@ function Get-GitHubProjectColumn the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.ProjectColumn + .EXAMPLE Get-GitHubProjectColumn -Project 999999 @@ -38,13 +47,22 @@ function Get-GitHubProjectColumn [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName = 'Project')] + [OutputType({$script:GitHubProjectColumnTypeName})] [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 = 'Project')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName = 'Project')] + [Alias('ProjectId')] [int64] $Project, - [Parameter(Mandatory, ParameterSetName = 'Column')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName = 'Column')] + [Alias('ColumnId')] [int64] $Column, [string] $AccessToken, @@ -84,10 +102,10 @@ function Get-GitHubProjectColumn 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubProjectColumnAdditionalProperties) } -function New-GitHubProjectColumn +filter New-GitHubProjectColumn { <# .DESCRIPTION @@ -111,18 +129,24 @@ function New-GitHubProjectColumn the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.ProjectColumn + .EXAMPLE New-GitHubProjectColumn -Project 999999 -Name 'Done' Creates a column called 'Done' for the project with ID 999999. #> - [CmdletBinding( - SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess)] + [OutputType({$script:GitHubProjectColumnTypeName})] [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)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('ProjectId')] [int64] $Project, [Parameter(Mandatory)] @@ -157,10 +181,10 @@ function New-GitHubProjectColumn 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubProjectColumnAdditionalProperties) } -function Set-GitHubProjectColumn +filter Set-GitHubProjectColumn { <# .DESCRIPTION @@ -184,17 +208,23 @@ function Set-GitHubProjectColumn the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.ProjectColumn + .EXAMPLE Set-GitHubProjectColumn -Column 999999 -Name NewColumnName Set the project column name to 'NewColumnName' with column with ID 999999. #> - [CmdletBinding( - SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess)] + [OutputType({$script:GitHubProjectColumnTypeName})] [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)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('ColumnId')] [int64] $Column, [Parameter(Mandatory)] @@ -228,10 +258,10 @@ function Set-GitHubProjectColumn 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubProjectColumnAdditionalProperties) } -function Remove-GitHubProjectColumn +filter Remove-GitHubProjectColumn { <# .DESCRIPTION @@ -276,7 +306,10 @@ function Remove-GitHubProjectColumn [Alias('Delete-GitHubProjectColumn')] [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)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('ColumnId')] [int64] $Column, [switch] $Force, @@ -315,7 +348,7 @@ function Remove-GitHubProjectColumn } } -function Move-GitHubProjectColumn +filter Move-GitHubProjectColumn { <# .DESCRIPTION @@ -361,12 +394,14 @@ function Move-GitHubProjectColumn Moves the project column with ID 999999 to the position after column with ID 888888. #> - [CmdletBinding( - SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess)] [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)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('ColumnId')] [int64] $Column, [switch] $First, @@ -423,4 +458,41 @@ function Move-GitHubProjectColumn } return Invoke-GHRestMethod @params -} \ No newline at end of file +} + +filter Add-GitHubProjectColumnAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Project objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. +#> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubProjectColumnTypeName + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + Add-Member -InputObject $item -Name 'ColumnId' -Value $item.id -MemberType NoteProperty -Force + } + + Write-Output $item + } +} From 95c416cafaae205ebc149fe14818303dbc1fec62 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 6 Jun 2020 15:30:06 -0700 Subject: [PATCH 15/80] Add Project Card support --- GitHubProjectCards.ps1 | 118 ++++++++++++++++++++++++++++++++------- GitHubProjectColumns.ps1 | 4 +- GitHubProjects.ps1 | 2 +- 3 files changed, 102 insertions(+), 22 deletions(-) diff --git a/GitHubProjectCards.ps1 b/GitHubProjectCards.ps1 index 10a4d46d..d579792b 100644 --- a/GitHubProjectCards.ps1 +++ b/GitHubProjectCards.ps1 @@ -1,7 +1,13 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubProjectCard +@{ + GitHubProjectCardTypeName = 'GitHub.ProjectCard' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + +filter Get-GitHubProjectCard { <# .DESCRIPTION @@ -26,6 +32,9 @@ function Get-GitHubProjectCard the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.ProjectCard + .EXAMPLE Get-GitHubProjectCard -Column 999999 @@ -49,12 +58,21 @@ function Get-GitHubProjectCard [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName = 'Column')] + [OutputType({$script:GitHubProjectCardTypeName})] [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 = 'Column')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName = 'Column')] + [Alias('ColumnId')] [int64] $Column, - [Parameter(Mandatory, ParameterSetName = 'Card')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName = 'Card')] + [Alias('CardId')] [int64] $Card, [ValidateSet('All', 'Archived', 'NotArchived')] @@ -107,10 +125,10 @@ function Get-GitHubProjectCard 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubProjectCardAdditionalProperties) } -function New-GitHubProjectCard +filter New-GitHubProjectCard { <# .DESCRIPTION @@ -142,6 +160,9 @@ function New-GitHubProjectCard the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.ProjectCard + .EXAMPLE New-GitHubProjectCard -Column 999999 -Note 'Note on card' @@ -165,10 +186,14 @@ function New-GitHubProjectCard [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName = 'Note')] + [OutputType({$script:GitHubProjectCardTypeName})] [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)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('ColumnId')] [int64] $Column, [Parameter(Mandatory, ParameterSetName = 'Note')] @@ -223,10 +248,10 @@ function New-GitHubProjectCard 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubProjectCardAdditionalProperties) } -function Set-GitHubProjectCard +filter Set-GitHubProjectCard { <# .DESCRIPTION @@ -257,6 +282,9 @@ function Set-GitHubProjectCard the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.ProjectCard + .EXAMPLE Set-GitHubProjectCard -Card 999999 -Note UpdatedNote @@ -273,11 +301,15 @@ function Set-GitHubProjectCard Restores the card with ID 999999. #> [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName = 'Note')] + SupportsShouldProcess, + DefaultParameterSetName = 'Note')] + [OutputType({$script:GitHubProjectCardTypeName})] [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)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('CardId')] [int64] $Card, [string] $Note, @@ -332,10 +364,10 @@ function Set-GitHubProjectCard 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubProjectCardAdditionalProperties) } -function Remove-GitHubProjectCard +filter Remove-GitHubProjectCard { <# .DESCRIPTION @@ -380,7 +412,10 @@ function Remove-GitHubProjectCard [Alias('Delete-GitHubProjectCard')] [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)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('CardId')] [int64] $Card, [switch] $Force, @@ -419,7 +454,7 @@ function Remove-GitHubProjectCard } } -function Move-GitHubProjectCard +filter Move-GitHubProjectCard { <# .DESCRIPTION @@ -474,11 +509,13 @@ function Move-GitHubProjectCard Moves the project card with ID 999999 to the position after the card ID 888888, in the column with ID 123456. #> - [CmdletBinding( - SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess)] [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)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('CardId')] [int64] $Card, [switch] $Top, @@ -543,4 +580,47 @@ function Move-GitHubProjectCard } return Invoke-GHRestMethod @params -} \ No newline at end of file +} + + +filter Add-GitHubProjectCardAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Project Card objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. +#> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubProjectColumnTypeName + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + Add-Member -InputObject $item -Name 'CardId' -Value $item.id -MemberType NoteProperty -Force + + if ($null -ne $item.creator) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.creator + } + } + + Write-Output $item + } +} diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index 02b11052..6bd81bf5 100644 --- a/GitHubProjectColumns.ps1 +++ b/GitHubProjectColumns.ps1 @@ -464,7 +464,7 @@ filter Add-GitHubProjectColumnAdditionalProperties { <# .SYNOPSIS - Adds type name and additional properties to ease pipelining to GitHub Project objects. + Adds type name and additional properties to ease pipelining to GitHub Project Column objects. .PARAMETER InputObject The GitHub object to add additional properties to. @@ -491,7 +491,7 @@ filter Add-GitHubProjectColumnAdditionalProperties if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { Add-Member -InputObject $item -Name 'ColumnId' -Value $item.id -MemberType NoteProperty -Force - } + } Write-Output $item } diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 86ad863d..60717d62 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -596,7 +596,7 @@ filter Add-GitHubProjectAdditionalProperties { $null = Add-GitHubUserAdditionalProperties -InputObject $item.creator } - } + } Write-Output $item } From 463ccc02357023c1cb85867e097113e2a8b69183 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 6 Jun 2020 15:42:54 -0700 Subject: [PATCH 16/80] Add Organization and Milestone support --- GitHubMilestones.ps1 | 28 +++++----------------------- GitHubOrganizations.ps1 | 7 ++++--- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index 45b87827..d902d057 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -170,7 +170,7 @@ filter Get-GitHubMilestone 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubMilestoneAdditionalProperties) } filter New-GitHubMilestone @@ -323,7 +323,7 @@ filter New-GitHubMilestone 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubMilestoneAdditionalProperties) } filter Set-GitHubMilestone @@ -491,7 +491,7 @@ filter Set-GitHubMilestone 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubMilestoneAdditionalProperties) } filter Remove-GitHubMilestone @@ -622,14 +622,6 @@ filter Add-GitHubMilestoneAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. - - .PARAMETER OwnerName - Owner of the repository. This information might be obtainable from InputObject, so this - is optional based on what InputObject contains. - - .PARAMETER RepositoryName - Name of the repository. This information might be obtainable from InputObject, so this - is optional based on what InputObject contains. #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] @@ -640,11 +632,7 @@ filter Add-GitHubMilestoneAdditionalProperties [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] - [string] $TypeName = $script:GitHubMilestoneTypeName, - - [string] $OwnerName, - - [string] $RepositoryName + [string] $TypeName = $script:GitHubMilestoneTypeName ) foreach ($item in $InputObject) @@ -653,13 +641,7 @@ filter Add-GitHubMilestoneAdditionalProperties if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { - if ($PSBoundParameters.ContainsKey('OwnerName') -and - $PSBoundParameters.ContainsKey('RepositoryName')) - { - $repositoryUrl = (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) - Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force - } - + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $item.html_url -MemberType NoteProperty -Force Add-Member -InputObject $item -Name 'MilestoneId' -Value $item.id -MemberType NoteProperty -Force Add-Member -InputObject $item -Name 'MilestoneNumber' -Value $item.number -MemberType NoteProperty -Force diff --git a/GitHubOrganizations.ps1 b/GitHubOrganizations.ps1 index 1c541663..69c2b50c 100644 --- a/GitHubOrganizations.ps1 +++ b/GitHubOrganizations.ps1 @@ -7,7 +7,7 @@ Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value } - function Get-GitHubOrganizationMember +filter Get-GitHubOrganizationMember { <# .SYNOPSIS @@ -32,7 +32,8 @@ If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - [PSCustomObject[]] List of members within the organization. + GitHub.User + List of members within the organization. .EXAMPLE Get-GitHubOrganizationMember -OrganizationName PowerShell @@ -66,7 +67,7 @@ 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubUserAdditionalProperties) } function Test-GitHubOrganizationMember From 396414c088aa84308b41735fd1127add8d821f41 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 6 Jun 2020 16:44:23 -0700 Subject: [PATCH 17/80] Add issue support --- GitHubCore.ps1 | 19 +++- GitHubIssues.ps1 | 237 ++++++++++++++++++++++++++++++--------- GitHubLabels.ps1 | 2 + GitHubMilestones.ps1 | 6 +- GitHubOrganizations.ps1 | 2 + GitHubProjectCards.ps1 | 2 + GitHubProjectColumns.ps1 | 2 + GitHubProjects.ps1 | 6 +- GitHubPullRequests.ps1 | 20 ++-- GitHubReleases.ps1 | 6 +- GitHubRepositories.ps1 | 5 +- GitHubTeams.ps1 | 2 + GitHubUsers.ps1 | 2 + 13 files changed, 245 insertions(+), 66 deletions(-) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 98175419..5f78148c 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -727,19 +727,24 @@ function Split-GitHubUri [PSCustomObject] - The OwnerName and RepositoryName elements from the provided URL .EXAMPLE - Split-GitHubUri -Uri 'https://github.com/PowerShell/PowerShellForGitHub' + Split-GitHubUri -Uri 'https://github.com/microsoft/PowerShellForGitHub' PowerShellForGitHub .EXAMPLE - Split-GitHubUri -Uri 'https://github.com/PowerShell/PowerShellForGitHub' -RepositoryName + Split-GitHubUri -Uri 'https://github.com/microsoft/PowerShellForGitHub' -RepositoryName PowerShellForGitHub .EXAMPLE - Split-GitHubUri -Uri 'https://github.com/PowerShell/PowerShellForGitHub' -OwnerName + Split-GitHubUri -Uri 'https://github.com/microsoft/PowerShellForGitHub' -OwnerName - PowerShell + microsoft + + .EXAMPLE + Split-GitHubUri -Uri 'https://github.com/microsoft/PowerShellForGitHub' + + @{'ownerName' = 'microsoft'; 'repositoryName' = 'PowerShellForGitHub'} #> [CmdletBinding(DefaultParameterSetName='RepositoryName')] param @@ -776,10 +781,14 @@ function Split-GitHubUri { return $components.ownerName } - elseif ($RepositoryName -or ($PSCmdlet.ParameterSetName -eq 'RepositoryName')) + elseif ($RepositoryName) { return $components.repositoryName } + else + { + return $components + } } function Join-GitHubUri diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index d27bf93e..ef843c0a 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -1,7 +1,14 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubIssue +@{ + GitHubIssueTypeName = 'GitHub.Issue' + GitHubIssueTimelineEventTypeName = 'GitHub.IssueTimelineEvent' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + +filter Get-GitHubIssue { <# .SYNOPSIS @@ -105,6 +112,9 @@ function Get-GitHubIssue the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Issue + .EXAMPLE Get-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -State Open @@ -118,6 +128,7 @@ function Get-GitHubIssue [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubIssueTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -128,7 +139,9 @@ function Get-GitHubIssue [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [string] $OrganizationName, @@ -136,6 +149,8 @@ function Get-GitHubIssue [ValidateSet('All', 'OwnedAndMember')] [string] $RepositoryType = 'All', + [Parameter(ValueFromPipelineByPropertyName)] + [Alias('IssueNumber')] [int64] $Issue, [switch] $IgnorePullRequests, @@ -324,7 +339,7 @@ function Get-GitHubIssue try { - $result = Invoke-GHRestMethodMultipleResult @params + $result = (Invoke-GHRestMethodMultipleResult @params | Add-GitHubIssueAdditionalProperties) if ($IgnorePullRequests) { @@ -339,7 +354,7 @@ function Get-GitHubIssue finally {} } -function Get-GitHubIssueTimeline +filter Get-GitHubIssueTimeline { <# .SYNOPSIS @@ -376,12 +391,16 @@ function Get-GitHubIssueTimeline the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.IssueTimelineEvent + .EXAMPLE Get-GitHubIssueTimeline -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 24 #> [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubIssueTimelineEventTypeName})] [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( @@ -393,10 +412,15 @@ function Get-GitHubIssueTimeline [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('IssueNumber')] [int64] $Issue, [string] $AccessToken, @@ -425,10 +449,10 @@ function Get-GitHubIssueTimeline 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubIssueAdditionalProperties) } -function New-GitHubIssue +filter New-GitHubIssue { <# .SYNOPSIS @@ -485,12 +509,16 @@ function New-GitHubIssue the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Issue + .EXAMPLE New-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Title 'Test Issue' #> [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubIssueTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -501,7 +529,9 @@ function New-GitHubIssue [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter(Mandatory)] @@ -556,10 +586,10 @@ function New-GitHubIssue 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) } -function Update-GitHubIssue +filter Update-GitHubIssue { <# .SYNOPSIS @@ -625,12 +655,16 @@ function Update-GitHubIssue the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Issue + .EXAMPLE Update-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 4 -Title 'Test Issue' -State Closed #> [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubIssueTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -641,10 +675,15 @@ function Update-GitHubIssue [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('IssueNumber')] [int64] $Issue, [string] $Title, @@ -707,10 +746,10 @@ function Update-GitHubIssue 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) } -function Lock-GitHubIssue +filter Lock-GitHubIssue { <# .SYNOPSIS @@ -766,10 +805,15 @@ function Lock-GitHubIssue [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('IssueNumber')] [int64] $Issue, [ValidateSet('OffTopic', 'TooHeated', 'Resolved', 'Spam')] @@ -823,7 +867,7 @@ function Lock-GitHubIssue return Invoke-GHRestMethod @params } -function Unlock-GitHubIssue +filter Unlock-GitHubIssue { <# .SYNOPSIS @@ -863,52 +907,145 @@ function Unlock-GitHubIssue .EXAMPLE Unlock-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 4 #> -[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.")] -[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(ParameterSetName='Elements')] - [string] $OwnerName, + [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.")] + [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(ParameterSetName='Elements')] + [string] $OwnerName, - [Parameter(ParameterSetName='Elements')] - [string] $RepositoryName, + [Parameter(ParameterSetName='Elements')] + [string] $RepositoryName, - [Parameter( - Mandatory, - ParameterSetName='Uri')] - [string] $Uri, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Uri')] + [Alias('RepositoryUrl')] + [string] $Uri, - [Parameter(Mandatory)] - [int64] $Issue, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('IssueNumber')] + [int64] $Issue, + + [string] $AccessToken, - [string] $AccessToken, + [switch] $NoStatus + ) + + Write-InvocationLog - [switch] $NoStatus -) + $elements = Resolve-RepositoryElements + $OwnerName = $elements.ownerName + $RepositoryName = $elements.repositoryName -Write-InvocationLog + $telemetryProperties = @{ + 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) + 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) + } -$elements = Resolve-RepositoryElements -$OwnerName = $elements.ownerName -$RepositoryName = $elements.repositoryName + $params = @{ + 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/lock" + 'Method' = 'Delete' + 'Description' = "Unlocking Issue #$Issue on $RepositoryName" + 'AcceptHeader' = 'application/vnd.github.sailor-v-preview+json' + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + } -$telemetryProperties = @{ - 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) - 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) + return Invoke-GHRestMethod @params } -$params = @{ - 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/lock" - 'Method' = 'Delete' - 'Description' = "Unlocking Issue #$Issue on $RepositoryName" - 'AcceptHeader' = 'application/vnd.github.sailor-v-preview+json' - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) -} +filter Add-GitHubIssueAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Issue objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. +#> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubIssueTypeName + ) -return Invoke-GHRestMethod @params + foreach ($item in $InputObject) + { + # Pull requests are _also_ issues. A pull request that is retrieved through the + # Issue endpoint will also have a 'pull_request' property. Let's make sure that + # we mark it up appropriately. + if ($null -ne $item.pull_request) + { + $null = Add-GitHubPullRequestAdditionalProperties -InputObject $item + Write-Output $item + continue + } + + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + $elements = Split-GitHubUri -Uri $item.html_url + $repositoryUrl = Join-GitHubUri @elements + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'IssueId' -Value $item.id -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'IssueNumber' -Value $item.number -MemberType NoteProperty -Force + + if ($null -ne $item.user) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.user + } + + if ($null -ne $item.labels) + { + $null = Add-GitHubLabelAdditionalProperties -InputObject $item.labels + } + + if ($null -ne $item.milestone) + { + $null = Add-GitHubMilestoneAdditionalProperties -InputObject $item.milestone + } + + if ($null -ne $item.assignee) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.assignee + } + + if ($null -ne $item.assignees) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.assignees + } + + if ($null -ne $item.closed_by) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.closed_by + } + + if ($null -ne $item.repository) + { + $null = Add-GitHubRepositoryAdditionalProperties -InputObject $item.repository + } + } + + Write-Output $item + } } diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 7e789da6..4c74bd62 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -1055,6 +1055,8 @@ filter Add-GitHubLabelAdditionalProperties [Parameter( Mandatory, ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index d902d057..5fd86741 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -629,6 +629,8 @@ filter Add-GitHubMilestoneAdditionalProperties [Parameter( Mandatory, ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] @@ -641,7 +643,9 @@ filter Add-GitHubMilestoneAdditionalProperties if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { - Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $item.html_url -MemberType NoteProperty -Force + $elements = Split-GitHubUri -Uri $item.html_url + $repositoryUrl = Join-GitHubUri @elements + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force Add-Member -InputObject $item -Name 'MilestoneId' -Value $item.id -MemberType NoteProperty -Force Add-Member -InputObject $item -Name 'MilestoneNumber' -Value $item.number -MemberType NoteProperty -Force diff --git a/GitHubOrganizations.ps1 b/GitHubOrganizations.ps1 index 69c2b50c..b5efed27 100644 --- a/GitHubOrganizations.ps1 +++ b/GitHubOrganizations.ps1 @@ -177,6 +177,8 @@ filter Add-GitHubOrganizationAdditionalProperties [Parameter( Mandatory, ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] diff --git a/GitHubProjectCards.ps1 b/GitHubProjectCards.ps1 index d579792b..540fb1d3 100644 --- a/GitHubProjectCards.ps1 +++ b/GitHubProjectCards.ps1 @@ -601,6 +601,8 @@ filter Add-GitHubProjectCardAdditionalProperties [Parameter( Mandatory, ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index 6bd81bf5..c5ee0f64 100644 --- a/GitHubProjectColumns.ps1 +++ b/GitHubProjectColumns.ps1 @@ -478,6 +478,8 @@ filter Add-GitHubProjectColumnAdditionalProperties [Parameter( Mandatory, ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 60717d62..2341e254 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -577,6 +577,8 @@ filter Add-GitHubProjectAdditionalProperties [Parameter( Mandatory, ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] @@ -589,7 +591,9 @@ filter Add-GitHubProjectAdditionalProperties if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { - Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $item.html_url -MemberType NoteProperty -Force + $elements = Split-GitHubUri -Uri $item.html_url + $repositoryUrl = Join-GitHubUri @elements + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force Add-Member -InputObject $item -Name 'ProjectId' -Value $item.id -MemberType NoteProperty -Force if ($null -ne $item.creator) diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index 5a57bc39..384a59a7 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -92,7 +92,7 @@ filter Get-GitHubPullRequest [string] $Uri, [Parameter(ValueFromPipelineByPropertyName)] - [Alias('PullRequestId')] + [Alias('PullRequestNumber')] [int64] $PullRequest, [ValidateSet('Open', 'Closed', 'All')] @@ -426,6 +426,8 @@ filter Add-GitHubPullRequestAdditionalProperties [Parameter( Mandatory, ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] @@ -438,19 +440,18 @@ filter Add-GitHubPullRequestAdditionalProperties if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { - if (-not [String]::IsNullOrEmpty($item.html_url)) - { - Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $item.html_url -MemberType NoteProperty -Force - } - + $elements = Split-GitHubUri -Uri $item.html_url + $repositoryUrl = Join-GitHubUri @elements + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force Add-Member -InputObject $item -Name 'PullRequestId' -Value $item.id -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'PullRequestNumber' -Value $item.number -MemberType NoteProperty -Force if ($null -ne $item.user) { $null = Add-GitHubUserAdditionalProperties -InputObject $item.user } - if ($null -ne $item.label) + if ($null -ne $item.labels) { $null = Add-GitHubLabelAdditionalProperties -InputObject $item.label } @@ -480,6 +481,11 @@ filter Add-GitHubPullRequestAdditionalProperties $null = Add-GitHubTeamAdditionalProperties -InputObject $item.requested_teams } + if ($null -ne $item.merged_by) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.merged_by + } + # TODO: What type are item.head and item.base? } diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index 03330380..d86e24f6 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -236,6 +236,8 @@ filter Add-GitHubRepositoryAdditionalProperties [Parameter( Mandatory, ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] @@ -250,7 +252,9 @@ filter Add-GitHubRepositoryAdditionalProperties { if (-not [String]::IsNullOrEmpty($item.html_url)) { - Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $item.html_url -MemberType NoteProperty -Force + $elements = Split-GitHubUri -Uri $item.html_url + $repositoryUrl = Join-GitHubUri @elements + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force } Add-Member -InputObject $item -Name 'ReleaseId' -Value $item.id -MemberType NoteProperty -Force diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 6819eb73..a272eb5a 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -1712,6 +1712,8 @@ filter Add-GitHubRepositoryAdditionalProperties [Parameter( Mandatory, ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] @@ -1728,7 +1730,8 @@ filter Add-GitHubRepositoryAdditionalProperties if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { - $repositoryUrl = $item.html_url + $elements = Split-GitHubUri -Uri $item.html_url + $repositoryUrl = Join-GitHubUri @elements if ([String]::IsNullOrEmpty($repositoryUrl) -and $PSBoundParameters.ContainsKey('OwnerName') -and $PSBoundParameters.ContainsKey('RepositoryName')) diff --git a/GitHubTeams.ps1 b/GitHubTeams.ps1 index 0458b613..35691c9d 100644 --- a/GitHubTeams.ps1 +++ b/GitHubTeams.ps1 @@ -269,6 +269,8 @@ filter Add-GitHubTeamAdditionalProperties [Parameter( Mandatory, ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 76643d70..9f46d58c 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -335,6 +335,8 @@ filter Add-GitHubUserAdditionalProperties [Parameter( Mandatory, ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] From 1076e91148b42b5b254f8704536da56006573fe8 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 6 Jun 2020 16:57:12 -0700 Subject: [PATCH 18/80] Add Event support --- GitHubCore.ps1 | 16 +++++--- GitHubEvents.ps1 | 100 ++++++++++++++++++++++++++++++++++++++--------- GitHubIssues.ps1 | 9 ++--- 3 files changed, 96 insertions(+), 29 deletions(-) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 5f78148c..036e476c 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -4,15 +4,18 @@ @{ defaultAcceptHeader = 'application/vnd.github.v3+json' mediaTypeVersion = 'v3' - squirrelAcceptHeader = 'application/vnd.github.squirrel-girl-preview' - symmetraAcceptHeader = 'application/vnd.github.symmetra-preview+json' - mercyAcceptHeader = 'application/vnd.github.mercy-preview+json' - nebulaAcceptHeader = 'application/vnd.github.nebula-preview+json' baptisteAcceptHeader = 'application/vnd.github.baptiste-preview+json' - scarletWitchAcceptHeader = 'application/vnd.github.scarlet-witch-preview+json' dorianAcceptHeader = 'application/vnd.github.dorian-preview+json' londonAcceptHeader = 'application/vnd.github.london-preview+json' - + machineManAcceptHeader = 'application/vnd.github.machine-man-preview' + mercyAcceptHeader = 'application/vnd.github.mercy-preview+json' + mockingbirdAcceptHeader = 'application/vnd.github.mockingbird-preview' + nebulaAcceptHeader = 'application/vnd.github.nebula-preview+json' + sailerVAcceptHeader = 'application/vnd.github.sailer-v-preview+json' + scarletWitchAcceptHeader = 'application/vnd.github.scarlet-witch-preview+json' + squirrelAcceptHeader = 'application/vnd.github.squirrel-girl-preview' + starfoxAcceptHeader = 'application/vnd.github.starfox-preview+json' + symmetraAcceptHeader = 'application/vnd.github.symmetra-preview+json' }.GetEnumerator() | ForEach-Object { Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value } @@ -747,6 +750,7 @@ function Split-GitHubUri @{'ownerName' = 'microsoft'; 'repositoryName' = 'PowerShellForGitHub'} #> [CmdletBinding(DefaultParameterSetName='RepositoryName')] + [OutputType([Hashtable])] param ( [Parameter(Mandatory)] diff --git a/GitHubEvents.ps1 b/GitHubEvents.ps1 index 7dae9bc9..73632844 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -1,7 +1,13 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubEvent +@{ + GitHubEventTypeName = 'GitHub.Event' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + +filter Get-GitHubEvent { <# .DESCRIPTION @@ -22,7 +28,7 @@ function Get-GitHubEvent The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER EventID + .PARAMETER EventId The ID of a specific event to get. If not supplied, will return back all events for this repository. .PARAMETER Issue @@ -38,6 +44,9 @@ function Get-GitHubEvent the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Event + .EXAMPLE Get-GitHubEvent -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -46,6 +55,7 @@ function Get-GitHubEvent [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='RepositoryElements')] + [OutputType({$script:GitHubEventTypeName})] [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='RepositoryElements')] @@ -58,17 +68,19 @@ function Get-GitHubEvent [Parameter(Mandatory, ParameterSetName='EventElements')] [string] $RepositoryName, - [Parameter(Mandatory, ParameterSetName='RepositoryUri')] - [Parameter(Mandatory, ParameterSetName='IssueUri')] - [Parameter(Mandatory, ParameterSetName='EventUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='RepositoryUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='EventUri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName='EventUri')] - [Parameter(Mandatory, ParameterSetName='EventElements')] - [int64] $EventID, + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='EventUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='EventElements')] + [int64] $EventId, - [Parameter(Mandatory, ParameterSetName='IssueUri')] - [Parameter(Mandatory, ParameterSetName='IssueElements')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueElements')] + [Alias('IssueNumber')] [int64] $Issue, [string] $AccessToken, @@ -92,10 +104,10 @@ function Get-GitHubEvent $uriFragment = "repos/$OwnerName/$RepositoryName/issues/events" $description = "Getting events for $RepositoryName" - if ($PSBoundParameters.ContainsKey('EventID')) + if ($PSBoundParameters.ContainsKey('EventId')) { - $uriFragment = "repos/$OwnerName/$RepositoryName/issues/events/$EventID" - $description = "Getting event $EventID for $RepositoryName" + $uriFragment = "repos/$OwnerName/$RepositoryName/issues/events/$EventId" + $description = "Getting event $EventId for $RepositoryName" } elseif ($PSBoundParameters.ContainsKey('Issue')) { @@ -104,10 +116,10 @@ function Get-GitHubEvent } $acceptHeaders = @( - 'application/vnd.github.starfox-preview+json', - 'application/vnd.github.sailer-v-preview+json', - 'application/vnd.github.symmetra-preview+json', - 'application/vnd.github.machine-man-preview') + $script:starfoxAcceptHeader, + $script:sailerVAcceptHeader, + $script:symmetraAcceptHeader, + $script:machineManAcceptHeader) $params = @{ 'UriFragment' = $uriFragment @@ -119,5 +131,57 @@ function Get-GitHubEvent 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubEventAdditionalProperties) +} + +filter Add-GitHubEventAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Event objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. +#> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubEventTypeName + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + $elements = Split-GitHubUri -Uri $item.url + $repositoryUrl = Join-GitHubUri @elements + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'EventId' -Value $item.id -MemberType NoteProperty -Force + + if ($null -ne $item.actor) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.actor + } + + if ($null -ne $item.issue) + { + $null = Add-GitHubIssueAdditionalProperties -InputObject $item.issue + } + } + + Write-Output $item + } } diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index ef843c0a..91419552 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -3,7 +3,6 @@ @{ GitHubIssueTypeName = 'GitHub.Issue' - GitHubIssueTimelineEventTypeName = 'GitHub.IssueTimelineEvent' }.GetEnumerator() | ForEach-Object { Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value } @@ -392,7 +391,7 @@ filter Get-GitHubIssueTimeline If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - GitHub.IssueTimelineEvent + GitHub.Event .EXAMPLE Get-GitHubIssueTimeline -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 24 @@ -400,7 +399,7 @@ filter Get-GitHubIssueTimeline [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [OutputType({$script:GitHubIssueTimelineEventTypeName})] + [OutputType({$script:GitHubEventTypeName})] [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( @@ -442,14 +441,14 @@ filter Get-GitHubIssueTimeline $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/timeline" 'Description' = "Getting timeline for Issue #$Issue in $RepositoryName" - 'AcceptHeader' = 'application/vnd.github.mockingbird-preview' + 'AcceptHeader' = $script:mockingbirdAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubIssueAdditionalProperties) + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubEventAdditionalProperties) } filter New-GitHubIssue From a6961faa37b3f95674168f697f6e5fa5d2be09c5 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 6 Jun 2020 16:58:55 -0700 Subject: [PATCH 19/80] Add contents support --- GitHubContents.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/GitHubContents.ps1 b/GitHubContents.ps1 index fce4b6c4..6a75d81e 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubContent +filter Get-GitHubContent { <# .SYNOPSIS @@ -73,9 +73,12 @@ function Get-GitHubContent [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, + [Parameter(ValueFromPipeline)] [string] $Path, [ValidateSet('Raw', 'Html', 'Object')] From 5f02002a01ac0d9eef64003da7b3ffb1aee47160 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sun, 7 Jun 2020 17:43:27 -0700 Subject: [PATCH 20/80] Add branches support --- GitHubBranches.ps1 | 60 +++++++++++++++++++++++++++++++++++++++++++--- GitHubCore.ps1 | 6 +++-- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/GitHubBranches.ps1 b/GitHubBranches.ps1 index 3bbb297a..dda90050 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -1,7 +1,13 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubRepositoryBranch +@{ + GitHubBranchTypeName = 'GitHub.Branch' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + +filter Get-GitHubRepositoryBranch { <# .SYNOPSIS @@ -39,7 +45,8 @@ function Get-GitHubRepositoryBranch If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - [PSCustomObject[]] List of branches within the given repository. + GitHub.Branch + List of branches within the given repository. .EXAMPLE Get-GitHubRepositoryBranch -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -54,6 +61,7 @@ function Get-GitHubRepositoryBranch [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubBranchTypeName})] [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.")] [Alias('Get-GitHubBranch')] @@ -66,9 +74,13 @@ function Get-GitHubRepositoryBranch [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, + [Parameter(ValueFromPipelineByPropertyName)] + [Alias('BranchName')] [string] $Name, [switch] $ProtectedOnly, @@ -104,6 +116,48 @@ function Get-GitHubRepositoryBranch 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubBranchAdditionalProperties) } +filter Add-GitHubBranchAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Branch objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. +#> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubBranchTypeName + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + $elements = Split-GitHubUri -Uri $item.commit.url + $repositoryUrl = Join-GitHubUri @elements + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + + Add-Member -InputObject $item -Name 'BranchName' -Value $item.name -MemberType NoteProperty -Force + } + + Write-Output $item + } +} diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 036e476c..18c35893 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -704,7 +704,7 @@ function Invoke-GHRestMethodMultipleResult } } -function Split-GitHubUri +filter Split-GitHubUri { <# .SYNOPSIS @@ -753,7 +753,9 @@ function Split-GitHubUri [OutputType([Hashtable])] param ( - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline)] [ValidateNotNullOrEmpty()] [string] $Uri, From a1d5936077bd0dc10a45955f307d5437103b7df9 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sun, 7 Jun 2020 17:53:41 -0700 Subject: [PATCH 21/80] Add Assignee support --- GitHubAssignees.ps1 | 62 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index 6a2c1309..d9212dd7 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubAssignee +filter Get-GitHubAssignee { <# .DESCRIPTION @@ -32,6 +32,9 @@ function Get-GitHubAssignee the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.User + .EXAMPLE Get-GitHubAssigneeList -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -40,6 +43,7 @@ function Get-GitHubAssignee [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubUserTypeName})] [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( @@ -51,7 +55,9 @@ function Get-GitHubAssignee [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, [string] $AccessToken, @@ -79,10 +85,10 @@ function Get-GitHubAssignee 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubUserAdditionalProperties) } -function Test-GitHubAssignee +filter Test-GitHubAssignee { <# .DESCRIPTION @@ -117,7 +123,8 @@ function Test-GitHubAssignee If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - [bool] If the assignee can be assigned to issues in the repository. + [bool] + If the assignee can be assigned to issues in the repository. .EXAMPLE Test-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee "LoginID123" @@ -127,7 +134,7 @@ function Test-GitHubAssignee [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [OutputType([bool])] + [OutputType([bool])] [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( @@ -139,9 +146,12 @@ function Test-GitHubAssignee [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, + [Alias('UserName')] [string] $Assignee, [string] $AccessToken, @@ -183,7 +193,7 @@ function Test-GitHubAssignee } } -function New-GithubAssignee +filter New-GithubAssignee { <# .DESCRIPTION @@ -221,6 +231,9 @@ function New-GithubAssignee the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Issue + .EXAMPLE New-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignee @@ -229,6 +242,7 @@ function New-GithubAssignee [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubIssueTypeName})] [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( @@ -240,14 +254,23 @@ function New-GithubAssignee [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('IssueId')] [int64] $Issue, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName)] [ValidateCount(1, 10)] + [Alias('UserName')] [string[]] $Assignee, [string] $AccessToken, @@ -284,10 +307,10 @@ function New-GithubAssignee 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) } -function Remove-GithubAssignee +filter Remove-GithubAssignee { <# .DESCRIPTION @@ -327,6 +350,9 @@ function Remove-GithubAssignee the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Issue + .EXAMPLE Remove-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees @@ -346,6 +372,7 @@ function Remove-GithubAssignee SupportsShouldProcess, DefaultParameterSetName='Elements', ConfirmImpact="High")] + [OutputType({$script:GitHubIssueTypeName})] [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(ParameterSetName='Elements')] @@ -356,13 +383,22 @@ function Remove-GithubAssignee [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('IssueId')] [int64] $Issue, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName)] + [Alias('UserName')] [string[]] $Assignee, [switch] $Force, @@ -408,6 +444,6 @@ function Remove-GithubAssignee 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) } } From c9a6942dd869a221e40a52e5703bd496a808b577 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sun, 7 Jun 2020 18:05:31 -0700 Subject: [PATCH 22/80] Add support for comments --- GitHubComments.ps1 | 159 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 120 insertions(+), 39 deletions(-) diff --git a/GitHubComments.ps1 b/GitHubComments.ps1 index ce8ac615..41260d4a 100644 --- a/GitHubComments.ps1 +++ b/GitHubComments.ps1 @@ -1,7 +1,13 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function Get-GitHubComment +@{ + GitHubCommentTypeName = 'GitHub.Comment' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + +filter Get-GitHubComment { <# .DESCRIPTION @@ -22,7 +28,7 @@ function Get-GitHubComment The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER CommentID + .PARAMETER Comment The ID of a specific comment to get. If not supplied, will return back all comments for this repository. .PARAMETER Issue @@ -55,6 +61,9 @@ function Get-GitHubComment the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Comment + .EXAMPLE Get-GitHubComment-OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -63,6 +72,7 @@ function Get-GitHubComment [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='RepositoryElements')] + [OutputType({$script:GitHubCommentTypeName})] [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='RepositoryElements')] @@ -75,17 +85,20 @@ function Get-GitHubComment [Parameter(Mandatory, ParameterSetName='CommentElements')] [string] $RepositoryName, - [Parameter(Mandatory, ParameterSetName='RepositoryUri')] - [Parameter(Mandatory, ParameterSetName='IssueUri')] - [Parameter(Mandatory, ParameterSetName='CommentUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='RepositoryUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='CommentUri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName='CommentUri')] - [Parameter(Mandatory, ParameterSetName='CommentElements')] - [string] $CommentID, + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='CommentUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='CommentElements')] + [Alias('CommentId')] + [string] $Comment, - [Parameter(Mandatory, ParameterSetName='IssueUri')] - [Parameter(Mandatory, ParameterSetName='IssueElements')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueElements')] + [Alias('IssueNumber')] [int64] $Issue, [Parameter(ParameterSetName='RepositoryUri')] @@ -130,13 +143,13 @@ function Get-GitHubComment 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) 'ProvidedIssue' = $PSBoundParameters.ContainsKey('Issue') - 'ProvidedComment' = $PSBoundParameters.ContainsKey('CommentID') + 'ProvidedComment' = $PSBoundParameters.ContainsKey('Comment') } - if ($PSBoundParameters.ContainsKey('CommentID')) + if ($PSBoundParameters.ContainsKey('Comment')) { - $uriFragment = "repos/$OwnerName/$RepositoryName/issues/comments/$CommentId" - $description = "Getting comment $CommentID for $RepositoryName" + $uriFragment = "repos/$OwnerName/$RepositoryName/issues/comments/$Comment" + $description = "Getting comment $Comment for $RepositoryName" } elseif ($PSBoundParameters.ContainsKey('Issue')) { @@ -187,10 +200,10 @@ function Get-GitHubComment 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethodMultipleResult @params + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubCommentAdditionalProperties) } -function New-GitHubComment +filter New-GitHubComment { <# .DESCRIPTION @@ -235,6 +248,9 @@ function New-GitHubComment the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Comment + .EXAMPLE New-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Body "Testing this API" @@ -243,6 +259,7 @@ function New-GitHubComment [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubCommentTypeName})] [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( @@ -254,10 +271,15 @@ function New-GitHubComment [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('IssueNumber')] [int64] $Issue, [Parameter(Mandatory)] @@ -299,10 +321,10 @@ function New-GitHubComment 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubCommentAdditionalProperties) } -function Set-GitHubComment +filter Set-GitHubComment { <# .DESCRIPTION @@ -323,8 +345,8 @@ function Set-GitHubComment The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER CommentID - The comment ID of the comment to edit. + .PARAMETER Comment + The ID of the comment to edit. .PARAMETER Body The new contents of the comment. @@ -347,14 +369,18 @@ function Set-GitHubComment the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .OUTPUTS + GitHub.Comment + .EXAMPLE - Set-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1 -Body "Testing this API" + Set-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Body "Testing this API" Update an existing comment in an issue for the Microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubCommentTypeName})] [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( @@ -366,11 +392,16 @@ function Set-GitHubComment [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] - [string] $CommentID, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('CommentId')] + [int64] $Comment, [Parameter(Mandatory)] [string] $Body, @@ -392,7 +423,7 @@ function Set-GitHubComment $telemetryProperties = @{ 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) - 'CommentID' = (Get-PiiSafeString -PlainText $CommentID) + 'Comment' = (Get-PiiSafeString -PlainText $Comment) } $hashBody = @{ @@ -400,10 +431,10 @@ function Set-GitHubComment } $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$CommentID" + 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$Comment" 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Patch' - 'Description' = "Update comment $CommentID for $RepositoryName" + 'Description' = "Update comment $Comment for $RepositoryName" 'AccessToken' = $AccessToken 'AcceptHeader' = (Get-MediaAcceptHeader -MediaType $MediaType -AsJson -AcceptHeader $squirrelAcceptHeader) 'TelemetryEventName' = $MyInvocation.MyCommand.Name @@ -411,10 +442,10 @@ function Set-GitHubComment 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubCommentAdditionalProperties) } -function Remove-GitHubComment +filter Remove-GitHubComment { <# .DESCRIPTION @@ -435,8 +466,8 @@ function Remove-GitHubComment The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER CommentID - The id of the comment to delete. + .PARAMETER Comment + The ID of the comment to delete. .PARAMETER Force If this switch is specified, you will not be prompted for confirmation of command execution. @@ -452,12 +483,12 @@ function Remove-GitHubComment If not supplied here, the DefaultNoStatus configuration property value will be used. .EXAMPLE - Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1 + Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Comment 1 Deletes a Github comment from the Microsoft\PowerShellForGitHub project. .EXAMPLE - Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1 -Confirm:$false + Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Confirm:$false Deletes a Github comment from the Microsoft\PowerShellForGitHub project without prompting confirmation. @@ -481,11 +512,16 @@ function Remove-GitHubComment [Parameter( Mandatory, + ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] - [string] $CommentID, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('CommentId')] + [int64] $Comment, [switch] $Force, @@ -503,7 +539,7 @@ function Remove-GitHubComment $telemetryProperties = @{ 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) - 'CommentID' = (Get-PiiSafeString -PlainText $CommentID) + 'Comment' = (Get-PiiSafeString -PlainText $Comment) } if ($Force -and (-not $Confirm)) @@ -511,12 +547,12 @@ function Remove-GitHubComment $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($CommentID, "Remove comment")) + if ($PSCmdlet.ShouldProcess($Comment, "Remove comment")) { $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$CommentID" + 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$Comment" 'Method' = 'Delete' - 'Description' = "Removing comment $CommentID for $RepositoryName" + 'Description' = "Removing comment $Comment for $RepositoryName" 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -527,3 +563,48 @@ function Remove-GitHubComment } } +filter Add-GitHubCommentAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Comment objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. +#> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubCommentTypeName + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + $elements = Split-GitHubUri -Uri $item.html_url + $repositoryUrl = Join-GitHubUri @elements + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + + if ($null -ne $item.user) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.user + } + } + + Write-Output $item + } +} \ No newline at end of file From f6da52a5690ae4497d2502baff054e97deb14867 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 8 Jun 2020 17:19:38 -0700 Subject: [PATCH 23/80] * [BREAKING CHANGE] Changed signature for Get-GitHubUserContextualInformation to be more natural (and to work better with pipelining) * Added new pipeline-related tests to GitHubAssinees.tests.ps1 * Created GitHubUsers.tests.ps1 and added a number of new tests for Users. * Moved a number of unrelated tests out of GitHubAnalytics.tests.ps1 to existing or new files: * Some tests moved to GitHubRepositories.tests.ps1 * Moved `Split-GitHubUri` tests to GitHubCore.tests.ps1 * Also added some new ones * Some tests moved to a new GitHubBranches.tests.ps1 * Some tests moved to a new GitHubIssues.tests.ps1 --- GitHubRepositories.ps1 | 4 + GitHubUsers.ps1 | 88 ++++++-- Tests/GitHubAnalytics.tests.ps1 | 147 ++---------- Tests/GitHubAssignees.tests.ps1 | 116 ++++++++-- Tests/GitHubBranches.tests.ps1 | 40 ++++ Tests/GitHubCore.Tests.ps1 | 49 ++++ Tests/GitHubEvents.tests.ps1 | 100 ++++----- Tests/GitHubIssues.tests.ps1 | 130 +++++++++++ Tests/GitHubLabels.tests.ps1 | 350 ++++++++++++++--------------- Tests/GitHubReleases.tests.ps1 | 101 ++++----- Tests/GitHubRepositories.tests.ps1 | 51 +++++ Tests/GitHubUsers.tests.ps1 | 139 ++++++++++++ 12 files changed, 878 insertions(+), 437 deletions(-) create mode 100644 Tests/GitHubBranches.tests.ps1 create mode 100644 Tests/GitHubIssues.tests.ps1 create mode 100644 Tests/GitHubUsers.tests.ps1 diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index a272eb5a..98583c60 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -113,8 +113,10 @@ filter New-GitHubRepository Mandatory, ValueFromPipeline)] [ValidateNotNullOrEmpty()] + [Alias('Name')] [string] $RepositoryName, + [Parameter(ValueFromPipelineByPropertyName)] [string] $OrganizationName, [string] $Description, @@ -1744,6 +1746,8 @@ filter Add-GitHubRepositoryAdditionalProperties Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force } + Add-Member -InputObject $item -Name 'RepositoryId' -Value $item.id -MemberType NoteProperty -Force + if ($null -ne $item.owner) { $null = Add-GitHubUserAdditionalProperties -InputObject $item.owner diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 9f46d58c..f1e891ce 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -124,11 +124,23 @@ filter Get-GitHubUserContextualInformation .PARAMETER User The GitHub user to retrieve information for. - .PARAMETER Subject - Identifies which additional information to receive about the user's hovercard. + .PARAMETER OrganizationId + The ID of an Organization. When provided, this returns back the context for the user + in relation to this Organization. - .PARAMETER SubjectId - The ID for the Subject. Required when Subject has been specified. + .PARAMETER RepositoryId + The ID for a Repository. When provided, this returns back the context for the user + in relation to this Repository. + + .PARAMETER IssueId + The ID for a Issue. When provided, this returns back the context for the user + in relation to this Issue. + NOTE: This is the *id* of the issue and not the issue *number*. + + .PARAMETER PullRequestId + The ID for a PullRequest. When provided, this returns back the context for the user + in relation to this Pull Request. + NOTE: This is the *id* of the pull request and not the pull request *number*. .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the @@ -147,9 +159,15 @@ filter Get-GitHubUserContextualInformation Get-GitHubUserContextualInformation -User octocat .EXAMPLE - Get-GitHubUserContextualInformation -User octocat -Subject Repository -SubjectId 1300192 + Get-GitHubUserContextualInformation -User octocat -RepositoryId 1300192 + + .EXAMPLE + Get-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 70 | + Get-GitHubUserContextualInformation -User octocat #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding( + SupportsShouldProcess, + DefaultParameterSetName='NoContext')] [OutputType({$script:GitHubUserContextualInformationTypeName})] [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.")] @@ -161,10 +179,29 @@ filter Get-GitHubUserContextualInformation [Alias('UserName')] [string] $User, - [ValidateSet('Organization', 'Repository', 'Issue', 'PullRequest')] - [string] $Subject, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Organization')] + [int64] $OrganizationId, + + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Repository')] + [int64] $RepositoryId, + + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Issue')] + [int64] $IssueId, - [string] $SubjectId, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='PullRequest')] + [int64] $PullRequestId, [string] $AccessToken, @@ -175,25 +212,28 @@ filter Get-GitHubUserContextualInformation $getParams = @() - # Intentionally not using -xor here because we need to know if we're setting the GET parameters as well. - if ((-not [String]::IsNullOrEmpty($Subject)) -or (-not [String]::IsNullOrEmpty($SubjectId))) + if ($PSCmdlet.ParameterSetName -ne 'NoContext') { - if ([String]::IsNullOrEmpty($Subject) -or [String]::IsNullOrEmpty($SubjectId)) + if ($PSCmdlet.ParameterSetName -eq 'Organization') { - $message = 'If either Subject or SubjectId has been provided, then BOTH must be provided.' - Write-Log -Message $message -Level Error - throw $message + $getParams += 'subject_type=organization' + $getParams += "subject_id=$OrganizationId" } - - $subjectConverter = @{ - 'Organization' = 'organization' - 'Repository' = 'repository' - 'Issue' = 'issue' - 'PullRequest' = 'pull_request' + elseif ($PSCmdlet.ParameterSetName -eq 'Repository') + { + $getParams += 'subject_type=repository' + $getParams += "subject_id=$RepositoryId" + } + elseif ($PSCmdlet.ParameterSetName -eq 'Issue') + { + $getParams += 'subject_type=issue' + $getParams += "subject_id=$IssueId" + } + elseif ($PSCmdlet.ParameterSetName -eq 'PullRequest') + { + $getParams += 'subject_type=pull_request' + $getParams += "subject_id=$PullRequestId" } - - $getParams += "subject_type=$($subjectConverter[$Subject])" - $getParams += "subject_id=$SubjectId" } $params = @{ diff --git a/Tests/GitHubAnalytics.tests.ps1 b/Tests/GitHubAnalytics.tests.ps1 index df62e4f5..df2c7756 100644 --- a/Tests/GitHubAnalytics.tests.ps1 +++ b/Tests/GitHubAnalytics.tests.ps1 @@ -12,6 +12,7 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { +<<<<<<< HEAD Describe 'Obtaining issues for repository' { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit @@ -102,6 +103,8 @@ try } +======= +>>>>>>> 89bfa42... * [BREAKING CHANGE] Changed signature for Get-GitHubUserContextualInformation to be more natural # TODO: Re-enable these tests once the module has sufficient support getting the repository into the # required state for testing, and to recover back to the original state at the conclusion of the test. @@ -178,135 +181,33 @@ try # } # } - if ($script:accessTokenConfigured) - { - Describe 'Obtaining collaborators for repository' { - $repositoryName = [guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit - $repositoryUrl = "https://github.com/$script:ownerName/$repositoryName" - - $collaborators = @(Get-GitHubRepositoryCollaborator -Uri $repositoryUrl) - - It 'Should return expected number of collaborators' { - $collaborators.Count | Should be 1 - } - - $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName -Confirm:$false - } - } - - Describe 'Obtaining contributors for repository' { - $repositoryName = [guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit - $repositoryUrl = "https://github.com/$script:ownerName/$repositoryName" - - $contributors = @(Get-GitHubRepositoryContributor -Uri $repositoryUrl -IncludeStatistics) - - It 'Should return expected number of contributors' { - $contributors.Count | Should be 1 - } - - $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName -Confirm:$false - } + # TODO: Re-enable these tests once the module has sufficient support getting the Organization + # and repository into the required state for testing, and to recover back to the original state + # at the conclusion of the test. - if ($script:accessTokenConfigured) - { - # TODO: Re-enable these tests once the module has sufficient support getting the Organization - # and repository into the required state for testing, and to recover back to the original state - # at the conclusion of the test. - - # Describe 'Obtaining organization members' { - # $members = Get-GitHubOrganizationMember -OrganizationName $script:organizationName - - # It 'Should return expected number of organization members' { - # @($members).Count | Should be 1 - # } - # } - - # Describe 'Obtaining organization teams' { - # $teams = Get-GitHubTeam -OrganizationName $script:organizationName + # Describe 'Obtaining organization members' { + # $members = Get-GitHubOrganizationMember -OrganizationName $script:organizationName - # It 'Should return expected number of organization teams' { - # @($teams).Count | Should be 2 - # } - # } - - # Describe 'Obtaining organization team members' { - # $members = Get-GitHubTeamMember -OrganizationName $script:organizationName -TeamName $script:organizationTeamName - - # It 'Should return expected number of organization team members' { - # @($members).Count | Should be 1 - # } - # } - } - - Describe 'Getting repositories from organization' { - $original = @(Get-GitHubRepository -OrganizationName $script:organizationName) - - $repo = New-GitHubRepository -RepositoryName ([guid]::NewGuid().Guid) -OrganizationName $script:organizationName - $current = @(Get-GitHubRepository -OrganizationName $script:organizationName) - - It 'Should return expected number of organization repositories' { - ($current.Count - $original.Count) | Should be 1 - } - - $null = Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false - } - - Describe 'Getting unique contributors from contributors array' { - $repositoryName = [guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit - - $contributors = @(Get-GitHubRepositoryContributor -OwnerName $script:ownerName -RepositoryName $repositoryName -IncludeStatistics) - - $uniqueContributors = $contributors | - Select-Object -ExpandProperty author | - Select-Object -ExpandProperty login -Unique - Sort-Object - - It 'Should return expected number of unique contributors' { - $uniqueContributors.Count | Should be 1 - } - - $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName -Confirm:$false - } - - Describe 'Getting repository name from url' { - $repositoryName = [guid]::NewGuid().Guid - $url = "https://github.com/$script:ownerName/$repositoryName" - $name = Split-GitHubUri -Uri $url -RepositoryName - - It 'Should return expected repository name' { - $name | Should be $repositoryName - } - } - - Describe 'Getting repository owner from url' { - $repositoryName = [guid]::NewGuid().Guid - $url = "https://github.com/$script:ownerName/$repositoryName" - $owner = Split-GitHubUri -Uri $url -OwnerName - - It 'Should return expected repository owner' { - $owner | Should be $script:ownerName - } - } - - Describe 'Getting branches for repository' { - $repositoryName = [guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit + # It 'Should return expected number of organization members' { + # @($members).Count | Should be 1 + # } + # } - $branches = @(Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName) + # Describe 'Obtaining organization teams' { + # $teams = Get-GitHubTeam -OrganizationName $script:organizationName - It 'Should return expected number of repository branches' { - $branches.Count | Should be 1 - } + # It 'Should return expected number of organization teams' { + # @($teams).Count | Should be 2 + # } + # } - It 'Should return the name of the branches' { - $branches[0].name | Should be 'master' - } + # Describe 'Obtaining organization team members' { + # $members = Get-GitHubTeamMember -OrganizationName $script:organizationName -TeamName $script:organizationTeamName - $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName -Confirm:$false - } + # It 'Should return expected number of organization team members' { + # @($members).Count | Should be 1 + # } + # } } finally { diff --git a/Tests/GitHubAssignees.tests.ps1 b/Tests/GitHubAssignees.tests.ps1 index 5e4738d5..fb5ccadd 100644 --- a/Tests/GitHubAssignees.tests.ps1 +++ b/Tests/GitHubAssignees.tests.ps1 @@ -12,13 +12,21 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - $issue = New-GitHubIssue -Uri $repo.svn_url -Title "Test issue" - Describe 'Getting a valid assignee' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + $issue = New-GitHubIssue -Uri $repo.RepositoryUrl -Title "Test issue" + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $issue = $issue + } + + AfterAll { + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } Context 'For getting a valid assignee' { - $assigneeList = @(Get-GitHubAssignee -Uri $repo.svn_url) + $assigneeList = @(Get-GitHubAssignee -Uri $repo.RepositoryUrl) It 'Should have returned the one assignee' { $assigneeList.Count | Should be 1 @@ -30,7 +38,7 @@ try $assigneeUserName | Should not be $null } - $hasPermission = Test-GitHubAssignee -Uri $repo.svn_url -Assignee $assigneeUserName + $hasPermission = Test-GitHubAssignee -Uri $repo.RepositoryUrl -Assignee $assigneeUserName It 'Should have returned an assignee with permission to be assigned to an issue'{ $hasPermission | Should be $true @@ -40,20 +48,30 @@ try } Describe 'Adding and removing an assignee to an issue'{ + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + $issue = New-GitHubIssue -Uri $repo.RepositoryUrl -Title "Test issue" + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $issue = $issue + } + + AfterAll { + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } Context 'For adding an assignee to an issue'{ - $assigneeList = @(Get-GitHubAssignee -Uri $repo.svn_url) - $assigneeUserName = $assigneeList[0].login - $assignees = $assigneeUserName - New-GithubAssignee -Uri $repo.svn_url -Issue $issue.number -Assignee $assignees - $issue = Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number + $assigneeList = @(Get-GitHubAssignee -Uri $repo.RepositoryUrl) + $assignees = $assigneeList[0].UserName + $null = New-GithubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Assignee $assignees + $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.number It 'Should have assigned the user to the issue' { $issue.assignee.login | Should be $assigneeUserName } - Remove-GithubAssignee -Uri $repo.svn_url -Issue $issue.number -Assignee $assignees -Confirm:$false - $issue = Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number + Remove-GithubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Assignee $assignees -Confirm:$false + $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.number It 'Should have removed the user from issue' { $issue.assignees.Count | Should be 0 @@ -61,7 +79,79 @@ try } } - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + Describe 'Adding and removing an assignee to an issue via the pipeline'{ + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $repo = $repo + } + + BeforeEach { + $issue = New-GitHubIssue -Uri $repo.RepositoryUrl -Title "Test issue" + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $issue = $issue + } + + AfterAll { + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } + + Context 'For adding an assignee to an issue - pipe in the repo'{ + $assigneeList = @($repo | Get-GitHubAssignee) + $assignees = $assigneeList[0].UserName + $null = $repo | New-GithubAssignee -Issue $issue.IssueNumber -Assignee $assignees + $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.number + + It 'Should have assigned the user to the issue' { + $issue.assignee.UserName | Should be $assigneeUserName + } + + $repo | Remove-GithubAssignee -Issue $issue.IssueNumber -Assignee $assignees -Confirm:$false + $issue = $repo | Get-GitHubIssue -Issue $issue.IssueNumber + + It 'Should have removed the user from issue' { + $issue.assignees.Count | Should be 0 + } + } + + Context 'For adding an assignee to an issue - pipe in the issue'{ + $assigneeList = @(Get-GitHubAssignee -Uri $repo.RepositoryUrl) + $assignees = $assigneeList[0].UserName + $null = $issue | New-GithubAssignee -Assignee $assignees + $issue = $issue | Get-GitHubIssue + + It 'Should have assigned the user to the issue' { + $issue.assignee.UserName | Should be $assigneeUserName + } + + $issue | Remove-GithubAssignee -Assignee $assignees -Confirm:$false + $issue = $issue | Get-GitHubIssue + + It 'Should have removed the user from issue' { + $issue.assignees.Count | Should be 0 + } + } + + Context 'For adding an assignee to an issue - pipe in the assignee'{ + $assigneeList = @(Get-GitHubAssignee -Uri $repo.RepositoryUrl) + $assignees = $assigneeList[0].UserName + $null = $assignees | New-GithubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number + $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.IssueNumber + + It 'Should have assigned the user to the issue' { + $issue.assignee.UserName | Should be $assigneeUserName + } + + $assignees | Remove-GithubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Confirm:$false + $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.IssueNumber + + It 'Should have removed the user from issue' { + $issue.assignees.Count | Should be 0 + } + } + } } finally { diff --git a/Tests/GitHubBranches.tests.ps1 b/Tests/GitHubBranches.tests.ps1 new file mode 100644 index 00000000..cfb5cfc5 --- /dev/null +++ b/Tests/GitHubBranches.tests.ps1 @@ -0,0 +1,40 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Tests for GitHubBranches.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 +{ + Describe 'Getting branches for repository' { + $repositoryName = [guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit + + $branches = @(Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName) + + It 'Should return expected number of repository branches' { + $branches.Count | Should be 1 + } + + It 'Should return the name of the branches' { + $branches[0].name | Should be 'master' + } + + $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName -Confirm:$false + } +} +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 + } +} diff --git a/Tests/GitHubCore.Tests.ps1 b/Tests/GitHubCore.Tests.ps1 index 0fab5a3a..fffb4b66 100644 --- a/Tests/GitHubCore.Tests.ps1 +++ b/Tests/GitHubCore.Tests.ps1 @@ -195,6 +195,55 @@ try } } } + + Describe 'Testing Split-GitHubUri' { + BeforeAll { + $repositoryName = [guid]::NewGuid().Guid + $url = "https://github.com/$script:ownerName/$repositoryName" + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $repositoryName = $repositoryName + $url = $url + } + + Context 'For getting the OwnerName' { + It 'Should return expected repository name' { + $name = Split-GitHubUri -Uri $url -RepositoryName + $name | Should be $repositoryName + } + + It 'Should return expected repository name with the pipeline' { + $name = $url | Split-GitHubUri -RepositoryName + $name | Should be $repositoryName + } + } + + Context 'For getting the RepositoryName' { + It 'Should return expected owner name' { + $name = Split-GitHubUri -Uri $url -OwnerName + $name | Should be $script:ownerName + } + + It 'Should return expected owner name with the pipeline' { + $owner = $url | Split-GitHubUri -OwnerName + $owner | Should be $script:ownerName + } + } + + Context 'For getting both the OwnerName and the RepositoryName' { + It 'Should return both OwnerName and RepositoryName' { + $elements = Split-GitHubUri -Uri $url + $elements.ownerName | Should be $script:ownerName + $elements.repositoryName | Should be $repositoryName + } + + It 'Should return both OwnerName and RepositoryName with the pipeline' { + $elements = $url | Split-GitHubUri + $elements.ownerName | Should be $script:ownerName + $elements.repositoryName | Should be $repositoryName + } + } + } } finally { diff --git a/Tests/GitHubEvents.tests.ps1 b/Tests/GitHubEvents.tests.ps1 index 4411d640..048ea9e7 100644 --- a/Tests/GitHubEvents.tests.ps1 +++ b/Tests/GitHubEvents.tests.ps1 @@ -12,78 +12,78 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { - if ($accessTokenConfigured) - { - Describe 'Getting events from repository' { - $repositoryName = [Guid]::NewGuid() - $null = New-GitHubRepository -RepositoryName $repositoryName + # All of these tests will fail without authentication. Let's just avoid the failures. + if (-not $accessTokenConfigured) { return } + + Describe 'Getting events from repository' { + $repositoryName = [Guid]::NewGuid() + $null = New-GitHubRepository -RepositoryName $repositoryName - Context 'For getting events from a new repository' { - $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) + Context 'For getting events from a new repository' { + $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) - It 'Should have no events' { - $events.Count | Should be 0 - } + It 'Should have no events' { + $events.Count | Should be 0 } + } - $issue = New-GithubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" - Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed + $issue = New-GithubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" + Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed - Context 'For getting events from a repository' { - $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) + Context 'For getting events from a repository' { + $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) - It 'Should have an event from closing an issue' { - $events.Count | Should be 1 - } + It 'Should have an event from closing an issue' { + $events.Count | Should be 1 } - - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false } - Describe 'Getting events from an issue' { - $repositoryName = [Guid]::NewGuid() - $null = New-GitHubRepository -RepositoryName $repositoryName - $issue = New-GithubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" - - Context 'For getting events from a new issue' { - $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) + $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + } - It 'Should have no events' { - $events.Count | Should be 0 - } - } + Describe 'Getting events from an issue' { + $repositoryName = [Guid]::NewGuid() + $null = New-GitHubRepository -RepositoryName $repositoryName + $issue = New-GithubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" - Context 'For getting events from an issue' { - Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed - Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Open - $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) + Context 'For getting events from a new issue' { + $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) - It 'Should have two events from closing and opening the issue' { - $events.Count | Should be 2 - } + It 'Should have no events' { + $events.Count | Should be 0 } - - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false } - Describe 'Getting an event directly' { - $repositoryName = [Guid]::NewGuid() - $null = New-GitHubRepository -RepositoryName $repositoryName - $issue = New-GithubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" + Context 'For getting events from an issue' { Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Open $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) - Context 'For getting an event directly'{ - $singleEvent = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -EventID $events[0].id - - It 'Should have the correct event type'{ - $singleEvent.event | Should be 'reopened' - } + It 'Should have two events from closing and opening the issue' { + $events.Count | Should be 2 } + } + + $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + Describe 'Getting an event directly' { + $repositoryName = [Guid]::NewGuid() + $null = New-GitHubRepository -RepositoryName $repositoryName + $issue = New-GithubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" + Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed + Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Open + $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) + + Context 'For getting an event directly'{ + $singleEvent = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -EventID $events[0].id + + It 'Should have the correct event type'{ + $singleEvent.event | Should be 'reopened' + } } + + $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false } } finally diff --git a/Tests/GitHubIssues.tests.ps1 b/Tests/GitHubIssues.tests.ps1 new file mode 100644 index 00000000..18353aaf --- /dev/null +++ b/Tests/GitHubIssues.tests.ps1 @@ -0,0 +1,130 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Tests for GitHubIssues.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 +{ + # All of these tests will fail without authentication. Let's just avoid the failures. + if (-not $accessTokenConfigured) { return } + + Describe 'Obtaining issues for repository' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $repo = $repo + } + + AfterAll { + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } + + Context 'When initially created, there are no issues' { + $issues = @(Get-GitHubIssue -Uri $repo.svn_url) + + It 'Should return expected number of issues' { + $issues.Count | Should be 0 + } + } + + Context 'When there are issues present' { + $newIssues = @() + for ($i = 0; $i -lt 4; $i++) + { + $newIssues += New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid().Guid) + } + + $newIssues[0] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[0].number -State Closed + $newIssues[-1] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[-1].number -State Closed + + $issues = @(Get-GitHubIssue -Uri $repo.svn_url) + It 'Should return only open issues' { + $issues.Count | Should be 2 + } + + $issues = @(Get-GitHubIssue -Uri $repo.svn_url -State All) + It 'Should return all issues' { + $issues.Count | Should be 4 + } + + $createdOnOrAfterDate = Get-Date -Date $newIssues[0].created_at + $createdOnOrBeforeDate = Get-Date -Date $newIssues[2].created_at + $issues = @((Get-GitHubIssue -Uri $repo.svn_url) | Where-Object { ($_.created_at -ge $createdOnOrAfterDate) -and ($_.created_at -le $createdOnOrBeforeDate) }) + + It 'Smart object date conversion works for comparing dates' { + $issues.Count | Should be 2 + } + + $createdDate = Get-Date -Date $newIssues[1].created_at + $issues = @(Get-GitHubIssue -Uri $repo.svn_url -State All | Where-Object { ($_.created_at -ge $createdDate) -and ($_.state -eq 'closed') }) + + It 'Able to filter based on date and state' { + $issues.Count | Should be 1 + } + } + + Context 'When issues are retrieved with a specific MediaTypes' { + $newIssue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid()) -Body ([guid]::NewGuid()) + + $issues = @(Get-GitHubIssue -Uri $repo.svn_url -Issue $newIssue.number -MediaType 'Html') + It 'Should return an issue with body_html' { + $issues[0].body_html | Should not be $null + } + } + } + + Describe 'Obtaining repository with biggest number of issues' { + BeforeAll { + $repo1 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + $repo2 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $repo1 = $repo1 + $repo2 = $repo2 + } + + AfterAll { + Remove-GitHubRepository -Uri $repo1.RepositoryUrl -Confirm:$false + Remove-GitHubRepository -Uri $repo2.RepositoryUrl -Confirm:$false + } + + Context 'When no additional conditions specified' { + for ($i = 0; $i -lt 3; $i++) + { + $null = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo1.name -Title ([guid]::NewGuid().Guid) + } + + $repos = @(($repo1.svn_url), ($repo2.svn_url)) + $issueCounts = @() + $repos | ForEach-Object { $issueCounts = $issueCounts + ([PSCustomObject]@{ 'Uri' = $_; 'Count' = (Get-GitHubIssue -Uri $_).Count }) } + $issueCounts = $issueCounts | Sort-Object -Property Count -Descending + + It 'Should return expected number of issues for each repository' { + $issueCounts[0].Count | Should be 3 + $issueCounts[1].Count | Should be 0 + } + + It 'Should return expected repository names' { + $issueCounts[0].Uri | Should be $repo1.svn_url + $issueCounts[1].Uri | Should be $repo2.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 + } +} diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index 1de571dc..9818d7d3 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -12,6 +12,9 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { + # All of these tests will fail without authentication. Let's just avoid the failures. + if (-not $accessTokenConfigured) { return } + $defaultLabels = @( @{ 'name' = 'pri:lowest' @@ -71,256 +74,253 @@ try } ) - if ($accessTokenConfigured) - { - Describe 'Getting labels from repository' { - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName - Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels + Describe 'Getting labels from repository' { + $repositoryName = [Guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName + Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels - Context 'When querying for all labels' { - $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) + Context 'When querying for all labels' { + $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) - It 'Should return expected number of labels' { - $labels.Count | Should be $:defaultLabels.Count - } + It 'Should return expected number of labels' { + $labels.Count | Should be $:defaultLabels.Count } + } - Context 'When querying for specific label' { - $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name bug + Context 'When querying for specific label' { + $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name bug - It 'Should return expected label' { - $label.name | Should be "bug" - } + It 'Should return expected label' { + $label.name | Should be "bug" } - - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false } - Describe 'Creating new label' { - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName + $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + } - $labelName = [Guid]::NewGuid().Guid - New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB - $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName + Describe 'Creating new label' { + $repositoryName = [Guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName - It 'New label should be created' { - $label.name | Should be $labelName - } + $labelName = [Guid]::NewGuid().Guid + New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB + $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName - AfterEach { - Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Confirm:$false - } + It 'New label should be created' { + $label.name | Should be $labelName + } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + AfterEach { + Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Confirm:$false } - Describe 'Removing label' { - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName - Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels + $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + } - $labelName = [Guid]::NewGuid().Guid - New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB - $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) + Describe 'Removing label' { + $repositoryName = [Guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName + Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels - It 'Should return increased number of labels' { - $labels.Count | Should be ($defaultLabels.Count + 1) - } + $labelName = [Guid]::NewGuid().Guid + New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB + $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) - Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Confirm:$false - $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) + It 'Should return increased number of labels' { + $labels.Count | Should be ($defaultLabels.Count + 1) + } - It 'Should return expected number of labels' { - $labels.Count | Should be $defaultLabels.Count - } + Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Confirm:$false + $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + It 'Should return expected number of labels' { + $labels.Count | Should be $defaultLabels.Count } - Describe 'Updating label' { - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName + $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + } - $labelName = [Guid]::NewGuid().Guid + Describe 'Updating label' { + $repositoryName = [Guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName - Context 'Updating label color' { - New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB - Update-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -NewName $labelName -Color AAAAAA - $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName + $labelName = [Guid]::NewGuid().Guid - AfterEach { - Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Confirm:$false - } + Context 'Updating label color' { + New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB + Update-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -NewName $labelName -Color AAAAAA + $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName - It 'Label should have different color' { - $label.color | Should be AAAAAA - } + AfterEach { + Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Confirm:$false } - Context 'Updating label name' { - $newLabelName = $labelName + "2" - New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB - Update-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -NewName $newLabelName -Color BBBBBB - $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $newLabelName + It 'Label should have different color' { + $label.color | Should be AAAAAA + } + } - AfterEach { - Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $newLabelName -Confirm:$false - } + Context 'Updating label name' { + $newLabelName = $labelName + "2" + New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB + Update-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -NewName $newLabelName -Color BBBBBB + $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $newLabelName - It 'Label should have different color' { - $label | Should not be $null - $label.color | Should be BBBBBB - } + AfterEach { + Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $newLabelName -Confirm:$false } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + It 'Label should have different color' { + $label | Should not be $null + $label.color | Should be BBBBBB + } } - Describe 'Applying set of labels on repository' { - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName + $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + } - $labelName = [Guid]::NewGuid().Guid - Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels + Describe 'Applying set of labels on repository' { + $repositoryName = [Guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName - # Add new label - New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB - $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) + $labelName = [Guid]::NewGuid().Guid + Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels - # Change color of existing label - Update-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "bug" -NewName "bug" -Color BBBBBB + # Add new label + New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB + $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) - # Remove one of approved labels" - Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "discussion" -Confirm:$false + # Change color of existing label + Update-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "bug" -NewName "bug" -Color BBBBBB - It 'Should return increased number of labels' { - $($labels).Count | Should be ($defaultLabels.Count + 1) - } + # Remove one of approved labels" + Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "discussion" -Confirm:$false - Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels - $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) + It 'Should return increased number of labels' { + $($labels).Count | Should be ($defaultLabels.Count + 1) + } - It 'Should return expected number of labels' { - $labels.Count | Should be $defaultLabels.Count - $bugLabel = $labels | Where-Object {$_.name -eq "bug"} - $bugLabel.color | Should be "fc2929" - } + Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels + $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + It 'Should return expected number of labels' { + $labels.Count | Should be $defaultLabels.Count + $bugLabel = $labels | Where-Object {$_.name -eq "bug"} + $bugLabel.color | Should be "fc2929" } - Describe 'Adding labels to an issue'{ - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName - Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels - - $issueName = [Guid]::NewGuid().Guid - $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName + $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + } - Context 'Adding labels to an issue' { - $labelsToAdd = @('pri:lowest', 'pri:low', 'pri:medium', 'pri:high', 'pri:highest', 'bug', 'duplicate', - 'enhancement', 'up for grabs', 'question', 'discussion', 'wontfix', 'in progress', 'ready') - $addedLabels = @(Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd) + Describe 'Adding labels to an issue'{ + $repositoryName = [Guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName + Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels - It 'Should return the number of labels that were just added' { - $addedLabels.Count | Should be $defaultLabels.Count - } + $issueName = [Guid]::NewGuid().Guid + $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName - $labelIssues = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number + Context 'Adding labels to an issue' { + $labelsToAdd = @('pri:lowest', 'pri:low', 'pri:medium', 'pri:high', 'pri:highest', 'bug', 'duplicate', + 'enhancement', 'up for grabs', 'question', 'discussion', 'wontfix', 'in progress', 'ready') + $addedLabels = @(Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd) - It 'Should return the number of labels that were just added from querying the issue again' { - $labelIssues.Count | Should be $defaultLabels.Count - } + It 'Should return the number of labels that were just added' { + $addedLabels.Count | Should be $defaultLabels.Count } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + $labelIssues = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number + + It 'Should return the number of labels that were just added from querying the issue again' { + $labelIssues.Count | Should be $defaultLabels.Count + } } - Describe 'Creating a new Issue with labels' { - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName - Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels + $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + } - $issueName = [Guid]::NewGuid().Guid - $issueLabels = @($defaultLabels[0].name, $defaultLabels[1].name) - $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName -Label $issueLabels + Describe 'Creating a new Issue with labels' { + $repositoryName = [Guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName + Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels - It 'Should return the number of labels that were just added' { - $issue.labels.Count | Should be $issueLabels.Count - } + $issueName = [Guid]::NewGuid().Guid + $issueLabels = @($defaultLabels[0].name, $defaultLabels[1].name) + $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName -Label $issueLabels - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + It 'Should return the number of labels that were just added' { + $issue.labels.Count | Should be $issueLabels.Count } - Describe 'Removing labels on an issue'{ - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName + $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + } - $issueName = [Guid]::NewGuid().Guid - $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName + Describe 'Removing labels on an issue' { + $repositoryName = [Guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName - $labelsToAdd = @('pri:lowest', 'pri:low', 'pri:medium', 'pri:high', 'pri:highest', 'bug', 'duplicate', - 'enhancement', 'up for grabs', 'question', 'discussion', 'wontfix', 'in progress', 'ready') - Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd - - Context 'For removing individual issues'{ - Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "discussion" -Issue $issue.number -Confirm:$false - Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "question" -Issue $issue.number -Force - Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "bug" -Issue $issue.number -Confirm:$false -Force - $labelIssues = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) - - It 'Should have removed three labels from the issue' { - $labelIssues.Count | Should be ($defaultLabels.Count - 3) - } - } + $issueName = [Guid]::NewGuid().Guid + $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName - Context 'For removing all issues'{ - Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -Confirm:$false - $labelIssues = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) + $labelsToAdd = @('pri:lowest', 'pri:low', 'pri:medium', 'pri:high', 'pri:highest', 'bug', 'duplicate', + 'enhancement', 'up for grabs', 'question', 'discussion', 'wontfix', 'in progress', 'ready') + Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd - It 'Should have removed all labels from the issue' { - $labelIssues.Count | Should be 0 - } + Context 'For removing individual issues'{ + Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "discussion" -Issue $issue.number -Confirm:$false + Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "question" -Issue $issue.number -Force + Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "bug" -Issue $issue.number -Confirm:$false -Force + $labelIssues = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) + + It 'Should have removed three labels from the issue' { + $labelIssues.Count | Should be ($defaultLabels.Count - 3) } + } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + Context 'For removing all issues'{ + Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -Confirm:$false + $labelIssues = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) + + It 'Should have removed all labels from the issue' { + $labelIssues.Count | Should be 0 + } } - Describe 'Replacing labels on an issue'{ - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName + $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + } - $issueName = [Guid]::NewGuid().Guid - $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName + Describe 'Replacing labels on an issue'{ + $repositoryName = [Guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName - $labelsToAdd = @('pri:lowest', 'pri:low', 'pri:medium', 'pri:high', 'pri:highest', 'bug', 'duplicate', - 'enhancement', 'up for grabs', 'question', 'discussion', 'wontfix', 'in progress', 'ready') + $issueName = [Guid]::NewGuid().Guid + $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName - Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName 'pri:medium' + $labelsToAdd = @('pri:lowest', 'pri:low', 'pri:medium', 'pri:high', 'pri:highest', 'bug', 'duplicate', + 'enhancement', 'up for grabs', 'question', 'discussion', 'wontfix', 'in progress', 'ready') - $addedLabels = @(Set-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd) + Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName 'pri:medium' - It 'Should return the issue with 14 labels' { - $addedLabels.Count | Should be $labelsToAdd.Count - } + $addedLabels = @(Set-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd) - $labelIssues = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number + It 'Should return the issue with 14 labels' { + $addedLabels.Count | Should be $labelsToAdd.Count + } - It 'Should have 14 labels after querying the issue' { - $labelIssues.Count | Should be $defaultLabels.Count - } + $labelIssues = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number - $updatedIssueLabels = $labelsToAdd[0] - $updatedIssue = Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -Label $updatedIssueLabels + It 'Should have 14 labels after querying the issue' { + $labelIssues.Count | Should be $defaultLabels.Count + } - It 'Should have 1 label after updating the issue' { - $updatedIssue.labels.Count | Should be $updatedIssueLabels.Count - } + $updatedIssueLabels = $labelsToAdd[0] + $updatedIssue = Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -Label $updatedIssueLabels - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + It 'Should have 1 label after updating the issue' { + $updatedIssue.labels.Count | Should be $updatedIssueLabels.Count } + + $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false } } finally diff --git a/Tests/GitHubReleases.tests.ps1 b/Tests/GitHubReleases.tests.ps1 index 53d5ed31..79ebfe9b 100644 --- a/Tests/GitHubReleases.tests.ps1 +++ b/Tests/GitHubReleases.tests.ps1 @@ -12,77 +12,74 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { - if ($accessTokenConfigured) - { - Describe 'Getting releases from repository' { - $ownerName = "dotnet" - $repositoryName = "core" - $releases = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName) - - Context 'When getting all releases' { - It 'Should return multiple releases' { - $releases.Count | Should BeGreaterThan 1 - } + Describe 'Getting releases from repository' { + $ownerName = "dotnet" + $repositoryName = "core" + $releases = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName) + + Context 'When getting all releases' { + It 'Should return multiple releases' { + $releases.Count | Should BeGreaterThan 1 } + } - Context 'When getting the latest releases' { - $latest = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Latest) + Context 'When getting the latest releases' { + $latest = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Latest) - It 'Should return one value' { - $latest.Count | Should Be 1 - } + It 'Should return one value' { + $latest.Count | Should Be 1 + } - It 'Should return the first release from the full releases list' { - $latest[0].url | Should Be $releases[0].url - $latest[0].name | Should Be $releases[0].name - } + It 'Should return the first release from the full releases list' { + $latest[0].url | Should Be $releases[0].url + $latest[0].name | Should Be $releases[0].name } + } - Context 'When getting a specific release' { - $specificIndex = 5 - $specific = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -ReleaseId $releases[$specificIndex].id) + Context 'When getting a specific release' { + $specificIndex = 5 + $specific = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -ReleaseId $releases[$specificIndex].id) - It 'Should return one value' { - $specific.Count | Should Be 1 - } + It 'Should return one value' { + $specific.Count | Should Be 1 + } - It 'Should return the correct release' { - $specific.name | Should Be $releases[$specificIndex].name - } + It 'Should return the correct release' { + $specific.name | Should Be $releases[$specificIndex].name } + } - Context 'When getting a tagged release' { - $taggedIndex = 8 - $tagged = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Tag $releases[$taggedIndex].tag_name) + Context 'When getting a tagged release' { + $taggedIndex = 8 + $tagged = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Tag $releases[$taggedIndex].tag_name) - It 'Should return one value' { - $tagged.Count | Should Be 1 - } + It 'Should return one value' { + $tagged.Count | Should Be 1 + } - It 'Should return the correct release' { - $tagged.name | Should Be $releases[$taggedIndex].name - } + It 'Should return the correct release' { + $tagged.name | Should Be $releases[$taggedIndex].name } } + } - Describe 'Getting releases from default owner/repository' { - $originalOwnerName = Get-GitHubConfiguration -Name DefaultOwnerName - $originalRepositoryName = Get-GitHubConfiguration -Name DefaultRepositoryName + Describe 'Getting releases from default owner/repository' { + $originalOwnerName = Get-GitHubConfiguration -Name DefaultOwnerName + $originalRepositoryName = Get-GitHubConfiguration -Name DefaultRepositoryName - try { - Set-GitHubConfiguration -DefaultOwnerName "dotnet" - Set-GitHubConfiguration -DefaultRepositoryName "core" - $releases = @(Get-GitHubRelease) + try { + Set-GitHubConfiguration -DefaultOwnerName "dotnet" + Set-GitHubConfiguration -DefaultRepositoryName "core" + $releases = @(Get-GitHubRelease) - Context 'When getting all releases' { - It 'Should return multiple releases' { - $releases.Count | Should BeGreaterThan 1 - } + Context 'When getting all releases' { + It 'Should return multiple releases' { + $releases.Count | Should BeGreaterThan 1 } - } finally { - Set-GitHubConfiguration -DefaultOwnerName $originalOwnerName - Set-GitHubConfiguration -DefaultRepositoryName $originalRepositoryName } + } finally { + Set-GitHubConfiguration -DefaultOwnerName $originalOwnerName + Set-GitHubConfiguration -DefaultRepositoryName $originalRepositoryName } } } diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 598361f7..597d7607 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -620,6 +620,57 @@ try } } } + + Describe 'Contributors for a repository' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([guid]::NewGuid().Guid) -AutoInit + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $repo = $repo + } + + AfterAll { + $null = Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } + + Context -Name 'Obtaining contributors for repository' -Fixture { + $contributors = @(Get-GitHubRepositoryContributor -Uri $repo.RepositoryUrl -IncludeStatistics) + + It 'Should return expected number of contributors' { + $contributors.Count | Should be 1 + } + + It 'Should return expected number of unique contributors' { + $uniqueContributors = $contributors | + Select-Object -ExpandProperty author | + Select-Object -ExpandProperty login -Unique + Sort-Object + + $uniqueContributors.Count | Should be 1 + } + } + } + + Describe 'Collaborators for a repository' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([guid]::NewGuid().Guid) -AutoInit + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $repo = $repo + } + + AfterAll { + $null = Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } + + Context -Name 'Obtaining collaborators for repository' -Fixture { + $collaborators = @(Get-GitHubRepositoryCollaborator -Uri $repo.RepositoryUrl) + + It 'Should return expected number of collaborators' { + $collaborators.Count | Should be 1 + } + } + } } finally { diff --git a/Tests/GitHubUsers.tests.ps1 b/Tests/GitHubUsers.tests.ps1 new file mode 100644 index 00000000..d81ab953 --- /dev/null +++ b/Tests/GitHubUsers.tests.ps1 @@ -0,0 +1,139 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Tests for GitHubIssues.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 +{ + Describe 'Getting a user' { + Context 'Current user when additional properties are enabled' { + BeforeAll { + $currentUser = Get-GitHubUser -Current + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $currentUser = $currentUser + } + + It 'Should have the expected type and additional properties' { + $currentUser.UserName | Should -Be $currentUser.login + $currentUser.UserId | Should -Be $currentUser.id + $currentUser.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Current user when additional properties are disabled' { + BeforeAll { + Set-GitHubConfiguration -DisablePipelineSupport + $currentUser = Get-GitHubUser -Current + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $currentUser = $currentUser + } + + AfterAll { + Set-GitHubConfiguration -DisablePipelineSupport:$false + } + + It 'Should only have the expected type' { + $currentUser.UserName | Should -BeNullOrEmpty + $currentUser.UserId | Should -BeNullOrEmpty + $currentUser.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Specific user as a parameter' { + BeforeAll { + $user = Get-GitHubUser -User $script:ownerName + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $user = $user + } + + It 'Should have the expected type and additional properties' { + $user.UserName | Should -Be $user.login + $user.UserId | Should -Be $user.id + $user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Specific user with the pipeline' { + BeforeAll { + $user = $script:ownerName | Get-GitHubUser + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $user = $user + } + + It 'Should have the expected type and additional properties' { + $user.UserName | Should -Be $user.login + $user.UserId | Should -Be $user.id + $user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + } + + Describe 'Getting user context' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $repo = $repo + } + + AfterAll { + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } + + Context 'Checking context on a repo' { + It 'Should indicate ownership as a parameter' { + $context = Get-GitHubUserContextualInformation -User $script:ownerName -RepositoryId $repo.id + 'Owns this repository' | Should -BeIn $context.contexts.message + } + + It 'Should indicate ownership with the repo on the pipeline' { + $context = $repo | Get-GitHubUserContextualInformation -User $script:ownerName + 'Owns this repository' | Should -BeIn $context.contexts.message + } + + It 'Should indicate ownership with the username on the pipeline' { + $context = $script:ownerName | Get-GitHubUserContextualInformation -RepositoryId $repo.id + 'Owns this repository' | Should -BeIn $context.contexts.message + } + + It 'Should indicate ownership with the user on the pipeline' { + $user = Get-GitHubUser -User $script:ownerName + $context = $user | Get-GitHubUserContextualInformation -RepositoryId $repo.id + 'Owns this repository' | Should -BeIn $context.contexts.message + } + } + + Context 'Checking context on an issue with the pipeline' { + $issue = New-GitHubIssue -Uri $repo.RepositoryUrl -Title ([guid]::NewGuid().Guid) + $context = $issue | Get-GitHubUserContextualInformation -User $script:ownerName + + It 'Should indicate the user created the issue' { + $context.contexts[0].octicon | Should -Be 'issue-opened' + } + + It 'Should indicate the user owns the repository' { + $context.contexts[1].message | Should -Be 'Owns this repository' + } + } + } +} +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 35ab96e408a44b956057580713d5ee4025e83b86 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 8 Jun 2020 22:07:15 -0700 Subject: [PATCH 24/80] Update Traffic and Forks tests --- Tests/GitHubRepositoryForks.tests.ps1 | 34 ++++++++- Tests/GitHubRepositoryTraffic.tests.ps1 | 98 ++++++++++++++++++------- 2 files changed, 103 insertions(+), 29 deletions(-) diff --git a/Tests/GitHubRepositoryForks.tests.ps1 b/Tests/GitHubRepositoryForks.tests.ps1 index c5267a20..2c83f60d 100644 --- a/Tests/GitHubRepositoryForks.tests.ps1 +++ b/Tests/GitHubRepositoryForks.tests.ps1 @@ -32,7 +32,7 @@ try } AfterAll { - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + $repo | Remove-GitHubRepository -Force } $newForks = @(Get-GitHubRepositoryFork -OwnerName $script:upstreamOwnerName -RepositoryName $script:upstreamRepositoryName -Sort Newest) @@ -43,6 +43,36 @@ try # think that there's an existing clone out there and so may name this one "...-1" $ourFork.full_name.StartsWith("$($script:ownerName)/$script:upstreamRepositoryName") | Should -BeTrue } + + It 'Should have the expected additional type and properties' { + $ourFork.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' + $ourFork.RepositoryId | Should -Be $ourFork.id + } + } + + Context 'When a new fork is created (with the pipeline)' { + BeforeAll { + $upstream = Get-GitHubRepository -OwnerName $script:upstreamOwnerName -RepositoryName $script:upstreamRepositoryName + $repo = $upstream | New-GitHubRepositoryFork + } + + AfterAll { + $repo | Remove-GitHubRepository -Force + } + + $newForks = @(Get-GitHubRepositoryFork -OwnerName $script:upstreamOwnerName -RepositoryName $script:upstreamRepositoryName -Sort Newest) + $ourFork = $newForks | Where-Object { $_.owner.login -eq $script:ownerName } + + It 'Should be in the list' { + # Doing this syntax, because due to odd timing with GitHub, it's possible it may + # think that there's an existing clone out there and so may name this one "...-1" + $ourFork.full_name.StartsWith("$($script:ownerName)/$script:upstreamRepositoryName") | Should -BeTrue + } + + It 'Should have the expected additional type and properties' { + ourFork.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' + ourFork.RepositoryId | Should -Be $ourFork.id + } } } @@ -53,7 +83,7 @@ try } AfterAll { - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + $repo | Remove-GitHubRepository -Force } $newForks = @(Get-GitHubRepositoryFork -OwnerName $script:upstreamOwnerName -RepositoryName $script:upstreamRepositoryName -Sort Newest) diff --git a/Tests/GitHubRepositoryTraffic.tests.ps1 b/Tests/GitHubRepositoryTraffic.tests.ps1 index ea542e19..6383565d 100644 --- a/Tests/GitHubRepositoryTraffic.tests.ps1 +++ b/Tests/GitHubRepositoryTraffic.tests.ps1 @@ -12,59 +12,103 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { - Describe 'Getting the referrer list' { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + Describe 'Testing the referrer traffic on a repository' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - Context 'When initially created, there are no referrers' { - $referrerList = Get-GitHubReferrerTraffic -Uri $repo.svn_url + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $repo = $repo + } + AfterAll { + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } + + Context 'When initially created, there are no referrers' { It 'Should return expected number of referrers' { - $referrerList.Count | Should be 0 + $traffic = Get-GitHubReferrerTraffic -Uri $repo.svn_url + $traffic.Count | Should -Be 0 } - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + It 'Should have the expected type (via pipeline)' { + $traffic = $repo | Get-GitHubReferrerTraffic + $traffic.PSObject.TypeNames[0] | Should -Be 'GitHub.ReferrerTraffic' + } } } - Describe 'Getting the popular content over the last 14 days' { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + Describe 'Testing the path traffic on a repository' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $repo = $repo + } - Context 'When initially created, there are is no popular content' { - $pathList = Get-GitHubPathTraffic -Uri $repo.svn_url + AfterAll { + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } - It 'Should return expected number of popular content' { - $pathList.Count | Should be 0 + Context 'Getting the popular content over the last 14 days' { + It 'Should have no traffic since it was just created' { + $traffic = Get-GitHubPathTraffic -Uri $repo.svn_url + $traffic.Count | Should -Be 0 } - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + It 'Should have the expected type (via pipeline)' { + $traffic = $repo | Get-GitHubPathTraffic + $traffic.PSObject.TypeNames[0] | Should -Be 'GitHub.PathTraffic' + } } } - Describe 'Getting the views over the last 14 days' { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + Describe 'Testing the view traffic on a repository' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - Context 'When initially created, there are no views' { - $viewList = Get-GitHubViewTraffic -Uri $repo.svn_url + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $repo = $repo + } - It 'Should return 0 in the count property' { - $viewList.Count | Should be 0 + AfterAll { + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } + + Context 'Getting the views over the last 14 days' { + It 'Should have no traffic since it was just created' { + $traffic = Get-GitHubViewTraffic -Uri $repo.svn_url + $traffic.Count | Should -Be 0 } - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + It 'Should have the expected type (via pipeline)' { + $traffic = $repo | Get-GitHubViewTraffic + $traffic.PSObject.TypeNames[0] | Should -Be 'GitHub.ViewTraffic' + } } } - Describe 'Getting the clones over the last 14 days' { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + Describe 'Testing the view traffic on a repository' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - Context 'When initially created, there is 0 clones' { - $cloneList = Get-GitHubCloneTraffic -Uri $repo.svn_url + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $repo = $repo + } + + AfterAll { + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } - It 'Should return expected number of clones' { - $cloneList.Count | Should be 0 + Context 'Getting the clones over the last 14 days' { + It 'Should have no clones since it was just created' { + $traffic = Get-GitHubCloneTraffic -Uri $repo.svn_url + $traffic.Count | Should -Be 0 } - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + It 'Should have the expected type (via pipeline)' { + $traffic = $repo | Get-GitHubCloneTraffic + $traffic.PSObject.TypeNames[0] | Should -Be 'GitHub.CloneTraffic' + } } } } From fef7aecaafa1440c16bd1dcd57d810280a7e1341 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 8 Jun 2020 22:07:31 -0700 Subject: [PATCH 25/80] Some Pester syntax cleanup --- Tests/GitHubAnalytics.tests.ps1 | 26 ++++---- Tests/GitHubAssignees.tests.ps1 | 22 +++---- Tests/GitHubBranches.tests.ps1 | 4 +- Tests/GitHubComments.tests.ps1 | 16 ++--- Tests/GitHubContents.tests.ps1 | 48 +++++++-------- Tests/GitHubCore.Tests.ps1 | 92 ++++++++++++++-------------- Tests/GitHubEvents.tests.ps1 | 10 +-- Tests/GitHubIssues.tests.ps1 | 20 +++--- Tests/GitHubLabels.tests.ps1 | 38 ++++++------ Tests/GitHubMilestones.tests.ps1 | 32 +++++----- Tests/GitHubProjectCards.tests.ps1 | 42 ++++++------- Tests/GitHubProjectColumns.tests.ps1 | 24 ++++---- Tests/GitHubProjects.tests.ps1 | 80 ++++++++++++------------ Tests/GitHubReleases.tests.ps1 | 18 +++--- Tests/GitHubRepositories.tests.ps1 | 6 +- 15 files changed, 239 insertions(+), 239 deletions(-) diff --git a/Tests/GitHubAnalytics.tests.ps1 b/Tests/GitHubAnalytics.tests.ps1 index df2c7756..9282dddc 100644 --- a/Tests/GitHubAnalytics.tests.ps1 +++ b/Tests/GitHubAnalytics.tests.ps1 @@ -113,7 +113,7 @@ try # $pullRequests = Get-GitHubPullRequest -Uri $script:repositoryUrl # It 'Should return expected number of PRs' { - # @($pullRequests).Count | Should be 2 + # @($pullRequests).Count | Should -Be 2 # } # } @@ -124,7 +124,7 @@ try # Where-Object { ($_.merged_at -ge $mergedStartDate) -and ($_.merged_at -le $mergedEndDate) } # It 'Should return expected number of PRs' { - # @($pullRequests).Count | Should be 3 + # @($pullRequests).Count | Should -Be 3 # } # } # } @@ -139,13 +139,13 @@ try # $pullRequestCounts = $pullRequestCounts | Sort-Object -Property Count -Descending # It 'Should return expected number of pull requests for each repository' { - # @($pullRequestCounts[0].Count) | Should be 2 - # @($pullRequestCounts[1].Count) | Should be 0 + # @($pullRequestCounts[0].Count) | Should -Be 2 + # @($pullRequestCounts[1].Count) | Should -Be 0 # } # It 'Should return expected repository names' { - # @($pullRequestCounts[0].Uri) | Should be $script:repositoryUrl - # @($pullRequestCounts[1].Uri) | Should be $script:repositoryUrl2 + # @($pullRequestCounts[0].Uri) | Should -Be $script:repositoryUrl + # @($pullRequestCounts[1].Uri) | Should -Be $script:repositoryUrl2 # } # } @@ -170,13 +170,13 @@ try # $pullRequests = Get-GitHubTopPullRequestRepository -Uri @($script:repositoryUrl, $script:repositoryUrl2) -State Closed -MergedOnOrAfter # It 'Should return expected number of pull requests for each repository' { - # @($pullRequests[0].Count) | Should be 3 - # @($pullRequests[1].Count) | Should be 0 + # @($pullRequests[0].Count) | Should -Be 3 + # @($pullRequests[1].Count) | Should -Be 0 # } # It 'Should return expected repository names' { - # @($pullRequests[0].Uri) | Should be $script:repositoryUrl - # @($pullRequests[1].Uri) | Should be $script:repositoryUrl2 + # @($pullRequests[0].Uri) | Should -Be $script:repositoryUrl + # @($pullRequests[1].Uri) | Should -Be $script:repositoryUrl2 # } # } # } @@ -189,7 +189,7 @@ try # $members = Get-GitHubOrganizationMember -OrganizationName $script:organizationName # It 'Should return expected number of organization members' { - # @($members).Count | Should be 1 + # @($members).Count | Should -Be 1 # } # } @@ -197,7 +197,7 @@ try # $teams = Get-GitHubTeam -OrganizationName $script:organizationName # It 'Should return expected number of organization teams' { - # @($teams).Count | Should be 2 + # @($teams).Count | Should -Be 2 # } # } @@ -205,7 +205,7 @@ try # $members = Get-GitHubTeamMember -OrganizationName $script:organizationName -TeamName $script:organizationTeamName # It 'Should return expected number of organization team members' { - # @($members).Count | Should be 1 + # @($members).Count | Should -Be 1 # } # } } diff --git a/Tests/GitHubAssignees.tests.ps1 b/Tests/GitHubAssignees.tests.ps1 index fb5ccadd..d6b46954 100644 --- a/Tests/GitHubAssignees.tests.ps1 +++ b/Tests/GitHubAssignees.tests.ps1 @@ -29,19 +29,19 @@ try $assigneeList = @(Get-GitHubAssignee -Uri $repo.RepositoryUrl) It 'Should have returned the one assignee' { - $assigneeList.Count | Should be 1 + $assigneeList.Count | Should -Be 1 } $assigneeUserName = $assigneeList[0].login It 'Should have returned an assignee with a login'{ - $assigneeUserName | Should not be $null + $assigneeUserName | Should -Not -Be $null } $hasPermission = Test-GitHubAssignee -Uri $repo.RepositoryUrl -Assignee $assigneeUserName It 'Should have returned an assignee with permission to be assigned to an issue'{ - $hasPermission | Should be $true + $hasPermission | Should -Be $true } } @@ -67,14 +67,14 @@ try $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.number It 'Should have assigned the user to the issue' { - $issue.assignee.login | Should be $assigneeUserName + $issue.assignee.login | Should -Be $assigneeUserName } Remove-GithubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Assignee $assignees -Confirm:$false $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.number It 'Should have removed the user from issue' { - $issue.assignees.Count | Should be 0 + $issue.assignees.Count | Should -Be 0 } } } @@ -105,14 +105,14 @@ try $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.number It 'Should have assigned the user to the issue' { - $issue.assignee.UserName | Should be $assigneeUserName + $issue.assignee.UserName | Should -Be $assigneeUserName } $repo | Remove-GithubAssignee -Issue $issue.IssueNumber -Assignee $assignees -Confirm:$false $issue = $repo | Get-GitHubIssue -Issue $issue.IssueNumber It 'Should have removed the user from issue' { - $issue.assignees.Count | Should be 0 + $issue.assignees.Count | Should -Be 0 } } @@ -123,14 +123,14 @@ try $issue = $issue | Get-GitHubIssue It 'Should have assigned the user to the issue' { - $issue.assignee.UserName | Should be $assigneeUserName + $issue.assignee.UserName | Should -Be $assigneeUserName } $issue | Remove-GithubAssignee -Assignee $assignees -Confirm:$false $issue = $issue | Get-GitHubIssue It 'Should have removed the user from issue' { - $issue.assignees.Count | Should be 0 + $issue.assignees.Count | Should -Be 0 } } @@ -141,14 +141,14 @@ try $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.IssueNumber It 'Should have assigned the user to the issue' { - $issue.assignee.UserName | Should be $assigneeUserName + $issue.assignee.UserName | Should -Be $assigneeUserName } $assignees | Remove-GithubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Confirm:$false $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.IssueNumber It 'Should have removed the user from issue' { - $issue.assignees.Count | Should be 0 + $issue.assignees.Count | Should -Be 0 } } } diff --git a/Tests/GitHubBranches.tests.ps1 b/Tests/GitHubBranches.tests.ps1 index cfb5cfc5..2bf8b593 100644 --- a/Tests/GitHubBranches.tests.ps1 +++ b/Tests/GitHubBranches.tests.ps1 @@ -19,11 +19,11 @@ try $branches = @(Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName) It 'Should return expected number of repository branches' { - $branches.Count | Should be 1 + $branches.Count | Should -Be 1 } It 'Should return the name of the branches' { - $branches[0].name | Should be 'master' + $branches[0].name | Should -Be 'master' } $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName -Confirm:$false diff --git a/Tests/GitHubComments.tests.ps1 b/Tests/GitHubComments.tests.ps1 index 66c9242b..5525a538 100644 --- a/Tests/GitHubComments.tests.ps1 +++ b/Tests/GitHubComments.tests.ps1 @@ -31,7 +31,7 @@ try $existingComment = Get-GitHubComment -Uri $repo.svn_url -CommentID $newComment.id It "Should have the expected body text" { - $existingComment.body | Should be $defaultCommentBody + $existingComment.body | Should -Be $defaultCommentBody } } @@ -39,11 +39,11 @@ try $existingComments = @(Get-GitHubComment -Uri $repo.svn_url -Issue $issue.number) It 'Should have the expected number of comments' { - $existingComments.Count | Should be 1 + $existingComments.Count | Should -Be 1 } It 'Should have the expected body text on the first comment' { - $existingComments[0].body | Should be $defaultCommentBody + $existingComments[0].body | Should -Be $defaultCommentBody } } @@ -51,7 +51,7 @@ try $existingComments = @(Get-GitHubComment -Uri $repo.svn_url -Issue $issue.number -MediaType 'Html') It 'Should have the expected body_html on the first comment' { - $existingComments[0].body_html | Should not be $null + $existingComments[0].body_html | Should -Not -Be $null } } @@ -60,11 +60,11 @@ try $editedComment = Set-GitHubComment -Uri $repo.svn_url -CommentID $newComment.id -Body $defaultEditedCommentBody It 'Should have a body that is not equal to the original body' { - $editedComment.body | Should not be $newComment.Body + $editedComment.body | Should -Not -Be $newComment.Body } It 'Should have the edited content' { - $editedComment.body | Should be $defaultEditedCommentBody + $editedComment.body | Should -Be $defaultEditedCommentBody } } @@ -72,7 +72,7 @@ try $existingComments = @(Get-GitHubComment -Uri $repo.svn_url) It 'Should have the expected number of comments' { - $existingComments.Count | Should be 2 + $existingComments.Count | Should -Be 2 } foreach($comment in $existingComments) { @@ -82,7 +82,7 @@ try $existingComments = @(Get-GitHubComment -Uri $repo.svn_url) It 'Should have no comments' { - $existingComments.Count | Should be 0 + $existingComments.Count | Should -Be 0 } } diff --git a/Tests/GitHubContents.tests.ps1 b/Tests/GitHubContents.tests.ps1 index 7dbf568e..07c1090e 100644 --- a/Tests/GitHubContents.tests.ps1 +++ b/Tests/GitHubContents.tests.ps1 @@ -37,20 +37,20 @@ try $folderOutput = Get-GitHubContent -OwnerName $script:ownerName -RepositoryName $repo.name It "Should have the expected name" { - $folderOutput.name | Should be "" + $folderOutput.name | Should -Be "" } It "Should have the expected path" { - $folderOutput.path | Should be "" + $folderOutput.path | Should -Be "" } It "Should have the expected type" { - $folderOutput.type | Should be "dir" + $folderOutput.type | Should -Be "dir" } It "Should have the expected entries" { - $folderOutput.entries.length | Should be 1 + $folderOutput.entries.length | Should -Be 1 } It "Should have the expected entry data" { - $folderOutput.entries[0].name | Should be $readmeFileName - $folderOutput.entries[0].path | Should be $readmeFileName + $folderOutput.entries[0].name | Should -Be $readmeFileName + $folderOutput.entries[0].path | Should -Be $readmeFileName } } @@ -59,20 +59,20 @@ try $folderOutput = Get-GitHubContent -Uri "https://github.com/$($script:ownerName)/$($repo.name)" It "Should have the expected name" { - $folderOutput.name | Should be "" + $folderOutput.name | Should -Be "" } It "Should have the expected path" { - $folderOutput.path | Should be "" + $folderOutput.path | Should -Be "" } It "Should have the expected type" { - $folderOutput.type | Should be "dir" + $folderOutput.type | Should -Be "dir" } It "Should have the expected entries" { - $folderOutput.entries.length | Should be 1 + $folderOutput.entries.length | Should -Be 1 } It "Should have the expected entry data" { - $folderOutput.entries[0].name | Should be $readmeFileName - $folderOutput.entries[0].path | Should be $readmeFileName + $folderOutput.entries[0].name | Should -Be $readmeFileName + $folderOutput.entries[0].path | Should -Be $readmeFileName } } @@ -82,7 +82,7 @@ try $readmeFileString = [System.Text.Encoding]::UTF8.GetString($readmeFileBytes) It "Should have the expected content" { - $readmeFileString | Should be $rawOutput + $readmeFileString | Should -Be $rawOutput } } @@ -91,7 +91,7 @@ try $readmeFileString = Get-GitHubContent -OwnerName $script:ownerName -RepositoryName $repo.name -Path $readmeFileName -MediaType Raw -ResultAsString It "Should have the expected content" { - $readmeFileString | Should be $rawOutput + $readmeFileString | Should -Be $rawOutput } } @@ -129,22 +129,22 @@ try $readmeFileObject = Get-GitHubContent -OwnerName $script:ownerName -RepositoryName $repo.name -Path $readmeFileName It "Should have the expected name" { - $readmeFileObject.name | Should be $readmeFileName + $readmeFileObject.name | Should -Be $readmeFileName } It "Should have the expected path" { - $readmeFileObject.path | Should be $readmeFileName + $readmeFileObject.path | Should -Be $readmeFileName } It "Should have the expected type" { - $readmeFileObject.type | Should be "file" + $readmeFileObject.type | Should -Be "file" } It "Should have the expected encoding" { - $readmeFileObject.encoding | Should be "base64" + $readmeFileObject.encoding | Should -Be "base64" } It "Should have the expected content" { # Convert from base64 $readmeFileString = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($readmeFileObject.content)) - $readmeFileString | Should be $rawOutput + $readmeFileString | Should -Be $rawOutput } } @@ -153,20 +153,20 @@ try $readmeFileObject = Get-GitHubContent -OwnerName $script:ownerName -RepositoryName $repo.name -Path $readmeFileName -MediaType Object -ResultAsString It "Should have the expected name" { - $readmeFileObject.name | Should be $readmeFileName + $readmeFileObject.name | Should -Be $readmeFileName } It "Should have the expected path" { - $readmeFileObject.path | Should be $readmeFileName + $readmeFileObject.path | Should -Be $readmeFileName } It "Should have the expected type" { - $readmeFileObject.type | Should be "file" + $readmeFileObject.type | Should -Be "file" } It "Should have the expected encoding" { - $readmeFileObject.encoding | Should be "base64" + $readmeFileObject.encoding | Should -Be "base64" } It "Should have the expected content" { - $readmeFileObject.contentAsString | Should be $rawOutput + $readmeFileObject.contentAsString | Should -Be $rawOutput } } diff --git a/Tests/GitHubCore.Tests.ps1 b/Tests/GitHubCore.Tests.ps1 index fffb4b66..f0b3f33a 100644 --- a/Tests/GitHubCore.Tests.ps1 +++ b/Tests/GitHubCore.Tests.ps1 @@ -28,7 +28,7 @@ try It 'Should return the same values' { $originalJson = (ConvertTo-Json -InputObject $original -Depth $jsonConversionDepth) $convertedJson = (ConvertTo-Json -InputObject $converted -Depth $jsonConversionDepth) - $originalJson -eq $convertedJson | Should be $true + $originalJson -eq $convertedJson | Should -Be $true } } @@ -48,7 +48,7 @@ try It 'Should return the correct values' { $originalJson = (ConvertTo-Json -InputObject $original -Depth $jsonConversionDepth) $convertedJson = (ConvertTo-Json -InputObject $converted -Depth $jsonConversionDepth) - $originalJson -eq $convertedJson | Should be $true + $originalJson -eq $convertedJson | Should -Be $true } } @@ -78,26 +78,26 @@ try $converted = ConvertTo-SmarterObject -InputObject $original It 'Should convert the value to a [DateTime]' { - $converted.closed_at -is [DateTime] | Should be $true - $converted.committed_at -is [DateTime] | Should be $true - $converted.completed_at -is [DateTime] | Should be $true - $converted.created_at -is [DateTime] | Should be $true - $converted.date -is [DateTime] | Should be $true - $converted.due_on -is [DateTime] | Should be $true - $converted.last_edited_at -is [DateTime] | Should be $true - $converted.last_read_at -is [DateTime] | Should be $true - $converted.merged_at -is [DateTime] | Should be $true - $converted.published_at -is [DateTime] | Should be $true - $converted.pushed_at -is [DateTime] | Should be $true - $converted.starred_at -is [DateTime] | Should be $true - $converted.started_at -is [DateTime] | Should be $true - $converted.submitted_at -is [DateTime] | Should be $true - $converted.timestamp -is [DateTime] | Should be $true - $converted.updated_at -is [DateTime] | Should be $true + $converted.closed_at -is [DateTime] | Should -Be $true + $converted.committed_at -is [DateTime] | Should -Be $true + $converted.completed_at -is [DateTime] | Should -Be $true + $converted.created_at -is [DateTime] | Should -Be $true + $converted.date -is [DateTime] | Should -Be $true + $converted.due_on -is [DateTime] | Should -Be $true + $converted.last_edited_at -is [DateTime] | Should -Be $true + $converted.last_read_at -is [DateTime] | Should -Be $true + $converted.merged_at -is [DateTime] | Should -Be $true + $converted.published_at -is [DateTime] | Should -Be $true + $converted.pushed_at -is [DateTime] | Should -Be $true + $converted.starred_at -is [DateTime] | Should -Be $true + $converted.started_at -is [DateTime] | Should -Be $true + $converted.submitted_at -is [DateTime] | Should -Be $true + $converted.timestamp -is [DateTime] | Should -Be $true + $converted.updated_at -is [DateTime] | Should -Be $true } It 'Should NOT convert the value to a [DateTime] if it''s not a known property' { - $converted.prop1 -is [DateTime] | Should be $false + $converted.prop1 -is [DateTime] | Should -Be $false } } @@ -124,22 +124,22 @@ try $converted = ConvertTo-SmarterObject -InputObject $original It 'Should keep the existing value' { - $original.closed_at -eq $converted.closed_at | Should be $true - $original.committed_at -eq $converted.committed_at | Should be $true - $original.completed_at -eq $converted.completed_at | Should be $true - $original.created_at -eq $converted.created_at | Should be $true - $original.date -eq $converted.date | Should be $true - $original.due_on -eq $converted.due_on | Should be $true - $original.last_edited_at -eq $converted.last_edited_at | Should be $true - $original.last_read_at -eq $converted.last_read_at | Should be $true - $original.merged_at -eq $converted.merged_at | Should be $true - $original.published_at -eq $converted.published_at | Should be $true - $original.pushed_at -eq $converted.pushed_at | Should be $true - $original.starred_at -eq $converted.starred_at | Should be $true - $original.started_at -eq $converted.started_at | Should be $true - $original.submitted_at -eq $converted.submitted_at | Should be $true - $original.timestamp -eq $converted.timestamp | Should be $true - $original.updated_at -eq $converted.updated_at | Should be $true + $original.closed_at -eq $converted.closed_at | Should -Be $true + $original.committed_at -eq $converted.committed_at | Should -Be $true + $original.completed_at -eq $converted.completed_at | Should -Be $true + $original.created_at -eq $converted.created_at | Should -Be $true + $original.date -eq $converted.date | Should -Be $true + $original.due_on -eq $converted.due_on | Should -Be $true + $original.last_edited_at -eq $converted.last_edited_at | Should -Be $true + $original.last_read_at -eq $converted.last_read_at | Should -Be $true + $original.merged_at -eq $converted.merged_at | Should -Be $true + $original.published_at -eq $converted.published_at | Should -Be $true + $original.pushed_at -eq $converted.pushed_at | Should -Be $true + $original.starred_at -eq $converted.starred_at | Should -Be $true + $original.started_at -eq $converted.started_at | Should -Be $true + $original.submitted_at -eq $converted.submitted_at | Should -Be $true + $original.timestamp -eq $converted.timestamp | Should -Be $true + $original.updated_at -eq $converted.updated_at | Should -Be $true } } @@ -156,7 +156,7 @@ try It 'Should still be an empty array after conversion' { $originalJson = (ConvertTo-Json -InputObject $original -Depth $jsonConversionDepth) $convertedJson = (ConvertTo-Json -InputObject $converted -Depth $jsonConversionDepth) - $originalJson -eq $convertedJson | Should be $true + $originalJson -eq $convertedJson | Should -Be $true } } @@ -173,7 +173,7 @@ try It 'Should still be a single item array after conversion' { $originalJson = (ConvertTo-Json -InputObject $original -Depth $jsonConversionDepth) $convertedJson = (ConvertTo-Json -InputObject $converted -Depth $jsonConversionDepth) - $originalJson -eq $convertedJson | Should be $true + $originalJson -eq $convertedJson | Should -Be $true } } @@ -190,7 +190,7 @@ try It 'Should still be a multi item array after conversion' { $originalJson = (ConvertTo-Json -InputObject $original -Depth $jsonConversionDepth) $convertedJson = (ConvertTo-Json -InputObject $converted -Depth $jsonConversionDepth) - $originalJson -eq $convertedJson | Should be $true + $originalJson -eq $convertedJson | Should -Be $true } } } @@ -209,38 +209,38 @@ try Context 'For getting the OwnerName' { It 'Should return expected repository name' { $name = Split-GitHubUri -Uri $url -RepositoryName - $name | Should be $repositoryName + $name | Should -Be $repositoryName } It 'Should return expected repository name with the pipeline' { $name = $url | Split-GitHubUri -RepositoryName - $name | Should be $repositoryName + $name | Should -Be $repositoryName } } Context 'For getting the RepositoryName' { It 'Should return expected owner name' { $name = Split-GitHubUri -Uri $url -OwnerName - $name | Should be $script:ownerName + $name | Should -Be $script:ownerName } It 'Should return expected owner name with the pipeline' { $owner = $url | Split-GitHubUri -OwnerName - $owner | Should be $script:ownerName + $owner | Should -Be $script:ownerName } } Context 'For getting both the OwnerName and the RepositoryName' { It 'Should return both OwnerName and RepositoryName' { $elements = Split-GitHubUri -Uri $url - $elements.ownerName | Should be $script:ownerName - $elements.repositoryName | Should be $repositoryName + $elements.ownerName | Should -Be $script:ownerName + $elements.repositoryName | Should -Be $repositoryName } It 'Should return both OwnerName and RepositoryName with the pipeline' { $elements = $url | Split-GitHubUri - $elements.ownerName | Should be $script:ownerName - $elements.repositoryName | Should be $repositoryName + $elements.ownerName | Should -Be $script:ownerName + $elements.repositoryName | Should -Be $repositoryName } } } diff --git a/Tests/GitHubEvents.tests.ps1 b/Tests/GitHubEvents.tests.ps1 index 048ea9e7..d9337103 100644 --- a/Tests/GitHubEvents.tests.ps1 +++ b/Tests/GitHubEvents.tests.ps1 @@ -23,7 +23,7 @@ try $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should have no events' { - $events.Count | Should be 0 + $events.Count | Should -Be 0 } } @@ -34,7 +34,7 @@ try $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should have an event from closing an issue' { - $events.Count | Should be 1 + $events.Count | Should -Be 1 } } @@ -50,7 +50,7 @@ try $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) It 'Should have no events' { - $events.Count | Should be 0 + $events.Count | Should -Be 0 } } @@ -60,7 +60,7 @@ try $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should have two events from closing and opening the issue' { - $events.Count | Should be 2 + $events.Count | Should -Be 2 } } @@ -79,7 +79,7 @@ try $singleEvent = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -EventID $events[0].id It 'Should have the correct event type'{ - $singleEvent.event | Should be 'reopened' + $singleEvent.event | Should -Be 'reopened' } } diff --git a/Tests/GitHubIssues.tests.ps1 b/Tests/GitHubIssues.tests.ps1 index 18353aaf..3fe63a0d 100644 --- a/Tests/GitHubIssues.tests.ps1 +++ b/Tests/GitHubIssues.tests.ps1 @@ -31,7 +31,7 @@ try $issues = @(Get-GitHubIssue -Uri $repo.svn_url) It 'Should return expected number of issues' { - $issues.Count | Should be 0 + $issues.Count | Should -Be 0 } } @@ -47,12 +47,12 @@ try $issues = @(Get-GitHubIssue -Uri $repo.svn_url) It 'Should return only open issues' { - $issues.Count | Should be 2 + $issues.Count | Should -Be 2 } $issues = @(Get-GitHubIssue -Uri $repo.svn_url -State All) It 'Should return all issues' { - $issues.Count | Should be 4 + $issues.Count | Should -Be 4 } $createdOnOrAfterDate = Get-Date -Date $newIssues[0].created_at @@ -60,14 +60,14 @@ try $issues = @((Get-GitHubIssue -Uri $repo.svn_url) | Where-Object { ($_.created_at -ge $createdOnOrAfterDate) -and ($_.created_at -le $createdOnOrBeforeDate) }) It 'Smart object date conversion works for comparing dates' { - $issues.Count | Should be 2 + $issues.Count | Should -Be 2 } $createdDate = Get-Date -Date $newIssues[1].created_at $issues = @(Get-GitHubIssue -Uri $repo.svn_url -State All | Where-Object { ($_.created_at -ge $createdDate) -and ($_.state -eq 'closed') }) It 'Able to filter based on date and state' { - $issues.Count | Should be 1 + $issues.Count | Should -Be 1 } } @@ -76,7 +76,7 @@ try $issues = @(Get-GitHubIssue -Uri $repo.svn_url -Issue $newIssue.number -MediaType 'Html') It 'Should return an issue with body_html' { - $issues[0].body_html | Should not be $null + $issues[0].body_html | Should -Not -Be $null } } } @@ -108,13 +108,13 @@ try $issueCounts = $issueCounts | Sort-Object -Property Count -Descending It 'Should return expected number of issues for each repository' { - $issueCounts[0].Count | Should be 3 - $issueCounts[1].Count | Should be 0 + $issueCounts[0].Count | Should -Be 3 + $issueCounts[1].Count | Should -Be 0 } It 'Should return expected repository names' { - $issueCounts[0].Uri | Should be $repo1.svn_url - $issueCounts[1].Uri | Should be $repo2.svn_url + $issueCounts[0].Uri | Should -Be $repo1.svn_url + $issueCounts[1].Uri | Should -Be $repo2.svn_url } } } diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index 9818d7d3..e5630896 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -83,7 +83,7 @@ try $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should return expected number of labels' { - $labels.Count | Should be $:defaultLabels.Count + $labels.Count | Should -Be $:defaultLabels.Count } } @@ -91,7 +91,7 @@ try $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name bug It 'Should return expected label' { - $label.name | Should be "bug" + $label.name | Should -Be "bug" } } @@ -107,7 +107,7 @@ try $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName It 'New label should be created' { - $label.name | Should be $labelName + $label.name | Should -Be $labelName } AfterEach { @@ -127,14 +127,14 @@ try $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should return increased number of labels' { - $labels.Count | Should be ($defaultLabels.Count + 1) + $labels.Count | Should -Be ($defaultLabels.Count + 1) } Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Confirm:$false $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should return expected number of labels' { - $labels.Count | Should be $defaultLabels.Count + $labels.Count | Should -Be $defaultLabels.Count } $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false @@ -156,7 +156,7 @@ try } It 'Label should have different color' { - $label.color | Should be AAAAAA + $label.color | Should -Be AAAAAA } } @@ -171,8 +171,8 @@ try } It 'Label should have different color' { - $label | Should not be $null - $label.color | Should be BBBBBB + $label | Should -Not -Be $null + $label.color | Should -Be BBBBBB } } @@ -197,16 +197,16 @@ try Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "discussion" -Confirm:$false It 'Should return increased number of labels' { - $($labels).Count | Should be ($defaultLabels.Count + 1) + $($labels).Count | Should -Be ($defaultLabels.Count + 1) } Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should return expected number of labels' { - $labels.Count | Should be $defaultLabels.Count + $labels.Count | Should -Be $defaultLabels.Count $bugLabel = $labels | Where-Object {$_.name -eq "bug"} - $bugLabel.color | Should be "fc2929" + $bugLabel.color | Should -Be "fc2929" } $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false @@ -226,13 +226,13 @@ try $addedLabels = @(Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd) It 'Should return the number of labels that were just added' { - $addedLabels.Count | Should be $defaultLabels.Count + $addedLabels.Count | Should -Be $defaultLabels.Count } $labelIssues = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number It 'Should return the number of labels that were just added from querying the issue again' { - $labelIssues.Count | Should be $defaultLabels.Count + $labelIssues.Count | Should -Be $defaultLabels.Count } } @@ -249,7 +249,7 @@ try $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName -Label $issueLabels It 'Should return the number of labels that were just added' { - $issue.labels.Count | Should be $issueLabels.Count + $issue.labels.Count | Should -Be $issueLabels.Count } $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false @@ -273,7 +273,7 @@ try $labelIssues = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) It 'Should have removed three labels from the issue' { - $labelIssues.Count | Should be ($defaultLabels.Count - 3) + $labelIssues.Count | Should -Be ($defaultLabels.Count - 3) } } @@ -282,7 +282,7 @@ try $labelIssues = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) It 'Should have removed all labels from the issue' { - $labelIssues.Count | Should be 0 + $labelIssues.Count | Should -Be 0 } } @@ -304,20 +304,20 @@ try $addedLabels = @(Set-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd) It 'Should return the issue with 14 labels' { - $addedLabels.Count | Should be $labelsToAdd.Count + $addedLabels.Count | Should -Be $labelsToAdd.Count } $labelIssues = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number It 'Should have 14 labels after querying the issue' { - $labelIssues.Count | Should be $defaultLabels.Count + $labelIssues.Count | Should -Be $defaultLabels.Count } $updatedIssueLabels = $labelsToAdd[0] $updatedIssue = Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -Label $updatedIssueLabels It 'Should have 1 label after updating the issue' { - $updatedIssue.labels.Count | Should be $updatedIssueLabels.Count + $updatedIssue.labels.Count | Should -Be $updatedIssueLabels.Count } $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false diff --git a/Tests/GitHubMilestones.tests.ps1 b/Tests/GitHubMilestones.tests.ps1 index db9ab8cf..6c1c9033 100644 --- a/Tests/GitHubMilestones.tests.ps1 +++ b/Tests/GitHubMilestones.tests.ps1 @@ -40,29 +40,29 @@ try $newMilestoneDueOnLateEvening = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle3 -State "Closed" -DueOn $defaultMilestoneDueOn.date.AddHours(23) It "Should have the expected title text" { - $existingMilestone.title | Should be $defaultMilestoneTitle1 + $existingMilestone.title | Should -Be $defaultMilestoneTitle1 } It "Should have the expected state" { - $existingMilestone.state | Should be "closed" + $existingMilestone.state | Should -Be "closed" } It "Should have the expected due_on date" { # GitHub drops the time that is attached to 'due_on', so it's only relevant # to compare the dates against each other. - (Get-Date -Date $existingMilestone.due_on).Date | Should be $defaultMilestoneDueOn.Date + (Get-Date -Date $existingMilestone.due_on).Date | Should -Be $defaultMilestoneDueOn.Date } It "Should have the expected due_on date even if early morning" { # GitHub drops the time that is attached to 'due_on', so it's only relevant # to compare the dates against each other. - (Get-Date -Date $newMilestoneDueOnEarlyMorning.due_on).Date | Should be $defaultMilestoneDueOn.Date + (Get-Date -Date $newMilestoneDueOnEarlyMorning.due_on).Date | Should -Be $defaultMilestoneDueOn.Date } It "Should have the expected due_on date even if late evening" { # GitHub drops the time that is attached to 'due_on', so it's only relevant # to compare the dates against each other. - (Get-Date -Date $newMilestoneDueOnLateEvening.due_on).Date | Should be $defaultMilestoneDueOn.Date + (Get-Date -Date $newMilestoneDueOnLateEvening.due_on).Date | Should -Be $defaultMilestoneDueOn.Date } It "Should allow the addition of an existing issue" { @@ -75,16 +75,16 @@ try $issue = Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number It 'Should have the expected number of milestones' { - $existingMilestones.Count | Should be 3 + $existingMilestones.Count | Should -Be 3 } It 'Should have the expected title text on the first milestone' { - $existingMilestones[0].title | Should be $defaultMilestoneTitle1 + $existingMilestones[0].title | Should -Be $defaultMilestoneTitle1 } It 'Should have the expected issue in the first milestone' { - $existingMilestones[0].open_issues | should be 1 - $issue.milestone.number | Should be 1 + $existingMilestones[0].open_issues | Should -Be 1 + $issue.milestone.number | Should -Be 1 } } @@ -93,13 +93,13 @@ try $editedMilestone = Set-GitHubMilestone -Uri $repo.svn_url -Milestone $newMilestone.number -Title $defaultEditedMilestoneTitle -Description $defaultEditedMilestoneDescription It 'Should have a title/description that is not equal to the original title/description' { - $editedMilestone.title | Should not be $newMilestone.title - $editedMilestone.description | Should not be $newMilestone.description + $editedMilestone.title | Should -Not -Be $newMilestone.title + $editedMilestone.description | Should -Not -Be $newMilestone.description } It 'Should have the edited content' { - $editedMilestone.title | Should be $defaultEditedMilestoneTitle - $editedMilestone.description | Should be $defaultEditedMilestoneDescription + $editedMilestone.title | Should -Be $defaultEditedMilestoneTitle + $editedMilestone.description | Should -Be $defaultEditedMilestoneDescription } } @@ -107,7 +107,7 @@ try $existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url -State All -Sort Completeness -Direction Descending) It 'Should have the expected number of milestones' { - $existingMilestones.Count | Should be 4 + $existingMilestones.Count | Should -Be 4 } foreach($milestone in $existingMilestones) { @@ -118,8 +118,8 @@ try $issue = Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number It 'Should have no milestones' { - $existingMilestones.Count | Should be 0 - $issue.milestone | Should be $null + $existingMilestones.Count | Should -Be 0 + $issue.milestone | Should -Be $null } } diff --git a/Tests/GitHubProjectCards.tests.ps1 b/Tests/GitHubProjectCards.tests.ps1 index 7875f4e7..2854ee63 100644 --- a/Tests/GitHubProjectCards.tests.ps1 +++ b/Tests/GitHubProjectCards.tests.ps1 @@ -54,33 +54,33 @@ try Context 'Get cards for a column' { $results = @(Get-GitHubProjectCard -Column $column.id) It 'Should get cards' { - $results | Should Not BeNullOrEmpty + $results | Should -Not -BeNullOrEmpty } It 'Note is correct' { - $results.note | Should be $defaultCard + $results.note | Should -Be $defaultCard } } Context 'Get all cards for a column' { $results = @(Get-GitHubProjectCard -Column $column.id -ArchivedState All) It 'Should get all cards' { - $results.Count | Should Be 2 + $results.Count | Should -Be 2 } } Context 'Get archived cards for a column' { $result = Get-GitHubProjectCard -Column $column.id -ArchivedState Archived It 'Should get archived card' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Note is correct' { - $result.note | Should be $defaultArchivedCard + $result.note | Should -Be $defaultArchivedCard } It 'Should be archived' { - $result.Archived | Should be $true + $result.Archived | Should -Be $true } } } @@ -106,11 +106,11 @@ try $result = Get-GitHubProjectCard -Card $card.id It 'Should get card' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Note has been updated' { - $result.note | Should be $defaultCardUpdated + $result.note | Should -Be $defaultCardUpdated } } @@ -119,11 +119,11 @@ try $result = Get-GitHubProjectCard -Card $cardArchived.id It 'Should get card' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Card is archived' { - $result.Archived | Should be $true + $result.Archived | Should -Be $true } } @@ -132,11 +132,11 @@ try $result = Get-GitHubProjectCard -Card $cardArchived.id It 'Should get card' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Card is not archived' { - $result.Archived | Should be $false + $result.Archived | Should -Be $false } } @@ -145,7 +145,7 @@ try $results = @(Get-GitHubProjectCard -Column $column.id) It 'Card is now top' { - $results[0].note | Should be $defaultCardTwo + $results[0].note | Should -Be $defaultCardTwo } } @@ -154,7 +154,7 @@ try $results = @(Get-GitHubProjectCard -Column $column.id) It 'Card now exists in new column' { - $results[1].note | Should be $defaultCardTwo + $results[1].note | Should -Be $defaultCardTwo } } @@ -163,13 +163,13 @@ try $results = @(Get-GitHubProjectCard -Column $columnTwo.id) It 'Card now exists in new column' { - $results[0].note | Should be $defaultCardTwo + $results[0].note | Should -Be $defaultCardTwo } } Context 'Move command throws appropriate error' { It 'Appropriate error is thrown' { - { Move-GitHubProjectCard -Card $cardTwo.id -Top -Bottom } | Should Throw 'You must use one (and only one) of the parameters Top, Bottom or After.' + { Move-GitHubProjectCard -Card $cardTwo.id -Top -Bottom } | Should -Throw 'You must use one (and only one) of the parameters Top, Bottom or After.' } } } @@ -192,11 +192,11 @@ try $result = Get-GitHubProjectCard -Card $card.id It 'Card exists' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Note is correct' { - $result.note | Should be $defaultCard + $result.note | Should -Be $defaultCard } } @@ -217,11 +217,11 @@ try $result = Get-GitHubProjectCard -Card $card.id It 'Card exists' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Content url is for an issue' { - $result.content_url | Should match 'issues' + $result.content_url | Should -Match 'issues' } } } @@ -237,7 +237,7 @@ try $null = Remove-GitHubProjectCard -Card $card.id -Confirm:$false It 'Project card should be removed' { - {Get-GitHubProjectCard -Card $card.id} | Should Throw + {Get-GitHubProjectCard -Card $card.id} | Should -Throw } } } diff --git a/Tests/GitHubProjectColumns.tests.ps1 b/Tests/GitHubProjectColumns.tests.ps1 index 6eb3f047..9df03d04 100644 --- a/Tests/GitHubProjectColumns.tests.ps1 +++ b/Tests/GitHubProjectColumns.tests.ps1 @@ -39,15 +39,15 @@ try Context 'Get columns for a project' { $results = @(Get-GitHubProjectColumn -Project $project.id) It 'Should get column' { - $results | Should Not BeNullOrEmpty + $results | Should -Not -BeNullOrEmpty } It 'Should only have one column' { - $results.Count | Should Be 1 + $results.Count | Should -Be 1 } It 'Name is correct' { - $results[0].name | Should Be $defaultColumn + $results[0].name | Should -Be $defaultColumn } } } @@ -72,11 +72,11 @@ try $result = Get-GitHubProjectColumn -Column $column.id It 'Should get column' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Name has been updated' { - $result.name | Should Be $defaultColumnUpdate + $result.name | Should -Be $defaultColumnUpdate } } @@ -85,11 +85,11 @@ try $results = @(Get-GitHubProjectColumn -Project $project.id) It 'Should still have more than one column in the project' { - $results.Count | Should Be 2 + $results.Count | Should -Be 2 } It 'Column is now in the first position' { - $results[0].name | Should Be $defaultColumnTwo + $results[0].name | Should -Be $defaultColumnTwo } } @@ -98,13 +98,13 @@ try $results = @(Get-GitHubProjectColumn -Project $project.id) It 'Column is now not in the first position' { - $results[1].name | Should Be $defaultColumnTwo + $results[1].name | Should -Be $defaultColumnTwo } } Context 'Move command throws appropriate error' { It 'Expected error returned' { - { Move-GitHubProjectColumn -Column $column.id -First -Last } | Should Throw 'You must use one (and only one) of the parameters First, Last or After.' + { Move-GitHubProjectColumn -Column $column.id -First -Last } | Should -Throw 'You must use one (and only one) of the parameters First, Last or After.' } } } @@ -127,11 +127,11 @@ try $result = Get-GitHubProjectColumn -Column $column.id It 'Column exists' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Name is correct' { - $result.name | Should Be $defaultColumn + $result.name | Should -Be $defaultColumn } } } @@ -147,7 +147,7 @@ try $null = Remove-GitHubProjectColumn -Column $column.id -Confirm:$false It 'Project column should be removed' { - {Get-GitHubProjectColumn -Column $column.id} | Should Throw + {Get-GitHubProjectColumn -Column $column.id} | Should -Throw } } } diff --git a/Tests/GitHubProjects.tests.ps1 b/Tests/GitHubProjects.tests.ps1 index dec75e4a..4d88eee1 100644 --- a/Tests/GitHubProjects.tests.ps1 +++ b/Tests/GitHubProjects.tests.ps1 @@ -49,19 +49,19 @@ try $results = @(Get-GitHubProject -UserName $script:ownerName | Where-Object Name -eq $defaultUserProject) It 'Should get project' { - $results | Should Not BeNullOrEmpty + $results | Should -Not -BeNullOrEmpty } It 'Should only get a single project' { - $results.Count | Should Be 1 + $results.Count | Should -Be 1 } It 'Name is correct' { - $results[0].name | Should be $defaultUserProject + $results[0].name | Should -Be $defaultUserProject } It 'Description is correct' { - $results[0].body | Should be $defaultUserProjectDesc + $results[0].body | Should -Be $defaultUserProjectDesc } } @@ -79,19 +79,19 @@ try $results = @(Get-GitHubProject -OrganizationName $script:organizationName | Where-Object Name -eq $defaultOrgProject) It 'Should get project' { - $results | Should Not BeNullOrEmpty + $results | Should -Not -BeNullOrEmpty } It 'Should only get a single project' { - $results.Count | Should Be 1 + $results.Count | Should -Be 1 } It 'Name is correct' { - $results[0].name | Should be $defaultOrgProject + $results[0].name | Should -Be $defaultOrgProject } It 'Description is correct' { - $results[0].body | Should be $defaultOrgProjectDesc + $results[0].body | Should -Be $defaultOrgProjectDesc } } @@ -109,19 +109,19 @@ try $results = @(Get-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name | Where-Object Name -eq $defaultRepoProject) It 'Should get project' { - $results | Should Not BeNullOrEmpty + $results | Should -Not -BeNullOrEmpty } It 'Should only get a single project' { - $results.Count | Should Be 1 + $results.Count | Should -Be 1 } It 'Name is correct' { - $results[0].name | Should be $defaultRepoProject + $results[0].name | Should -Be $defaultRepoProject } It 'Description is correct' { - $results[0].body | Should be $defaultRepoProjectDesc + $results[0].body | Should -Be $defaultRepoProjectDesc } } @@ -140,23 +140,23 @@ try $results = @(Get-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -State 'Closed' | Where-Object Name -eq $defaultProjectClosed) It 'Should get project' { - $results | Should Not BeNullOrEmpty + $results | Should -Not -BeNullOrEmpty } It 'Should only get a single project' { - $results.Count | Should Be 1 + $results.Count | Should -Be 1 } It 'Name is correct' { - $results[0].name | Should be $defaultProjectClosed + $results[0].name | Should -Be $defaultProjectClosed } It 'Description is correct' { - $results[0].body | Should be $defaultProjectClosedDesc + $results[0].body | Should -Be $defaultProjectClosedDesc } It 'State is correct' { - $results[0].state | Should be "Closed" + $results[0].state | Should -Be "Closed" } } } @@ -177,15 +177,15 @@ try $null = Set-GitHubProject -Project $project.id -Description $modifiedUserProjectDesc $result = Get-GitHubProject -Project $project.id It 'Should get project' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Name is correct' { - $result.name | Should be $defaultUserProject + $result.name | Should -Be $defaultUserProject } It 'Description should be updated' { - $result.body | Should be $modifiedUserProjectDesc + $result.body | Should -Be $modifiedUserProjectDesc } } @@ -204,23 +204,23 @@ try $null = Set-GitHubProject -Project $project.id -Description $modifiedOrgProjectDesc -Private:$false -OrganizationPermission Admin $result = Get-GitHubProject -Project $project.id It 'Should get project' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Name is correct' { - $result.name | Should be $defaultOrgProject + $result.name | Should -Be $defaultOrgProject } It 'Description should be updated' { - $result.body | Should be $modifiedOrgProjectDesc + $result.body | Should -Be $modifiedOrgProjectDesc } It 'Visibility should be updated to public' { - $result.private | Should be $false + $result.private | Should -Be $false } It 'Organization permission should be updated to admin' { - $result.organization_permission | Should be 'admin' + $result.organization_permission | Should -Be 'admin' } } @@ -240,15 +240,15 @@ try $null = Set-GitHubProject -Project $project.id -Description $modifiedRepoProjectDesc $result = Get-GitHubProject -Project $project.id It 'Should get project' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Name is correct' { - $result.name | Should be $defaultRepoProject + $result.name | Should -Be $defaultRepoProject } It 'Description should be updated' { - $result.body | Should be $modifiedRepoProjectDesc + $result.body | Should -Be $modifiedRepoProjectDesc } } } @@ -270,15 +270,15 @@ try $project.id = (New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc).id $result = Get-GitHubProject -Project $project.id It 'Project exists' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Name is correct' { - $result.name | Should be $defaultUserProject + $result.name | Should -Be $defaultUserProject } It 'Description should be updated' { - $result.body | Should be $defaultUserProjectDesc + $result.body | Should -Be $defaultUserProjectDesc } } @@ -298,15 +298,15 @@ try $project.id = (New-GitHubProject -OrganizationName $script:organizationName -Name $defaultOrgProject -Description $defaultOrgProjectDesc).id $result = Get-GitHubProject -Project $project.id It 'Project exists' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Name is correct' { - $result.name | Should be $defaultOrgProject + $result.name | Should -Be $defaultOrgProject } It 'Description should be updated' { - $result.body | Should be $defaultOrgProjectDesc + $result.body | Should -Be $defaultOrgProjectDesc } } @@ -326,15 +326,15 @@ try $project.id = (New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultRepoProject -Description $defaultRepoProjectDesc).id $result = Get-GitHubProject -Project $project.id It 'Project Exists' { - $result | Should Not BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty } It 'Name is correct' { - $result.name | Should be $defaultRepoProject + $result.name | Should -Be $defaultRepoProject } It 'Description should be updated' { - $result.body | Should be $defaultRepoProjectDesc + $result.body | Should -Be $defaultRepoProjectDesc } } } @@ -350,7 +350,7 @@ try $null = Remove-GitHubProject -Project $project.id -Force It 'Project should be removed' { - {Get-GitHubProject -Project $project.id} | Should Throw + {Get-GitHubProject -Project $project.id} | Should -Throw } } @@ -364,7 +364,7 @@ try $null = Remove-GitHubProject -Project $project.id -Force It 'Project should be removed' { - {Get-GitHubProject -Project $project.id} | Should Throw + {Get-GitHubProject -Project $project.id} | Should -Throw } } @@ -378,7 +378,7 @@ try $null = Remove-GitHubProject -Project $project.id -Confirm:$false It 'Project should be removed' { - {Get-GitHubProject -Project $project.id} | Should Throw + {Get-GitHubProject -Project $project.id} | Should -Throw } } } diff --git a/Tests/GitHubReleases.tests.ps1 b/Tests/GitHubReleases.tests.ps1 index 79ebfe9b..00854478 100644 --- a/Tests/GitHubReleases.tests.ps1 +++ b/Tests/GitHubReleases.tests.ps1 @@ -19,7 +19,7 @@ try Context 'When getting all releases' { It 'Should return multiple releases' { - $releases.Count | Should BeGreaterThan 1 + $releases.Count | Should -BeGreaterThan 1 } } @@ -27,12 +27,12 @@ try $latest = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Latest) It 'Should return one value' { - $latest.Count | Should Be 1 + $latest.Count | Should -Be 1 } It 'Should return the first release from the full releases list' { - $latest[0].url | Should Be $releases[0].url - $latest[0].name | Should Be $releases[0].name + $latest[0].url | Should -Be $releases[0].url + $latest[0].name | Should -Be $releases[0].name } } @@ -41,11 +41,11 @@ try $specific = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -ReleaseId $releases[$specificIndex].id) It 'Should return one value' { - $specific.Count | Should Be 1 + $specific.Count | Should -Be 1 } It 'Should return the correct release' { - $specific.name | Should Be $releases[$specificIndex].name + $specific.name | Should -Be $releases[$specificIndex].name } } @@ -54,11 +54,11 @@ try $tagged = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Tag $releases[$taggedIndex].tag_name) It 'Should return one value' { - $tagged.Count | Should Be 1 + $tagged.Count | Should -Be 1 } It 'Should return the correct release' { - $tagged.name | Should Be $releases[$taggedIndex].name + $tagged.name | Should -Be $releases[$taggedIndex].name } } } @@ -74,7 +74,7 @@ try Context 'When getting all releases' { It 'Should return multiple releases' { - $releases.Count | Should BeGreaterThan 1 + $releases.Count | Should -BeGreaterThan 1 } } } finally { diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 597d7607..de5a1f24 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -637,7 +637,7 @@ try $contributors = @(Get-GitHubRepositoryContributor -Uri $repo.RepositoryUrl -IncludeStatistics) It 'Should return expected number of contributors' { - $contributors.Count | Should be 1 + $contributors.Count | Should -Be 1 } It 'Should return expected number of unique contributors' { @@ -646,7 +646,7 @@ try Select-Object -ExpandProperty login -Unique Sort-Object - $uniqueContributors.Count | Should be 1 + $uniqueContributors.Count | Should -Be 1 } } } @@ -667,7 +667,7 @@ try $collaborators = @(Get-GitHubRepositoryCollaborator -Uri $repo.RepositoryUrl) It 'Should return expected number of collaborators' { - $collaborators.Count | Should be 1 + $collaborators.Count | Should -Be 1 } } } From be76b8558dbe122457a1cbee80b550ffb8de83a0 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 9 Jun 2020 00:34:58 -0700 Subject: [PATCH 26/80] Adds half of the pipeline repository tests. --- GitHubRepositories.ps1 | 90 +++++++++++++++++++----- GitHubUsers.ps1 | 29 +++++--- PowerShellForGitHub.psd1 | 1 + Tests/GitHubRepositories.tests.ps1 | 106 ++++++++++++++++++++++++++++- Tests/GitHubUsers.tests.ps1 | 10 +-- USAGE.md | 2 +- 6 files changed, 203 insertions(+), 35 deletions(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 98583c60..92037d20 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -102,6 +102,9 @@ filter New-GitHubRepository .EXAMPLE New-GitHubRepository -RepositoryName MyNewRepo -AutoInit + .EXAMPLE + 'MyNewRepo' | New-GitHubRepository -AutoInit + .EXAMPLE New-GitHubRepository -RepositoryName MyNewRepo -Organization MyOrg -DisallowRebaseMerge #> @@ -263,6 +266,12 @@ filter Remove-GitHubRepository Remove-GitHubRepository -Uri https://github.com/You/YourRepoToDelete -Force Remove repository with the given URI, without prompting for confirmation. + + .EXAMPLE + $repo = Get-GitHubRepository -Uri https://github.com/You/YourRepoToDelete + $repo | Remove-GitHubRepository -Force + + You can also pipe in a repo that was returned from a previous command. #> [CmdletBinding( SupportsShouldProcess, @@ -410,11 +419,21 @@ filter Get-GitHubRepository Gets all of the repositories for the user octocat + .EXAMPLE + Get-GitHubUser -UserName octocat | Get-GitHubRepository + + Gets all of the repositories for the user octocat + .EXAMPLE Get-GitHubRepository -Uri https://github.com/microsoft/PowerShellForGitHub Gets information about the microsoft/PowerShellForGitHub repository. + .EXAMPLE + $repo | Get-GitHubRepository + + You can pipe in a previous repository to get its information again. + .EXAMPLE Get-GitHubRepository -OrganizationName PowerShell @@ -716,10 +735,14 @@ filter Rename-GitHubRepository [OutputType({$script:GitHubRepositoryTypeName})] [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=$true, ParameterSetName='Elements')] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $OwnerName, - [Parameter(Mandatory=$true, ParameterSetName='Elements')] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $RepositoryName, [Parameter( @@ -730,7 +753,7 @@ filter Rename-GitHubRepository [string] $Uri, [parameter(Mandatory)] - [String]$NewName, + [String] $NewName, [switch] $Force, @@ -760,7 +783,7 @@ filter Rename-GitHubRepository $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName" 'Method' = 'Patch' - Body = ConvertTo-Json -InputObject @{name = $NewName} + 'Body' = ConvertTo-Json -InputObject @{name = $NewName} 'Description' = "Renaming repository at '$repositoryInfoForDisplayMessage' to '$NewName'" 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name @@ -797,6 +820,9 @@ filter Update-GitHubRepository The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. + .PARAMETER Name + Rename the repository to this new name. + .PARAMETER Description A short description of the repository. @@ -865,6 +891,13 @@ filter Update-GitHubRepository Update-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub -Private:$false Changes the visibility of the specified repository to be public. + + .EXAMPLE + Get-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub | + Update-GitHubRepository -Name 'PoShForGitHub' -Confirm:$false + + Renames the repository without any user confirmation prompting. This is identical to using + Rename-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub -NewName 'PoShForGitHub' -Confirm:$false #> [CmdletBinding( SupportsShouldProcess, @@ -885,6 +918,9 @@ filter Update-GitHubRepository [Alias('RepositoryUrl')] [string] $Uri, + [ValidateNotNullOrEmpty()] + [string] $Name, + [string] $Description, [string] $Homepage, @@ -927,8 +963,17 @@ filter Update-GitHubRepository 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - $hashBody = @{ - 'name' = $RepositoryName + $hashBody = @{} + + if ($PSBoundParameters.ContainsKey('Name')) + { + $existingName = if ($PSCmdlet.ParameterSetName -eq 'Uri') { $Uri } else { $OwnerName, $RepositoryName -join '/' } + if (-not $PSCmdlet.ShouldProcess($existingName, "Rename repository to '$Name'")) + { + return + } + + $hashBody['name'] = $Name } if ($PSBoundParameters.ContainsKey('Description')) { $hashBody['description'] = $Description } @@ -1078,7 +1123,7 @@ filter Set-GitHubRepositoryTopic The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER Name + .PARAMETER Topic Array of topics to add to the repository. .PARAMETER Clear @@ -1101,7 +1146,7 @@ filter Set-GitHubRepositoryTopic Set-GitHubRepositoryTopic -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Clear .EXAMPLE - Set-GitHubRepositoryTopic -Uri https://github.com/PowerShell/PowerShellForGitHub -Name ('octocat', 'powershell', 'github') + Set-GitHubRepositoryTopic -Uri https://github.com/PowerShell/PowerShellForGitHub -Topic ('octocat', 'powershell', 'github') #> [CmdletBinding( SupportsShouldProcess, @@ -1130,11 +1175,14 @@ filter Set-GitHubRepositoryTopic [Parameter( Mandatory, + ValueFromPipeline, ParameterSetName='ElementsName')] [Parameter( Mandatory, + ValueFromPipeline, ParameterSetName='UriName')] - [string[]] $Name, + [Alias('Name')] + [string[]] $Topic, [Parameter( Mandatory, @@ -1164,7 +1212,7 @@ filter Set-GitHubRepositoryTopic if ($Clear) { $description = "Clearing topics in $RepositoryName" - $Name = @() + $Topic = @() } else { @@ -1172,7 +1220,7 @@ filter Set-GitHubRepositoryTopic } $hashBody = @{ - 'names' = $Name + 'names' = $Topic } $params = @{ @@ -1620,7 +1668,7 @@ filter Move-GitHubRepositoryOwnership If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - GitHub.RepositoryTopic + GitHub.Repository .EXAMPLE Move-GitHubRepositoryOwnership -OwnerName Microsoft -RepositoryName PowerShellForGitHub -NewOwnerName OctoCat @@ -1732,13 +1780,19 @@ filter Add-GitHubRepositoryAdditionalProperties if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { - $elements = Split-GitHubUri -Uri $item.html_url - $repositoryUrl = Join-GitHubUri @elements - if ([String]::IsNullOrEmpty($repositoryUrl) -and - $PSBoundParameters.ContainsKey('OwnerName') -and - $PSBoundParameters.ContainsKey('RepositoryName')) + $repositoryUrl = [String]::Empty + if ([String]::IsNullOrEmpty($item.html_url)) + { + if ($PSBoundParameters.ContainsKey('OwnerName') -and + $PSBoundParameters.ContainsKey('RepositoryName')) + { + $repositoryUrl = (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) + } + } + else { - $repositoryUrl = (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) + $elements = Split-GitHubUri -Uri $item.html_url + $repositoryUrl = Join-GitHubUri @elements } if (-not [String]::IsNullOrEmpty($repositoryUrl)) diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index f1e891ce..71cb8673 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -49,10 +49,15 @@ filter Get-GitHubUser GitHub.User .EXAMPLE - Get-GitHubUser -User octocat + Get-GitHubUser -UserName octocat Gets information on just the user named 'octocat' + .EXAMPLE + 'octocat', 'PowerShellForGitHubTeam' | Get-GitHubUser + + Gets information on the users named 'octocat' and 'PowerShellForGitHubTeam' + .EXAMPLE Get-GitHubUser @@ -74,8 +79,9 @@ filter Get-GitHubUser ValueFromPipeline, ValueFromPipelineByPropertyName, ParameterSetName='ListAndSearch')] - [Alias('UserName')] - [string] $User, + [Alias('Name')] + [Alias('User')] + [string] $UserName, [Parameter(ParameterSetName='Current')] [switch] $Current, @@ -105,7 +111,7 @@ filter Get-GitHubUser } else { - return (Invoke-GHRestMethod -UriFragment "users/$User" -Description "Getting user $User" -Method 'Get' @params | + return (Invoke-GHRestMethod -UriFragment "users/$UserName" -Description "Getting user $User" -Method 'Get' @params | Add-GitHubUserAdditionalProperties) } } @@ -161,6 +167,10 @@ filter Get-GitHubUserContextualInformation .EXAMPLE Get-GitHubUserContextualInformation -User octocat -RepositoryId 1300192 + .EXAMPLE + $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName 'PowerShellForGitHub' + $repo | Get-GitHubUserContextualInformation -User octocat + .EXAMPLE Get-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 70 | Get-GitHubUserContextualInformation -User octocat @@ -176,8 +186,9 @@ filter Get-GitHubUserContextualInformation Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] - [Alias('UserName')] - [string] $User, + [Alias('Name')] + [Alias('User')] + [string] $UserName, [Parameter( Mandatory, @@ -237,9 +248,9 @@ filter Get-GitHubUserContextualInformation } $params = @{ - 'UriFragment' = "users/$User/hovercard`?" + ($getParams -join '&') + 'UriFragment' = "users/$UserName/hovercard`?" + ($getParams -join '&') 'Method' = 'Get' - 'Description' = "Getting hovercard information for $User" + 'Description' = "Getting hovercard information for $UserName" 'AcceptHeader' = 'application/vnd.github.hagar-preview+json' 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name @@ -247,7 +258,7 @@ filter Get-GitHubUserContextualInformation } return (Invoke-GHRestMethod @params | - Add-GitHubUserAdditionalProperties -TypeName $script:GitHubUserContextualInformationTypeName -Name $User) + Add-GitHubUserAdditionalProperties -TypeName $script:GitHubUserContextualInformationTypeName -Name $UserName) } function Update-GitHubCurrentUser diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index 5ef27773..750fd498 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -95,6 +95,7 @@ 'Group-GitHubPullRequest', 'Invoke-GHRestMethod', 'Invoke-GHRestMethodMultipleResult', + 'Join-GitHubUri', 'Lock-GitHubIssue', 'Move-GitHubProjectCard', 'Move-GitHubProjectColumn', diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index de5a1f24..99fac6ca 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -418,6 +418,18 @@ try $renamedRepo.name | Should -Be $newRepoName } + It "Should work via the pipeline" { + $renamedRepo = $repo | Rename-GitHubRepository -NewName $newRepoName -Confirm:$false + $renamedRepo.name | Should -Be $newRepoName + $renamedRepo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' + } + + It "Should be possible to rename with Update-GitHubRepository too" { + $renamedRepo = $repo | Update-GitHubRepository -Name $newRepoName -Confirm:$false + $renamedRepo.name | Should -Be $newRepoName + $renamedRepo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' + } + AfterEach -Scriptblock { Remove-GitHubRepository -Uri "$($repo.svn_url)$suffixToAddToRepo" -Confirm:$false } @@ -555,6 +567,80 @@ try } } + Describe 'Common user repository pipeline scenarios' { + Context 'For authenticated user' { + BeforeAll -Scriptblock { + $repo = ([Guid]::NewGuid().Guid) | New-GitHubRepository -AutoInit + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $repo = $repo + } + + It "Should have expected additional properties and type after creation" { + $repo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' + $repo.RepositoryUrl | Should -Be (Join-GitHubUri -OwnerName $script:ownerName -RepositoryName $repo.name) + $repo.RepositoryId | Should -Be $repo.id + $repo.owner.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + + It "Should have expected additional properties and type after creation" { + $returned = ($repo | Get-GitHubRepository) + $returned.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' + $returned.RepositoryUrl | Should -Be (Join-GitHubUri -OwnerName $script:ownerName -RepositoryName $returned.name) + $returned.RepositoryId | Should -Be $returned.id + $returned.owner.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + + It "Should get the repository by user" { + $repos = @($script:ownerName | Get-GitHubUser | Get-GitHubRepository) + $repos.name | Should -Contain $repo.name + } + + It 'Should be removable by the pipeline' { + ($repo | Remove-GitHubRepository -Confirm:$false) | Should -BeNullOrEmpty + { $repo | Get-GitHubRepository } | Should -Throw + } + } + } + + Describe 'Common organization repository pipeline scenarios' { + Context 'For organization' { + BeforeAll -Scriptblock { + $org = [PSCustomObject]@{'OrganizationName' = $script:organizationName} + $repo = $org | New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $repo = $repo + } + + It "Should have expected additional properties and type after creation" { + $repo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' + $repo.RepositoryUrl | Should -Be (Join-GitHubUri -OwnerName $script:organizationName -RepositoryName $repo.name) + $repo.RepositoryId | Should -Be $repo.id + $repo.owner.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $repo.organization.PSObject.TypeNames[0] | Should -Be 'GitHub.Organization' + $repo.organization.OrganizationName | Should -Be $repo.organization.login + $repo.organization.OrganizationId | Should -Be $repo.organization.id + } + + It "Should have expected additional properties and type after creation" { + $returned = ($repo | Get-GitHubRepository) + $returned.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' + $returned.RepositoryUrl | Should -Be (Join-GitHubUri -OwnerName $script:organizationName -RepositoryName $returned.name) + $returned.RepositoryId | Should -Be $returned.id + $returned.owner.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $returned.organization.PSObject.TypeNames[0] | Should -Be 'GitHub.Organization' + $returned.organization.OrganizationName | Should -Be $returned.organization.login + $returned.organization.OrganizationId | Should -Be $returned.organization.id + } + + It 'Should be removable by the pipeline' { + ($repo | Remove-GitHubRepository -Confirm:$false) | Should -BeNullOrEmpty + { $repo | Get-GitHubRepository } | Should -Throw + } + } + } + Describe 'Get/set repository topic' { Context -Name 'For creating and getting a repository topic' -Fixture { @@ -563,17 +649,33 @@ try } It 'Should have the expected topic' { - Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name -Name $defaultRepoTopic + $null = Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name -Topic $defaultRepoTopic $topic = Get-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name $topic.names | Should -Be $defaultRepoTopic } It 'Should have no topics' { - Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name -Clear + $null = Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name -Clear $topic = Get-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name $topic.names | Should -BeNullOrEmpty } + It 'Should have the expected topic (using repo via pipeline)' { + $null = $repo | Set-GitHubRepositoryTopic -Topic $defaultRepoTopic + $topic = $repo | Get-GitHubRepositoryTopic + $topic.names | Should -Be $defaultRepoTopic + $topic.PSObject.TypeNames[0] | Should -Be 'GitHub.RepositoryTopic' + $topic.RepositoryUrl | Should -Be $repo.RepositoryUrl + } + + It 'Should have the expected topic (using topic via pipeline)' { + $null = $defaultRepoTopic | Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name + $topic = $repo | Get-GitHubRepositoryTopic + $topic.names | Should -Be $defaultRepoTopic + $topic.PSObject.TypeNames[0] | Should -Be 'GitHub.RepositoryTopic' + $topic.RepositoryUrl | Should -Be $repo.RepositoryUrl + } + AfterAll -ScriptBlock { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } diff --git a/Tests/GitHubUsers.tests.ps1 b/Tests/GitHubUsers.tests.ps1 index d81ab953..0df4eed7 100644 --- a/Tests/GitHubUsers.tests.ps1 +++ b/Tests/GitHubUsers.tests.ps1 @@ -50,7 +50,7 @@ try Context 'Specific user as a parameter' { BeforeAll { - $user = Get-GitHubUser -User $script:ownerName + $user = Get-GitHubUser -UserName $script:ownerName # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments $user = $user @@ -93,12 +93,12 @@ try Context 'Checking context on a repo' { It 'Should indicate ownership as a parameter' { - $context = Get-GitHubUserContextualInformation -User $script:ownerName -RepositoryId $repo.id + $context = Get-GitHubUserContextualInformation -UserName $script:ownerName -RepositoryId $repo.id 'Owns this repository' | Should -BeIn $context.contexts.message } It 'Should indicate ownership with the repo on the pipeline' { - $context = $repo | Get-GitHubUserContextualInformation -User $script:ownerName + $context = $repo | Get-GitHubUserContextualInformation -UserName $script:ownerName 'Owns this repository' | Should -BeIn $context.contexts.message } @@ -108,7 +108,7 @@ try } It 'Should indicate ownership with the user on the pipeline' { - $user = Get-GitHubUser -User $script:ownerName + $user = Get-GitHubUser -UserName $script:ownerName $context = $user | Get-GitHubUserContextualInformation -RepositoryId $repo.id 'Owns this repository' | Should -BeIn $context.contexts.message } @@ -116,7 +116,7 @@ try Context 'Checking context on an issue with the pipeline' { $issue = New-GitHubIssue -Uri $repo.RepositoryUrl -Title ([guid]::NewGuid().Guid) - $context = $issue | Get-GitHubUserContextualInformation -User $script:ownerName + $context = $issue | Get-GitHubUserContextualInformation -UserName $script:ownerName It 'Should indicate the user created the issue' { $context.contexts[0].octicon | Should -Be 'issue-opened' diff --git a/USAGE.md b/USAGE.md index 844d1186..b386b674 100644 --- a/USAGE.md +++ b/USAGE.md @@ -354,7 +354,7 @@ Update-GitHubCurrentUser -Location 'Seattle, WA' -Hireable:$false #### Getting any user ```powershell -Get-GitHubUser -Name octocat +Get-GitHubUser -UserName octocat ``` #### Getting all users From d65eb3f115e7b16e65650c45de4ae3f8b793f0a6 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 9 Jun 2020 07:31:45 -0700 Subject: [PATCH 27/80] Make Set-GitHubRepositoryTopic pipeline input work well with an array --- GitHubRepositories.ps1 | 91 +++++++++++++++++++----------- Tests/GitHubRepositories.tests.ps1 | 18 ++++++ 2 files changed, 76 insertions(+), 33 deletions(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 92037d20..37334bb4 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -1099,7 +1099,7 @@ filter Get-GitHubRepositoryTopic Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTopicTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } -filter Set-GitHubRepositoryTopic +function Set-GitHubRepositoryTopic { <# .SYNOPSIS @@ -1147,6 +1147,16 @@ filter Set-GitHubRepositoryTopic .EXAMPLE Set-GitHubRepositoryTopic -Uri https://github.com/PowerShell/PowerShellForGitHub -Topic ('octocat', 'powershell', 'github') + + .EXAMPLE + ('octocat', 'powershell', 'github') | Set-GitHubRepositoryTopic -Uri https://github.com/PowerShell/PowerShellForGitHub + + .NOTES + This is implemented as a function rather than a filter because the ValueFromPipeline + parameter (Topic) is itself an array which we want to ensure is processed only a single time. + This API endpoint doesn't add topics to a repository, it replaces the existing topics with + the new set provided, so we need to make sure that we have all the requested topics available + to us at the time that the API endpoint is called. #> [CmdletBinding( SupportsShouldProcess, @@ -1197,46 +1207,61 @@ filter Set-GitHubRepositoryTopic [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation - - $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters - $OwnerName = $elements.ownerName - $RepositoryName = $elements.repositoryName - - $telemetryProperties = @{ - 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) - 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) - 'Clear' = $PSBoundParameters.ContainsKey('Clear') + begin + { + $topics = @() } - if ($Clear) + process { - $description = "Clearing topics in $RepositoryName" - $Topic = @() + foreach ($value in $Topic) + { + $topics += $value + } } - else + + end { - $description = "Replacing topics in $RepositoryName" - } + Write-InvocationLog -Invocation $MyInvocation - $hashBody = @{ - 'names' = $Topic - } + $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters + $OwnerName = $elements.ownerName + $RepositoryName = $elements.repositoryName - $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName/topics" - 'Body' = (ConvertTo-Json -InputObject $hashBody) - 'Method' = 'Put' - 'Description' = $description - 'AcceptHeader' = $script:mercyAcceptHeader - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) - } + $telemetryProperties = @{ + 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) + 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) + 'Clear' = $PSBoundParameters.ContainsKey('Clear') + } - return (Invoke-GHRestMethod @params | - Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTopicTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) + if ($Clear) + { + $description = "Clearing topics in $RepositoryName" + } + else + { + $description = "Replacing topics in $RepositoryName" + } + + $hashBody = @{ + 'names' = $topics + } + + $params = @{ + 'UriFragment' = "repos/$OwnerName/$RepositoryName/topics" + 'Body' = (ConvertTo-Json -InputObject $hashBody) + 'Method' = 'Put' + 'Description' = $description + 'AcceptHeader' = $script:mercyAcceptHeader + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) + } + + return (Invoke-GHRestMethod @params | + Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTopicTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) + } } filter Get-GitHubRepositoryContributor diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 99fac6ca..a3d55243 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -651,18 +651,21 @@ try It 'Should have the expected topic' { $null = Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name -Topic $defaultRepoTopic $topic = Get-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name + $topic.names | Should -Be $defaultRepoTopic } It 'Should have no topics' { $null = Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name -Clear $topic = Get-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name + $topic.names | Should -BeNullOrEmpty } It 'Should have the expected topic (using repo via pipeline)' { $null = $repo | Set-GitHubRepositoryTopic -Topic $defaultRepoTopic $topic = $repo | Get-GitHubRepositoryTopic + $topic.names | Should -Be $defaultRepoTopic $topic.PSObject.TypeNames[0] | Should -Be 'GitHub.RepositoryTopic' $topic.RepositoryUrl | Should -Be $repo.RepositoryUrl @@ -671,11 +674,26 @@ try It 'Should have the expected topic (using topic via pipeline)' { $null = $defaultRepoTopic | Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name $topic = $repo | Get-GitHubRepositoryTopic + $topic.names | Should -Be $defaultRepoTopic $topic.PSObject.TypeNames[0] | Should -Be 'GitHub.RepositoryTopic' $topic.RepositoryUrl | Should -Be $repo.RepositoryUrl } + It 'Should have the expected multi-topic (using topic via pipeline)' { + $topics = @('one', 'two') + $null = $topics | Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name + $result = $repo | Get-GitHubRepositoryTopic + + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.RepositoryTopic' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.names.count | Should -Be $topics.Count + foreach ($topic in $topics) + { + $result.names | Should -Contain $topic + } + } + AfterAll -ScriptBlock { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } From b3cc8a115581c7cb2b285a4d5d5a17ce255b7499 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 9 Jun 2020 14:45:34 -0700 Subject: [PATCH 28/80] * Fixed 'GitHub' casing throughout module * Fixed handling of typing for Repo Contributors, Collaborators and Tags. * Added missing 'Affiliation' parameter to Get-GitHubRepositoryCollaborator * Completed required repository tests --- GitHubAssignees.ps1 | 14 ++++----- GitHubComments.ps1 | 14 ++++----- GitHubMilestones.ps1 | 19 +++++++----- GitHubMiscellaneous.ps1 | 2 +- GitHubProjectCards.ps1 | 4 +-- GitHubProjectColumns.ps1 | 4 +-- GitHubProjects.ps1 | 6 ++-- GitHubRepositories.ps1 | 48 ++++++++++++++++++++++++++---- GitHubRepositoryTraffic.ps1 | 6 ++-- GitHubUsers.ps1 | 32 ++++++++++++++++++-- PowerShellForGitHub.psd1 | 4 +-- Tests/GitHubAssignees.tests.ps1 | 16 +++++----- Tests/GitHubEvents.tests.ps1 | 6 ++-- Tests/GitHubRepositories.tests.ps1 | 43 ++++++++++++++++++++++++++ Tests/GitHubUsers.tests.ps1 | 5 ++++ USAGE.md | 4 +-- 16 files changed, 172 insertions(+), 55 deletions(-) diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index d9212dd7..388608aa 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -193,11 +193,11 @@ filter Test-GitHubAssignee } } -filter New-GithubAssignee +filter New-GitHubAssignee { <# .DESCRIPTION - Adds a list of assignees to a Github Issue for the given repository. + Adds a list of assignees to a GitHub Issue for the given repository. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -235,7 +235,7 @@ filter New-GithubAssignee GitHub.Issue .EXAMPLE - New-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignee + New-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignee Lists the available assignees for issues from the Microsoft\PowerShellForGitHub project. #> @@ -310,11 +310,11 @@ filter New-GithubAssignee return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) } -filter Remove-GithubAssignee +filter Remove-GitHubAssignee { <# .DESCRIPTION - Removes an assignee from a Github issue. + Removes an assignee from a GitHub issue. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -354,12 +354,12 @@ filter Remove-GithubAssignee GitHub.Issue .EXAMPLE - Remove-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees + Remove-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees Removes the available assignees for issues from the Microsoft\PowerShellForGitHub project. .EXAMPLE - Remove-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees -Confirm:$false + Remove-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees -Confirm:$false Removes the available assignees for issues from the Microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified. diff --git a/GitHubComments.ps1 b/GitHubComments.ps1 index 41260d4a..d8d5d88b 100644 --- a/GitHubComments.ps1 +++ b/GitHubComments.ps1 @@ -11,7 +11,7 @@ filter Get-GitHubComment { <# .DESCRIPTION - Get the comments for a given Github repository. + Get the comments for a given GitHub repository. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -207,7 +207,7 @@ filter New-GitHubComment { <# .DESCRIPTION - Creates a new Github comment in an issue for the given repository + Creates a new GitHub comment in an issue for the given repository The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -254,7 +254,7 @@ filter New-GitHubComment .EXAMPLE New-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Body "Testing this API" - Creates a new Github comment in an issue for the Microsoft\PowerShellForGitHub project. + Creates a new GitHub comment in an issue for the Microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -449,7 +449,7 @@ filter Remove-GitHubComment { <# .DESCRIPTION - Deletes a Github comment for the given repository + Deletes a GitHub comment for the given repository The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -485,7 +485,7 @@ filter Remove-GitHubComment .EXAMPLE Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Comment 1 - Deletes a Github comment from the Microsoft\PowerShellForGitHub project. + Deletes a GitHub comment from the Microsoft\PowerShellForGitHub project. .EXAMPLE Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Confirm:$false @@ -493,9 +493,9 @@ filter Remove-GitHubComment Deletes a Github comment from the Microsoft\PowerShellForGitHub project without prompting confirmation. .EXAMPLE - Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1 -Force + Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Force - Deletes a Github comment from the Microsoft\PowerShellForGitHub project without prompting confirmation. + Deletes a GitHub comment from the Microsoft\PowerShellForGitHub project without prompting confirmation. #> [CmdletBinding( SupportsShouldProcess, diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index 5fd86741..69f6154b 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -15,7 +15,7 @@ filter Get-GitHubMilestone { <# .DESCRIPTION - Get the milestones for a given Github repository. + Get the milestones for a given GitHub repository. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -33,7 +33,8 @@ filter Get-GitHubMilestone them individually. .PARAMETER Milestone - The number of a specific milestone to get. If not supplied, will return back all milestones for this repository. + The number of a specific milestone to get. If not supplied, will return back all milestones + for this repository. .PARAMETER Sort How to sort the results. @@ -177,7 +178,7 @@ filter New-GitHubMilestone { <# .DESCRIPTION - Creates a new Github milestone for the given repository + Creates a new GitHub milestone for the given repository The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -224,7 +225,7 @@ filter New-GitHubMilestone .EXAMPLE New-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Title "Testing this API" - Creates a new Github milestone for the Microsoft\PowerShellForGitHub project. + Creates a new GitHub milestone for the Microsoft\PowerShellForGitHub project. .NOTES For more information on how GitHub handles the dates specified in DueOn, please refer to @@ -498,7 +499,7 @@ filter Remove-GitHubMilestone { <# .DESCRIPTION - Deletes a Github milestone for the given repository + Deletes a GitHub milestone for the given repository The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -534,17 +535,19 @@ filter Remove-GitHubMilestone .EXAMPLE Remove-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 - Deletes a Github milestone from the Microsoft\PowerShellForGitHub project. + Deletes a GitHub milestone from the Microsoft\PowerShellForGitHub project. .EXAMPLE Remove-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Confirm:$false - Deletes a Github milestone from the Microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified. + Deletes a Github milestone from the Microsoft\PowerShellForGitHub project. Will not prompt + for confirmation, as -Confirm:$false was specified. .EXAMPLE Remove-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Force - Deletes a Github milestone from the Microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Force was specified. + Deletes a Github milestone from the Microsoft\PowerShellForGitHub project. Will not prompt + for confirmation, as -Force was specified. #> [CmdletBinding( SupportsShouldProcess, diff --git a/GitHubMiscellaneous.ps1 b/GitHubMiscellaneous.ps1 index 611692d1..dd492353 100644 --- a/GitHubMiscellaneous.ps1 +++ b/GitHubMiscellaneous.ps1 @@ -350,7 +350,7 @@ function Get-GitHubEmoji If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - Github.Emoji + GitHub.Emoji .EXAMPLE Get-GitHubEmoji diff --git a/GitHubProjectCards.ps1 b/GitHubProjectCards.ps1 index 540fb1d3..984bf4c4 100644 --- a/GitHubProjectCards.ps1 +++ b/GitHubProjectCards.ps1 @@ -11,7 +11,7 @@ filter Get-GitHubProjectCard { <# .DESCRIPTION - Get the cards for a given Github Project Column. + Get the cards for a given GitHub Project Column. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -132,7 +132,7 @@ filter New-GitHubProjectCard { <# .DESCRIPTION - Creates a new card for a Github project. + Creates a new card for a GitHub project. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index c5ee0f64..c1499055 100644 --- a/GitHubProjectColumns.ps1 +++ b/GitHubProjectColumns.ps1 @@ -11,7 +11,7 @@ filter Get-GitHubProjectColumn { <# .DESCRIPTION - Get the columns for a given Github Project. + Get the columns for a given GitHub Project. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -109,7 +109,7 @@ filter New-GitHubProjectColumn { <# .DESCRIPTION - Creates a new column for a Github project. + Creates a new column for a GitHub project. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 2341e254..bbb8c649 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -11,7 +11,7 @@ filter Get-GitHubProject { <# .DESCRIPTION - Get the projects for a given Github user, repository or organization. + Get the projects for a given GitHub user, repository or organization. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -188,7 +188,7 @@ filter New-GitHubProject { <# .DESCRIPTION - Creates a new Github project for the given repository + Creates a new GitHub project for the given repository The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -470,7 +470,7 @@ filter Remove-GitHubProject { <# .DESCRIPTION - Removes the projects for a given Github repository. + Removes the projects for a given GitHub repository. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 37334bb4..6a76a479 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -4,8 +4,7 @@ @{ GitHubRepositoryTypeName = 'GitHub.Repository' GitHubRepositoryTopicTypeName = 'GitHub.RepositoryTopic' - GitHubRepositoryContributorTypeName = 'GitHub.RepositoryContributor' - GitHubRepositoryCollaboratorTypeName = 'GitHub.RepositoryCollaborator' + GitHubRepositoryContributorStatisticsTypeName = 'GitHub.RepositoryContributorStatistics' GitHubRepositoryLanguageTypeName = 'GitHub.RepositoryLanguage' GitHubRepositoryTagTypeName = 'GitHub.RepositoryTag' }.GetEnumerator() | ForEach-Object { @@ -1376,7 +1375,28 @@ filter Get-GitHubRepositoryContributor 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubUserAdditionalProperties) + $results = Invoke-GHRestMethodMultipleResult @params + + if ($IncludeStatistics) + { + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $script:GitHubRepositoryContributorStatisticsTypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + $repositoryUrl = (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + $null = Add-GitHubUserAdditionalProperties -InputObject $item.author + } + } + } + else + { + $results = $results | Add-GitHubUserAdditionalProperties + } + + return $results } filter Get-GitHubRepositoryCollaborator @@ -1407,6 +1427,13 @@ filter Get-GitHubRepositoryCollaborator 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 Affiliation + Filter collaborators returned by their affiliation. Can be one of: + All: All collaborators the authenticated user can see. + Direct: All collaborators with permissions to an organization-owned repository, + regardless of organization membership status. + Outside: All outside collaborators of an organization-owned repository. + .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 @@ -1441,6 +1468,9 @@ filter Get-GitHubRepositoryCollaborator [Alias('RepositoryUrl')] [string] $Uri, + [ValidateSet('All', 'Direct', 'Outside')] + [string] $Affiliation = 'All', + [string] $AccessToken, [switch] $NoStatus @@ -1457,8 +1487,12 @@ filter Get-GitHubRepositoryCollaborator 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } + $getParams = @( + "affiliation=$($Affiliation.ToLower())" + ) + $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName/collaborators" + 'UriFragment' = "repos/$OwnerName/$RepositoryName/collaborators?" + ($getParams -join '&') 'Description' = "Getting collaborators for $RepositoryName" 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name @@ -1607,6 +1641,7 @@ filter Get-GitHubRepositoryTag [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$scrit:GitHubRepositoryTagTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -1825,7 +1860,10 @@ filter Add-GitHubRepositoryAdditionalProperties Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force } - Add-Member -InputObject $item -Name 'RepositoryId' -Value $item.id -MemberType NoteProperty -Force + if ($item.id -gt 0) + { + Add-Member -InputObject $item -Name 'RepositoryId' -Value $item.id -MemberType NoteProperty -Force + } if ($null -ne $item.owner) { diff --git a/GitHubRepositoryTraffic.ps1 b/GitHubRepositoryTraffic.ps1 index 7f7b264a..930d7b60 100644 --- a/GitHubRepositoryTraffic.ps1 +++ b/GitHubRepositoryTraffic.ps1 @@ -107,7 +107,7 @@ filter Get-GitHubPathTraffic { <# .SYNOPSIS - Get the top 10 popular contents over the last 14 days for a given Github repository. + Get the top 10 popular contents over the last 14 days for a given GitHub repository. .DESCRIPTION Get the top 10 popular contents over the last 14 days for a given GitHub repository. @@ -200,7 +200,7 @@ filter Get-GitHubViewTraffic { <# .SYNOPSIS - Get the total number of views and breakdown per day or week for the last 14 days for the given Github Repository. + Get the total number of views and breakdown per day or week for the last 14 days for the given GitHub Repository. .DESCRIPTION Get the total number of views and breakdown per day or week for the last 14 days. @@ -301,7 +301,7 @@ filter Get-GitHubCloneTraffic { <# .SYNOPSIS - Get the total number of clones and breakdown per day or week for the last 14 days for the given Github Repository. + Get the total number of clones and breakdown per day or week for the last 14 days for the given GitHub Repository. .DESCRIPTION Get the total number of clones and breakdown per day or week for the last 14 days. diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 71cb8673..870c3510 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -223,27 +223,41 @@ filter Get-GitHubUserContextualInformation $getParams = @() + $contextType = [String]::Empty + $contextId = 0 if ($PSCmdlet.ParameterSetName -ne 'NoContext') { if ($PSCmdlet.ParameterSetName -eq 'Organization') { $getParams += 'subject_type=organization' $getParams += "subject_id=$OrganizationId" + + $contextType = 'OrganizationId' + $contextId = $OrganizationId } elseif ($PSCmdlet.ParameterSetName -eq 'Repository') { $getParams += 'subject_type=repository' $getParams += "subject_id=$RepositoryId" + + $contextType = 'RepositoryId' + $contextId = $RepositoryId } elseif ($PSCmdlet.ParameterSetName -eq 'Issue') { $getParams += 'subject_type=issue' $getParams += "subject_id=$IssueId" + + $contextType = 'IssueId' + $contextId = $IssueId } elseif ($PSCmdlet.ParameterSetName -eq 'PullRequest') { $getParams += 'subject_type=pull_request' $getParams += "subject_id=$PullRequestId" + + $contextType = 'PullRequestId' + $contextId = $PullRequestId } } @@ -257,8 +271,22 @@ filter Get-GitHubUserContextualInformation 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethod @params | - Add-GitHubUserAdditionalProperties -TypeName $script:GitHubUserContextualInformationTypeName -Name $UserName) + $result = Invoke-GHRestMethod @params + foreach ($item in $result.contexts) + { + $item.PSObject.TypeNames.Insert(0, $script:GitHubUserContextualInformationTypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + Add-Member -InputObject $item -Name 'UserName' -Value $UserName -MemberType NoteProperty -Force + if ($PSCmdlet.ParameterSetName -ne 'NoContext') + { + Add-Member -InputObject $item -Name $contextType -Value $contextId -MemberType NoteProperty -Force + } + } + } + + return $result } function Update-GitHubCurrentUser diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index 750fd498..d100478c 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -100,7 +100,7 @@ 'Move-GitHubProjectCard', 'Move-GitHubProjectColumn', 'Move-GitHubRepositoryOwnership', - 'New-GithubAssignee', + 'New-GitHubAssignee', 'New-GitHubComment', 'New-GitHubIssue', 'New-GitHubLabel', @@ -111,7 +111,7 @@ 'New-GitHubPullRequest', 'New-GitHubRepository', 'New-GitHubRepositoryFork', - 'Remove-GithubAssignee', + 'Remove-GitHubAssignee', 'Remove-GitHubComment', 'Remove-GitHubIssueLabel', 'Remove-GitHubLabel', diff --git a/Tests/GitHubAssignees.tests.ps1 b/Tests/GitHubAssignees.tests.ps1 index d6b46954..199617e9 100644 --- a/Tests/GitHubAssignees.tests.ps1 +++ b/Tests/GitHubAssignees.tests.ps1 @@ -63,14 +63,14 @@ try Context 'For adding an assignee to an issue'{ $assigneeList = @(Get-GitHubAssignee -Uri $repo.RepositoryUrl) $assignees = $assigneeList[0].UserName - $null = New-GithubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Assignee $assignees + $null = New-GitHubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Assignee $assignees $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.number It 'Should have assigned the user to the issue' { $issue.assignee.login | Should -Be $assigneeUserName } - Remove-GithubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Assignee $assignees -Confirm:$false + Remove-GitHubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Assignee $assignees -Confirm:$false $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.number It 'Should have removed the user from issue' { @@ -101,14 +101,14 @@ try Context 'For adding an assignee to an issue - pipe in the repo'{ $assigneeList = @($repo | Get-GitHubAssignee) $assignees = $assigneeList[0].UserName - $null = $repo | New-GithubAssignee -Issue $issue.IssueNumber -Assignee $assignees + $null = $repo | New-GitHubAssignee -Issue $issue.IssueNumber -Assignee $assignees $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.number It 'Should have assigned the user to the issue' { $issue.assignee.UserName | Should -Be $assigneeUserName } - $repo | Remove-GithubAssignee -Issue $issue.IssueNumber -Assignee $assignees -Confirm:$false + $repo | Remove-GitHubAssignee -Issue $issue.IssueNumber -Assignee $assignees -Confirm:$false $issue = $repo | Get-GitHubIssue -Issue $issue.IssueNumber It 'Should have removed the user from issue' { @@ -119,14 +119,14 @@ try Context 'For adding an assignee to an issue - pipe in the issue'{ $assigneeList = @(Get-GitHubAssignee -Uri $repo.RepositoryUrl) $assignees = $assigneeList[0].UserName - $null = $issue | New-GithubAssignee -Assignee $assignees + $null = $issue | New-GitHubAssignee -Assignee $assignees $issue = $issue | Get-GitHubIssue It 'Should have assigned the user to the issue' { $issue.assignee.UserName | Should -Be $assigneeUserName } - $issue | Remove-GithubAssignee -Assignee $assignees -Confirm:$false + $issue | Remove-GitHubAssignee -Assignee $assignees -Confirm:$false $issue = $issue | Get-GitHubIssue It 'Should have removed the user from issue' { @@ -137,14 +137,14 @@ try Context 'For adding an assignee to an issue - pipe in the assignee'{ $assigneeList = @(Get-GitHubAssignee -Uri $repo.RepositoryUrl) $assignees = $assigneeList[0].UserName - $null = $assignees | New-GithubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number + $null = $assignees | New-GitHubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.IssueNumber It 'Should have assigned the user to the issue' { $issue.assignee.UserName | Should -Be $assigneeUserName } - $assignees | Remove-GithubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Confirm:$false + $assignees | Remove-GitHubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Confirm:$false $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.IssueNumber It 'Should have removed the user from issue' { diff --git a/Tests/GitHubEvents.tests.ps1 b/Tests/GitHubEvents.tests.ps1 index d9337103..9466c1f3 100644 --- a/Tests/GitHubEvents.tests.ps1 +++ b/Tests/GitHubEvents.tests.ps1 @@ -27,7 +27,7 @@ try } } - $issue = New-GithubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" + $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed Context 'For getting events from a repository' { @@ -44,7 +44,7 @@ try Describe 'Getting events from an issue' { $repositoryName = [Guid]::NewGuid() $null = New-GitHubRepository -RepositoryName $repositoryName - $issue = New-GithubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" + $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" Context 'For getting events from a new issue' { $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) @@ -70,7 +70,7 @@ try Describe 'Getting an event directly' { $repositoryName = [Guid]::NewGuid() $null = New-GitHubRepository -RepositoryName $repositoryName - $issue = New-GithubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" + $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Open $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index a3d55243..4b338424 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -715,6 +715,14 @@ try It 'Should contain PowerShell' { $languages = Get-GitHubRepositoryLanguage -OwnerName "microsoft" -RepositoryName "PowerShellForGitHub" $languages.PowerShell | Should -Not -BeNullOrEmpty + $languages.PSObject.TypeNames[0] | Should -Be 'GitHub.RepositoryLanguage' + } + + It 'Should contain PowerShell (via pipeline)' { + $psfg = Get-GitHubRepository -OwnerName "microsoft" -RepositoryName "PowerShellForGitHub" + $languages = $psfg | Get-GitHubRepositoryLanguage + $languages.PowerShell | Should -Not -BeNullOrEmpty + $languages.PSObject.TypeNames[0] | Should -Be 'GitHub.RepositoryLanguage' } AfterAll -ScriptBlock { @@ -735,6 +743,11 @@ try $tags | Should -BeNullOrEmpty } + It 'Should be empty (via pipeline)' { + $tags = $repo | Get-GitHubRepositoryTag + $tags | Should -BeNullOrEmpty + } + AfterAll -ScriptBlock { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -758,6 +771,7 @@ try It 'Should return expected number of contributors' { $contributors.Count | Should -Be 1 + #$contributors[0].PSObject.TypeName = 'GitHub.User' } It 'Should return expected number of unique contributors' { @@ -769,6 +783,15 @@ try $uniqueContributors.Count | Should -Be 1 } } + + Context -Name 'Obtaining contributors for repository (via pipeline)' -Fixture { + $contributors = @($repo | Get-GitHubRepositoryContributor -IncludeStatistics) + + It 'Should return expected number of contributors' { + $contributors.Count | Should -Be 1 + #$contributors[0].PSObject.TypeName = 'GitHub.User' + } + } } Describe 'Collaborators for a repository' { @@ -788,6 +811,26 @@ try It 'Should return expected number of collaborators' { $collaborators.Count | Should -Be 1 + $collaborators[0].PSObject.TypeName = 'GitHub.User' + } + } + + Context -Name 'Obtaining collaborator statistics for repository' -Fixture { + $stats = @(Get-GitHubRepositoryCollaborator -Uri $repo.RepositoryUrl -IncludeStatistics) + + It 'Should return expected number of collaborators' { + $stats.Count | Should -Be 1 + $stats[0].PSObject.TypeName = 'GitHub.RepositoryContributorStatistics' + $stats[0].author.PSObject.TypeName = 'GitHub.User' + } + } + + Context -Name 'Obtaining collaborators for repository (via pipeline)' -Fixture { + $collaborators = @($repo | Get-GitHubRepositoryCollaborator) + + It 'Should return expected number of collaborators' { + $collaborators.Count | Should -Be 1 + $collaborators[0].PSObject.TypeName = 'GitHub.User' } } } diff --git a/Tests/GitHubUsers.tests.ps1 b/Tests/GitHubUsers.tests.ps1 index 0df4eed7..73448669 100644 --- a/Tests/GitHubUsers.tests.ps1 +++ b/Tests/GitHubUsers.tests.ps1 @@ -105,12 +105,14 @@ try It 'Should indicate ownership with the username on the pipeline' { $context = $script:ownerName | Get-GitHubUserContextualInformation -RepositoryId $repo.id 'Owns this repository' | Should -BeIn $context.contexts.message + $context.contexts[0].PSObject.TypeNames[0] | Should -Be 'GitHub.UserContextualInformation' } It 'Should indicate ownership with the user on the pipeline' { $user = Get-GitHubUser -UserName $script:ownerName $context = $user | Get-GitHubUserContextualInformation -RepositoryId $repo.id 'Owns this repository' | Should -BeIn $context.contexts.message + $context.contexts[0].PSObject.TypeNames[0] | Should -Be 'GitHub.UserContextualInformation' } } @@ -120,10 +122,13 @@ try It 'Should indicate the user created the issue' { $context.contexts[0].octicon | Should -Be 'issue-opened' + $context.contexts[0].IssueId | Should -Be $issue.IssueId + $context.contexts[0].PSObject.TypeNames[0] | Should -Be 'GitHub.UserContextualInformation' } It 'Should indicate the user owns the repository' { $context.contexts[1].message | Should -Be 'Owns this repository' + $context.contexts[1].PSObject.TypeNames[0] | Should -Be 'GitHub.UserContextualInformation' } } } diff --git a/USAGE.md b/USAGE.md index b386b674..f1363af1 100644 --- a/USAGE.md +++ b/USAGE.md @@ -417,12 +417,12 @@ $HasPermission = Test-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerS #### Add assignee to an issue ```powershell -New-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1 +New-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1 ``` #### Remove assignee from an issue ```powershell -Remove-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1 +Remove-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1 ``` ---------- From 3d4fca5873aa5e60bc863a84f6f4f5a2949b88df Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 9 Jun 2020 15:15:21 -0700 Subject: [PATCH 29/80] Updated releases tests for pipelining --- GitHubReleases.ps1 | 17 ++++++------ Tests/GitHubReleases.tests.ps1 | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index d86e24f6..fff51d80 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -31,8 +31,8 @@ filter Get-GitHubRelease The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER ReleaseId - Specific releaseId of a release. + .PARAMETER Release + The ID of a specific release. This is an optional parameter which can limit the results to a single release. .PARAMETER Latest @@ -62,7 +62,7 @@ filter Get-GitHubRelease Gets all releases for the default configured owner/repository. .EXAMPLE - Get-GitHubRelease -ReleaseId 12345 + Get-GitHubRelease -Release 12345 Get a specific release for the default configured owner/repository @@ -143,7 +143,8 @@ filter Get-GitHubRelease Mandatory, ValueFromPipelineByPropertyName, ParameterSetName="Uri-ReleaseId")] - [string] $ReleaseId, + [Alias('ReleaseId')] + [int64] $Release, [Parameter( Mandatory, @@ -180,12 +181,12 @@ filter Get-GitHubRelease $uriFragment = "repos/$OwnerName/$RepositoryName/releases" $description = "Getting releases for $OwnerName/$RepositoryName" - if(-not [String]::IsNullOrEmpty($ReleaseId)) + if ($PSBoundParameters.ContainsKey('Release')) { - $telemetryProperties['ProvidedReleaseId'] = $true + $telemetryProperties['ProvidedRelease'] = $true - $uriFragment += "/$ReleaseId" - $description = "Getting release information for $ReleaseId from $OwnerName/$RepositoryName" + $uriFragment += "/$Release" + $description = "Getting release information for $Release from $OwnerName/$RepositoryName" } if($Latest) diff --git a/Tests/GitHubReleases.tests.ps1 b/Tests/GitHubReleases.tests.ps1 index 00854478..b0594284 100644 --- a/Tests/GitHubReleases.tests.ps1 +++ b/Tests/GitHubReleases.tests.ps1 @@ -21,6 +21,12 @@ try It 'Should return multiple releases' { $releases.Count | Should -BeGreaterThan 1 } + + It 'Should have expected type and additional properties' { + $releases[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' + $releases[0].html_url.StartsWith($releases[0].RepositoryUrl) | Should -BeTrue + $releases[0].id | Should -Be $releases[0].ReleaseId + } } Context 'When getting the latest releases' { @@ -34,6 +40,36 @@ try $latest[0].url | Should -Be $releases[0].url $latest[0].name | Should -Be $releases[0].name } + + It 'Should have expected type and additional properties' { + $latest[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' + $latest[0].html_url.StartsWith($latest[0].RepositoryUrl) | Should -BeTrue + $latest[0].id | Should -Be $latest[0].ReleaseId + } + } + + Context 'When getting the latest releases via the pipeline' { + $latest = @($repo | Get-GitHubRelease -Latest) + + It 'Should return one value' { + $latest.Count | Should -Be 1 + } + + It 'Should return the first release from the full releases list' { + $latest[0].url | Should -Be $releases[0].url + $latest[0].name | Should -Be $releases[0].name + } + + It 'Should have expected type and additional properties' { + $latest[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' + $latest[0].html_url.StartsWith($latest[0].RepositoryUrl) | Should -BeTrue + $latest[0].id | Should -Be $latest[0].ReleaseId + } + + $latestAgain = @($latest | Get-GitHubRelease) + It 'Should be the same release' { + $latest[0].ReleaseId | Should -Be $latestAgain[0].ReleaseId + } } Context 'When getting a specific release' { @@ -47,6 +83,12 @@ try It 'Should return the correct release' { $specific.name | Should -Be $releases[$specificIndex].name } + + It 'Should have expected type and additional properties' { + $specific[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' + $specific[0].html_url.StartsWith($specific[0].RepositoryUrl) | Should -BeTrue + $specific[0].id | Should -Be $specific[0].ReleaseId + } } Context 'When getting a tagged release' { @@ -60,6 +102,12 @@ try It 'Should return the correct release' { $tagged.name | Should -Be $releases[$taggedIndex].name } + + It 'Should have expected type and additional properties' { + $tagged[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' + $tagged[0].html_url.StartsWith($tagged[0].RepositoryUrl) | Should -BeTrue + $tagged[0].id | Should -Be $tagged[0].ReleaseId + } } } From 5e9f7a39c499773fd1c9d4b6993166ce8a689ce9 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 9 Jun 2020 15:20:09 -0700 Subject: [PATCH 30/80] Fixing releases and tests --- GitHubReleases.ps1 | 2 +- Tests/GitHubReleases.tests.ps1 | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index fff51d80..04b52641 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -219,7 +219,7 @@ filter Get-GitHubRelease } -filter Add-GitHubRepositoryAdditionalProperties +filter Add-GitHubReleaseAdditionalProperties { <# .SYNOPSIS diff --git a/Tests/GitHubReleases.tests.ps1 b/Tests/GitHubReleases.tests.ps1 index b0594284..ee2e6fda 100644 --- a/Tests/GitHubReleases.tests.ps1 +++ b/Tests/GitHubReleases.tests.ps1 @@ -49,7 +49,8 @@ try } Context 'When getting the latest releases via the pipeline' { - $latest = @($repo | Get-GitHubRelease -Latest) + $latest = @(Get-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName | + Get-GitHubRelease -Latest) It 'Should return one value' { $latest.Count | Should -Be 1 From cd27d4f74045c88ec1ef1babff3a63e073c135d4 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 9 Jun 2020 15:59:45 -0700 Subject: [PATCH 31/80] Fixing some repository issues --- GitHubRepositories.ps1 | 2 +- Tests/GitHubRepositories.tests.ps1 | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 6a76a479..f4c91bf4 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -1379,7 +1379,7 @@ filter Get-GitHubRepositoryContributor if ($IncludeStatistics) { - foreach ($item in $InputObject) + foreach ($item in $results) { $item.PSObject.TypeNames.Insert(0, $script:GitHubRepositoryContributorStatisticsTypeName) diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 4b338424..e873924e 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -789,7 +789,17 @@ try It 'Should return expected number of contributors' { $contributors.Count | Should -Be 1 - #$contributors[0].PSObject.TypeName = 'GitHub.User' + $contributors[0].PSObject.TypeNames[0] = 'GitHub.User' + } + } + + Context -Name 'Obtaining collaborator statistics for repository' -Fixture { + $stats = @(Get-GitHubRepositoryContributor -Uri $repo.RepositoryUrl -IncludeStatistics) + + It 'Should return expected number of contributors' { + $stats.Count | Should -Be 1 + $stats[0].PSObject.TypeNames[0] = 'GitHub.RepositoryContributorStatistics' + $stats[0].author.PSObject.TypeNames[0] = 'GitHub.User' } } } @@ -811,17 +821,7 @@ try It 'Should return expected number of collaborators' { $collaborators.Count | Should -Be 1 - $collaborators[0].PSObject.TypeName = 'GitHub.User' - } - } - - Context -Name 'Obtaining collaborator statistics for repository' -Fixture { - $stats = @(Get-GitHubRepositoryCollaborator -Uri $repo.RepositoryUrl -IncludeStatistics) - - It 'Should return expected number of collaborators' { - $stats.Count | Should -Be 1 - $stats[0].PSObject.TypeName = 'GitHub.RepositoryContributorStatistics' - $stats[0].author.PSObject.TypeName = 'GitHub.User' + $collaborators[0].PSObject.TypeNames[0] = 'GitHub.User' } } @@ -830,7 +830,7 @@ try It 'Should return expected number of collaborators' { $collaborators.Count | Should -Be 1 - $collaborators[0].PSObject.TypeName = 'GitHub.User' + $collaborators[0].PSObject.TypeNames[0] = 'GitHub.User' } } } From c5f9b3e8d8416f5231d599f1ec0770661e762883 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 9 Jun 2020 23:38:04 -0700 Subject: [PATCH 32/80] Migrate from PSUseDeclaredVarsMoreThanAssignments workaround to Set-StrictMode --- Tests/Common.ps1 | 9 +++++ Tests/GitHubAnalytics.tests.ps1 | 5 +++ Tests/GitHubAssignees.tests.ps1 | 17 +++------- Tests/GitHubBranches.tests.ps1 | 5 +++ Tests/GitHubComments.tests.ps1 | 5 +++ Tests/GitHubContents.tests.ps1 | 5 +++ Tests/GitHubCore.Tests.ps1 | 9 ++--- Tests/GitHubEvents.tests.ps1 | 5 +++ Tests/GitHubIssues.tests.ps1 | 12 +++---- Tests/GitHubLabels.tests.ps1 | 5 +++ Tests/GitHubMilestones.tests.ps1 | 5 +++ Tests/GitHubProjectCards.tests.ps1 | 23 +++---------- Tests/GitHubProjectColumns.tests.ps1 | 18 +++------- Tests/GitHubProjects.tests.ps1 | 44 +++---------------------- Tests/GitHubReleases.tests.ps1 | 5 +++ Tests/GitHubRepositories.tests.ps1 | 12 ------- Tests/GitHubRepositoryTraffic.tests.ps1 | 17 +++------- Tests/GitHubUsers.tests.ps1 | 20 +++-------- 18 files changed, 89 insertions(+), 132 deletions(-) diff --git a/Tests/Common.ps1 b/Tests/Common.ps1 index f28dc534..2e5d5512 100644 --- a/Tests/Common.ps1 +++ b/Tests/Common.ps1 @@ -1,6 +1,15 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +# PSScriptAnalyzer incorrectly flags a number of variables as PSUseDeclaredVarsMoreThanAssignments +# since it doesn't work well with variables defined in BeforeAll{} but only referenced in a later Context. +# We are suppressing that rule in Test files, which means that we are then losing out on catching +# scenarios where we might be assigning to a variable and then referencing it with a typo. +# By setting StrictMode, the test file will immediately fail if there are any variables that are +# being referenced before they were assigned. It won't catch variables that are assigned to but +# never referenced, but that's not as big of a deal for tests. +Set-StrictMode -Version 1.0 + # Caches if the tests are actively configured with an access token. $script:accessTokenConfigured = $false diff --git a/Tests/GitHubAnalytics.tests.ps1 b/Tests/GitHubAnalytics.tests.ps1 index 9282dddc..5529c26b 100644 --- a/Tests/GitHubAnalytics.tests.ps1 +++ b/Tests/GitHubAnalytics.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubAnalytics.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') diff --git a/Tests/GitHubAssignees.tests.ps1 b/Tests/GitHubAssignees.tests.ps1 index 199617e9..25f74af3 100644 --- a/Tests/GitHubAssignees.tests.ps1 +++ b/Tests/GitHubAssignees.tests.ps1 @@ -6,6 +6,11 @@ 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') @@ -16,9 +21,6 @@ try BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit $issue = New-GitHubIssue -Uri $repo.RepositoryUrl -Title "Test issue" - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $issue = $issue } AfterAll { @@ -51,9 +53,6 @@ try BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit $issue = New-GitHubIssue -Uri $repo.RepositoryUrl -Title "Test issue" - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $issue = $issue } AfterAll { @@ -82,16 +81,10 @@ try Describe 'Adding and removing an assignee to an issue via the pipeline'{ BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } BeforeEach { $issue = New-GitHubIssue -Uri $repo.RepositoryUrl -Title "Test issue" - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $issue = $issue } AfterAll { diff --git a/Tests/GitHubBranches.tests.ps1 b/Tests/GitHubBranches.tests.ps1 index 2bf8b593..6fa36a20 100644 --- a/Tests/GitHubBranches.tests.ps1 +++ b/Tests/GitHubBranches.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubBranches.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') diff --git a/Tests/GitHubComments.tests.ps1 b/Tests/GitHubComments.tests.ps1 index 5525a538..1a9348e3 100644 --- a/Tests/GitHubComments.tests.ps1 +++ b/Tests/GitHubComments.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubComments.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') diff --git a/Tests/GitHubContents.tests.ps1 b/Tests/GitHubContents.tests.ps1 index 07c1090e..3685a552 100644 --- a/Tests/GitHubContents.tests.ps1 +++ b/Tests/GitHubContents.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubContents.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') diff --git a/Tests/GitHubCore.Tests.ps1 b/Tests/GitHubCore.Tests.ps1 index f0b3f33a..cb6c3533 100644 --- a/Tests/GitHubCore.Tests.ps1 +++ b/Tests/GitHubCore.Tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubCore.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') @@ -200,10 +205,6 @@ try BeforeAll { $repositoryName = [guid]::NewGuid().Guid $url = "https://github.com/$script:ownerName/$repositoryName" - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repositoryName = $repositoryName - $url = $url } Context 'For getting the OwnerName' { diff --git a/Tests/GitHubEvents.tests.ps1 b/Tests/GitHubEvents.tests.ps1 index 9466c1f3..8976fd8c 100644 --- a/Tests/GitHubEvents.tests.ps1 +++ b/Tests/GitHubEvents.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubEvents.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') diff --git a/Tests/GitHubIssues.tests.ps1 b/Tests/GitHubIssues.tests.ps1 index 3fe63a0d..985aa82b 100644 --- a/Tests/GitHubIssues.tests.ps1 +++ b/Tests/GitHubIssues.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubIssues.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') @@ -18,9 +23,6 @@ try Describe 'Obtaining issues for repository' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } AfterAll { @@ -85,10 +87,6 @@ try BeforeAll { $repo1 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit $repo2 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo1 = $repo1 - $repo2 = $repo2 } AfterAll { diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index e5630896..744f3455 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubLabels.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') diff --git a/Tests/GitHubMilestones.tests.ps1 b/Tests/GitHubMilestones.tests.ps1 index 6c1c9033..0f07dc75 100644 --- a/Tests/GitHubMilestones.tests.ps1 +++ b/Tests/GitHubMilestones.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubMilestones.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') diff --git a/Tests/GitHubProjectCards.tests.ps1 b/Tests/GitHubProjectCards.tests.ps1 index 2854ee63..9c2d4075 100644 --- a/Tests/GitHubProjectCards.tests.ps1 +++ b/Tests/GitHubProjectCards.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubProjectCards.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') @@ -41,10 +46,6 @@ try $card = New-GitHubProjectCard -Column $column.id -Note $defaultCard $cardArchived = New-GitHubProjectCard -Column $column.id -Note $defaultArchivedCard $null = Set-GitHubProjectCard -Card $cardArchived.id -Archive - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $card = $card - $cardArchived = $cardArchived } AfterAll { @@ -90,11 +91,6 @@ try $card = New-GitHubProjectCard -Column $column.id -Note $defaultCard $cardTwo = New-GitHubProjectCard -Column $column.id -Note $defaultCardTwo $cardArchived = New-GitHubProjectCard -Column $column.id -Note $defaultArchivedCard - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $card = $card - $cardTwo = $cardTwo - $cardArchived = $cardArchived } AfterAll { @@ -178,9 +174,6 @@ try Context 'Create project card with note' { BeforeAll { $card = @{id = 0} - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $card = $card } AfterAll { @@ -203,9 +196,6 @@ try Context 'Create project card from issue' { BeforeAll { $card = @{id = 0} - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $card = $card } AfterAll { @@ -230,9 +220,6 @@ try Context 'Remove card' { BeforeAll { $card = New-GitHubProjectCard -Column $column.id -Note $defaultCard - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $card = $card } $null = Remove-GitHubProjectCard -Card $card.id -Confirm:$false diff --git a/Tests/GitHubProjectColumns.tests.ps1 b/Tests/GitHubProjectColumns.tests.ps1 index 9df03d04..6ce4a009 100644 --- a/Tests/GitHubProjectColumns.tests.ps1 +++ b/Tests/GitHubProjectColumns.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubProjectColumns.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 Describe 'Getting Project Columns' { BeforeAll { $column = New-GitHubProjectColumn -Project $project.id -Name $defaultColumn - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $column = $column } AfterAll { @@ -56,10 +58,6 @@ try BeforeAll { $column = New-GitHubProjectColumn -Project $project.id -Name $defaultColumn $columntwo = New-GitHubProjectColumn -Project $project.id -Name $defaultColumnTwo - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $column = $column - $columnTwo = $columnTwo } AfterAll { @@ -113,9 +111,6 @@ try Context 'Create project column' { BeforeAll { $column = @{id = 0} - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $column = $column } AfterAll { @@ -140,9 +135,6 @@ try Context 'Remove project column' { BeforeAll { $column = New-GitHubProjectColumn -Project $project.id -Name $defaultColumn - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $column = $column } $null = Remove-GitHubProjectColumn -Column $column.id -Confirm:$false diff --git a/Tests/GitHubProjects.tests.ps1 b/Tests/GitHubProjects.tests.ps1 index 4d88eee1..eb896542 100644 --- a/Tests/GitHubProjects.tests.ps1 +++ b/Tests/GitHubProjects.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubProjects.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') @@ -38,9 +43,6 @@ try Context 'Get User projects' { BeforeAll { $project = New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $project = $project } AfterAll { @@ -68,9 +70,6 @@ try Context 'Get Organization projects' { BeforeAll { $project = New-GitHubProject -OrganizationName $script:organizationName -Name $defaultOrgProject -Description $defaultOrgProjectDesc - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $project = $project } AfterAll { @@ -98,9 +97,6 @@ try Context 'Get Repo projects' { BeforeAll { $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultRepoProject -Description $defaultRepoProjectDesc - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $project = $project } AfterAll { @@ -129,9 +125,6 @@ try BeforeAll { $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultProjectClosed -Description $defaultProjectClosedDesc $null = Set-GitHubProject -Project $project.id -State Closed - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $project = $project } AfterAll { @@ -165,9 +158,6 @@ try Context 'Modify User projects' { BeforeAll { $project = New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $project = $project } AfterAll { @@ -192,9 +182,6 @@ try Context 'Modify Organization projects' { BeforeAll { $project = New-GitHubProject -OrganizationName $script:organizationName -Name $defaultOrgProject -Description $defaultOrgProjectDesc - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $project = $project } AfterAll { @@ -228,9 +215,6 @@ try Context 'Modify Repo projects' { BeforeAll { $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultRepoProject -Description $defaultRepoProjectDesc - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $project = $project } AfterAll { @@ -257,9 +241,6 @@ try Context 'Create User projects' { BeforeAll { $project = @{id = 0} - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $project = $project } AfterAll { @@ -285,9 +266,6 @@ try Context 'Create Organization projects' { BeforeAll { $project = @{id = 0} - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $project = $project } AfterAll { @@ -313,9 +291,6 @@ try Context 'Create Repo projects' { BeforeAll { $project = @{id = 0} - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $project = $project } AfterAll { @@ -343,9 +318,6 @@ try Context 'Remove User projects' { BeforeAll { $project = New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $project = $project } $null = Remove-GitHubProject -Project $project.id -Force @@ -357,9 +329,6 @@ try Context 'Remove Organization projects' { BeforeAll { $project = New-GitHubProject -OrganizationName $script:organizationName -Name $defaultOrgProject -Description $defaultOrgProjectDesc - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $project = $project } $null = Remove-GitHubProject -Project $project.id -Force @@ -371,9 +340,6 @@ try Context 'Remove Repo projects' { BeforeAll { $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultRepoProject -Description $defaultRepoProjectDesc - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $project = $project } $null = Remove-GitHubProject -Project $project.id -Confirm:$false diff --git a/Tests/GitHubReleases.tests.ps1 b/Tests/GitHubReleases.tests.ps1 index ee2e6fda..10c1b42a 100644 --- a/Tests/GitHubReleases.tests.ps1 +++ b/Tests/GitHubReleases.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubReleases.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') diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index e873924e..14ea530a 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -571,9 +571,6 @@ try Context 'For authenticated user' { BeforeAll -Scriptblock { $repo = ([Guid]::NewGuid().Guid) | New-GitHubRepository -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } It "Should have expected additional properties and type after creation" { @@ -608,9 +605,6 @@ try BeforeAll -Scriptblock { $org = [PSCustomObject]@{'OrganizationName' = $script:organizationName} $repo = $org | New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } It "Should have expected additional properties and type after creation" { @@ -757,9 +751,6 @@ try Describe 'Contributors for a repository' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } AfterAll { @@ -807,9 +798,6 @@ try Describe 'Collaborators for a repository' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } AfterAll { diff --git a/Tests/GitHubRepositoryTraffic.tests.ps1 b/Tests/GitHubRepositoryTraffic.tests.ps1 index 6383565d..39d8aa32 100644 --- a/Tests/GitHubRepositoryTraffic.tests.ps1 +++ b/Tests/GitHubRepositoryTraffic.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubRepositoryTraffic.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') @@ -15,9 +20,6 @@ try Describe 'Testing the referrer traffic on a repository' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } AfterAll { @@ -40,9 +42,6 @@ try Describe 'Testing the path traffic on a repository' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } AfterAll { @@ -65,9 +64,6 @@ try Describe 'Testing the view traffic on a repository' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } AfterAll { @@ -90,9 +86,6 @@ try Describe 'Testing the view traffic on a repository' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } AfterAll { diff --git a/Tests/GitHubUsers.tests.ps1 b/Tests/GitHubUsers.tests.ps1 index 73448669..837455b6 100644 --- a/Tests/GitHubUsers.tests.ps1 +++ b/Tests/GitHubUsers.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubIssues.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') @@ -16,9 +21,6 @@ try Context 'Current user when additional properties are enabled' { BeforeAll { $currentUser = Get-GitHubUser -Current - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $currentUser = $currentUser } It 'Should have the expected type and additional properties' { @@ -32,9 +34,6 @@ try BeforeAll { Set-GitHubConfiguration -DisablePipelineSupport $currentUser = Get-GitHubUser -Current - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $currentUser = $currentUser } AfterAll { @@ -51,9 +50,6 @@ try Context 'Specific user as a parameter' { BeforeAll { $user = Get-GitHubUser -UserName $script:ownerName - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $user = $user } It 'Should have the expected type and additional properties' { @@ -66,9 +62,6 @@ try Context 'Specific user with the pipeline' { BeforeAll { $user = $script:ownerName | Get-GitHubUser - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $user = $user } It 'Should have the expected type and additional properties' { @@ -82,9 +75,6 @@ try Describe 'Getting user context' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } AfterAll { From 0c3e8840ced551595b1890d1908f2cceda05d9cf Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Wed, 10 Jun 2020 00:43:47 -0700 Subject: [PATCH 33/80] Add pull request tests --- GitHubPullRequests.ps1 | 2 +- Tests/GitHubPullRequests.tests.ps1 | 73 ++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 Tests/GitHubPullRequests.tests.ps1 diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index 384a59a7..d392c194 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -453,7 +453,7 @@ filter Add-GitHubPullRequestAdditionalProperties if ($null -ne $item.labels) { - $null = Add-GitHubLabelAdditionalProperties -InputObject $item.label + $null = Add-GitHubLabelAdditionalProperties -InputObject $item.labels } if ($null -ne $item.milestone) diff --git a/Tests/GitHubPullRequests.tests.ps1 b/Tests/GitHubPullRequests.tests.ps1 new file mode 100644 index 00000000..3da2a09f --- /dev/null +++ b/Tests/GitHubPullRequests.tests.ps1 @@ -0,0 +1,73 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Tests for GitHubPullRequests.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') + +try +{ + Describe 'Getting pull request from repository' { + BeforeAll { + $repo = Get-GitHubRepository -OwnerName 'microsoft' -RepositoryName 'PowerShellForGitHub' + } + + Context 'When getting a pull request' { + $pullRequestNumber = 39 + $pullRequest = Get-GitHubPullRequest -OwnerName 'microsoft' -RepositoryName 'PowerShellForGitHub' -PullRequest $pullRequestNumber + + It 'Should be the expected pull request' { + $pullRequest.number | Should -Be $pullRequestNumber + } + + It 'Should have the expected type and additional properties' { + $elements = Split-GitHubUri -Uri $pullRequest.html_url + $repositoryUrl = Join-GitHubUri @elements + + $pullRequest.PSObject.TypeNames[0] | Should -Be 'GitHub.PullRequest' + $pullRequest.RepositoryUrl | Should -Be $repo.RepositoryUrl + $pullRequest.PullRequestId | Should -Be $pullRequest.id + $pullRequest.PullRequestNumber | Should -Be $pullRequest.number + $pullRequest.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $pullRequest.labels[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $pullRequest.assignee.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $pullRequest.assignees[0].PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $pullRequest.requested_teams[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Team' + $pullRequest.merged_by.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + + It 'Should be refreshable via the pipeline' { + $refresh = $pullRequest | Get-GitHubPullRequest + $refresh.PullRequestNumber | Should -Be $pullRequest.PullRequestNumber + } + + It 'Should be retrievable by passing the repo on the pipeline' { + $pullRequest = $repo | Get-GitHubPullRequest -PullRequest $pullRequestNumber + $pullRequest.number | Should -Be $pullRequestNumber + } + + It 'Should fail when it the pull request does not exist' { + { $repo | Get-GitHubPullRequest -PullRequest 1 } | Should -Throw + } + } + } +} +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 c1d610161b366a75fc0df44f3872a3e9f9c3e379 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Wed, 10 Jun 2020 00:47:33 -0700 Subject: [PATCH 34/80] Fix Organization pipelining --- GitHubOrganizations.ps1 | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/GitHubOrganizations.ps1 b/GitHubOrganizations.ps1 index b5efed27..e93c2c82 100644 --- a/GitHubOrganizations.ps1 +++ b/GitHubOrganizations.ps1 @@ -38,12 +38,16 @@ filter Get-GitHubOrganizationMember .EXAMPLE Get-GitHubOrganizationMember -OrganizationName PowerShell #> + [CmdletBinding(SupportsShouldProcess)] + [OutputType({$script:GitHubUserTypeName})] [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.")] - [CmdletBinding(SupportsShouldProcess)] param ( - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [String] $OrganizationName, @@ -103,17 +107,21 @@ function Test-GitHubOrganizationMember .EXAMPLE Test-GitHubOrganizationMember -OrganizationName PowerShell -UserName Octocat #> - [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.")] [CmdletBinding(SupportsShouldProcess)] [OutputType([bool])] + [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)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [String] $OrganizationName, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [String] $UserName, From d71a5f504c24a4dea6d18f714107ef5463a120a9 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Wed, 10 Jun 2020 01:14:11 -0700 Subject: [PATCH 35/80] Add templates for missing test files with TODO's --- Tests/GitHubMiscellaneous.tests.ps1 | 30 +++++++++++++++++++++++++++++ Tests/GitHubOrganizations.tests.ps1 | 30 +++++++++++++++++++++++++++++ Tests/GitHubTeams.tests.ps1 | 30 +++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 Tests/GitHubMiscellaneous.tests.ps1 create mode 100644 Tests/GitHubOrganizations.tests.ps1 create mode 100644 Tests/GitHubTeams.tests.ps1 diff --git a/Tests/GitHubMiscellaneous.tests.ps1 b/Tests/GitHubMiscellaneous.tests.ps1 new file mode 100644 index 00000000..877e4de1 --- /dev/null +++ b/Tests/GitHubMiscellaneous.tests.ps1 @@ -0,0 +1,30 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Tests for GitHubMiscellaneous.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') + +try +{ + # TODO +} +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 + } +} diff --git a/Tests/GitHubOrganizations.tests.ps1 b/Tests/GitHubOrganizations.tests.ps1 new file mode 100644 index 00000000..2fbf5fee --- /dev/null +++ b/Tests/GitHubOrganizations.tests.ps1 @@ -0,0 +1,30 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Tests for GitHubOrganizations.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') + +try +{ + # TODO once more capabilities exist in the module's API set +} +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 + } +} diff --git a/Tests/GitHubTeams.tests.ps1 b/Tests/GitHubTeams.tests.ps1 new file mode 100644 index 00000000..21658992 --- /dev/null +++ b/Tests/GitHubTeams.tests.ps1 @@ -0,0 +1,30 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Tests for GitHubTeams.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') + +try +{ + # TODO once more capabilities exist in the module's API set +} +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 7ef504397efef1812b57e63d32d39cff8e6bdd3d Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Wed, 10 Jun 2020 15:12:54 -0700 Subject: [PATCH 36/80] Fix forks test names --- GitHubOrganizations.ps1 | 2 +- Tests/GitHubAnalytics.tests.ps1 | 93 --------------------------------- 2 files changed, 1 insertion(+), 94 deletions(-) diff --git a/GitHubOrganizations.ps1 b/GitHubOrganizations.ps1 index e93c2c82..f5db66f9 100644 --- a/GitHubOrganizations.ps1 +++ b/GitHubOrganizations.ps1 @@ -74,7 +74,7 @@ filter Get-GitHubOrganizationMember return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubUserAdditionalProperties) } -function Test-GitHubOrganizationMember +filter Test-GitHubOrganizationMember { <# .SYNOPSIS diff --git a/Tests/GitHubAnalytics.tests.ps1 b/Tests/GitHubAnalytics.tests.ps1 index 5529c26b..4a8cd49a 100644 --- a/Tests/GitHubAnalytics.tests.ps1 +++ b/Tests/GitHubAnalytics.tests.ps1 @@ -17,99 +17,6 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { -<<<<<<< HEAD - Describe 'Obtaining issues for repository' { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - Context 'When initially created, there are no issues' { - $issues = @(Get-GitHubIssue -Uri $repo.svn_url) - - It 'Should return expected number of issues' { - $issues.Count | Should be 0 - } - } - - Context 'When there are issues present' { - $newIssues = @() - for ($i = 0; $i -lt 4; $i++) - { - $newIssues += New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid().Guid) - } - - $newIssues[0] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[0].number -State Closed - $newIssues[-1] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[-1].number -State Closed - - $issues = @(Get-GitHubIssue -Uri $repo.svn_url) - It 'Should return only open issues' { - $issues.Count | Should be 2 - } - - $issues = @(Get-GitHubIssue -Uri $repo.svn_url -State All) - It 'Should return all issues' { - $issues.Count | Should be 4 - } - - $createdOnOrAfterDate = Get-Date -Date $newIssues[0].created_at - $createdOnOrBeforeDate = Get-Date -Date $newIssues[2].created_at - $issues = @((Get-GitHubIssue -Uri $repo.svn_url) | Where-Object { ($_.created_at -ge $createdOnOrAfterDate) -and ($_.created_at -le $createdOnOrBeforeDate) }) - - It 'Smart object date conversion works for comparing dates' { - $issues.Count | Should be 2 - } - - $createdDate = Get-Date -Date $newIssues[1].created_at - $issues = @(Get-GitHubIssue -Uri $repo.svn_url -State All | Where-Object { ($_.created_at -ge $createdDate) -and ($_.state -eq 'closed') }) - - It 'Able to filter based on date and state' { - $issues.Count | Should be 1 - } - } - - Context 'When issues are retrieved with a specific MediaTypes' { - $newIssue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid()) -Body ([guid]::NewGuid()) - - $issues = @(Get-GitHubIssue -Uri $repo.svn_url -Issue $newIssue.number -MediaType 'Html') - It 'Should return an issue with body_html' { - $issues[0].body_html | Should not be $null - } - } - - $null = Remove-GitHubRepository -Uri ($repo.svn_url) -Confirm:$false - } - - Describe 'Obtaining repository with biggest number of issues' { - $repo1 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - $repo2 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - Context 'When no additional conditions specified' { - for ($i = 0; $i -lt 3; $i++) - { - $null = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo1.name -Title ([guid]::NewGuid().Guid) - } - - $repos = @(($repo1.svn_url), ($repo2.svn_url)) - $issueCounts = @() - $repos | ForEach-Object { $issueCounts = $issueCounts + ([PSCustomObject]@{ 'Uri' = $_; 'Count' = (Get-GitHubIssue -Uri $_).Count }) } - $issueCounts = $issueCounts | Sort-Object -Property Count -Descending - - It 'Should return expected number of issues for each repository' { - $issueCounts[0].Count | Should be 3 - $issueCounts[1].Count | Should be 0 - } - - It 'Should return expected repository names' { - $issueCounts[0].Uri | Should be $repo1.svn_url - $issueCounts[1].Uri | Should be $repo2.svn_url - } - } - - $null = Remove-GitHubRepository -Uri ($repo1.svn_url) -Confirm:$false - $null = Remove-GitHubRepository -Uri ($repo2.svn_url) -Confirm:$false - } - - -======= ->>>>>>> 89bfa42... * [BREAKING CHANGE] Changed signature for Get-GitHubUserContextualInformation to be more natural # TODO: Re-enable these tests once the module has sufficient support getting the repository into the # required state for testing, and to recover back to the original state at the conclusion of the test. From d3fbeab64fbdd46f1b10ca08e1d7eeab8ef277ed Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Wed, 10 Jun 2020 15:19:37 -0700 Subject: [PATCH 37/80] Fixing Get-GitHubUser for specific user --- GitHubUsers.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 870c3510..9698b478 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -104,14 +104,14 @@ filter Get-GitHubUser return (Invoke-GHRestMethod -UriFragment "user" -Description "Getting current authenticated user" -Method 'Get' @params | Add-GitHubUserAdditionalProperties) } - elseif ([String]::IsNullOrEmpty($User)) + elseif ([String]::IsNullOrEmpty($UserName)) { return (Invoke-GHRestMethodMultipleResult -UriFragment 'users' -Description 'Getting all users' @params | Add-GitHubUserAdditionalProperties) } else { - return (Invoke-GHRestMethod -UriFragment "users/$UserName" -Description "Getting user $User" -Method 'Get' @params | + return (Invoke-GHRestMethod -UriFragment "users/$UserName" -Description "Getting user $UserName" -Method 'Get' @params | Add-GitHubUserAdditionalProperties) } } From af3f0a323bef949296fa8439561604434d5a85d3 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Wed, 10 Jun 2020 15:22:17 -0700 Subject: [PATCH 38/80] Re-fixing forks tests after rebase --- Tests/GitHubRepositoryForks.tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/GitHubRepositoryForks.tests.ps1 b/Tests/GitHubRepositoryForks.tests.ps1 index 2c83f60d..45a3e47d 100644 --- a/Tests/GitHubRepositoryForks.tests.ps1 +++ b/Tests/GitHubRepositoryForks.tests.ps1 @@ -70,8 +70,8 @@ try } It 'Should have the expected additional type and properties' { - ourFork.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' - ourFork.RepositoryId | Should -Be $ourFork.id + $ourFork.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' + $ourFork.RepositoryId | Should -Be $ourFork.id } } } From a0f57461f8839c52f2467dbf7d9aefc8e2d36ffb Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Wed, 10 Jun 2020 16:04:02 -0700 Subject: [PATCH 39/80] Rename-GitHubRepository should just directly call Update-GitHubRepository --- GitHubRepositories.ps1 | 51 ++++++++++++------------------ Tests/GitHubRepositories.tests.ps1 | 2 +- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index f4c91bf4..78d8f378 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -761,38 +761,15 @@ filter Rename-GitHubRepository [switch] $NoStatus ) - if ($Force -and (-not $Confirm)) + # This method was created by mistake and is now retained to avoid a breaking change. + # Update-GitHubRepository is able to handle this scenario just fine. + if ($PSBoundParameters.ContainsKey('NewName')) { - $ConfirmPreference = 'None' + $null = $PSBoundParameters.Add('Name', $NewName) + $null = $PSBoundParameters.Remove('NewName') } - $repositoryInfoForDisplayMessage = if ($PSCmdlet.ParameterSetName -eq "Uri") { $Uri } else { $OwnerName, $RepositoryName -join "/" } - if ($PSCmdlet.ShouldProcess($repositoryInfoForDisplayMessage, "Rename repository to '$NewName'")) - { - Write-InvocationLog -Invocation $MyInvocation - $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters - $OwnerName = $elements.ownerName - $RepositoryName = $elements.repositoryName - - $telemetryProperties = @{ - 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) - 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) - } - - $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName" - 'Method' = 'Patch' - 'Body' = ConvertTo-Json -InputObject @{name = $NewName} - 'Description' = "Renaming repository at '$repositoryInfoForDisplayMessage' to '$NewName'" - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) - } - - return (Invoke-GHRestMethod @params | - Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) - } + return Update-GitHubRepository @PSBoundParameters } filter Update-GitHubRepository @@ -868,6 +845,10 @@ filter Update-GitHubRepository Specify this to archive this repository. NOTE: You cannot unarchive repositories through the API / this module. + .PARAMETER Force + If this switch is specified, you will not be prompted for confirmation of command execution + when renaming the repository. + .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. @@ -893,14 +874,15 @@ filter Update-GitHubRepository .EXAMPLE Get-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub | - Update-GitHubRepository -Name 'PoShForGitHub' -Confirm:$false + Update-GitHubRepository -Name 'PoShForGitHub' -Force Renames the repository without any user confirmation prompting. This is identical to using Rename-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub -NewName 'PoShForGitHub' -Confirm:$false #> [CmdletBinding( SupportsShouldProcess, - DefaultParameterSetName='Elements')] + DefaultParameterSetName='Elements', + ConfirmImpact='High')] [OutputType({$script:GitHubRepositoryTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( @@ -946,6 +928,8 @@ filter Update-GitHubRepository [switch] $Archived, + [switch] $Force, + [string] $AccessToken, [switch] $NoStatus @@ -962,6 +946,11 @@ filter Update-GitHubRepository 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } + if ($Force -and (-not $Confirm)) + { + $ConfirmPreference = 'None' + } + $hashBody = @{} if ($PSBoundParameters.ContainsKey('Name')) diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 14ea530a..b1e03b55 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -409,7 +409,7 @@ try } It "Should have the expected new repository name - by URI" { - $renamedRepo = $repo | Rename-GitHubRepository -NewName $newRepoName -Force + $renamedRepo = Rename-GitHubRepository -Uri ($repo.RepositoryUrl) -NewName $newRepoName -Force $renamedRepo.name | Should -Be $newRepoName } From 74ba3d666cac15661c6e00a537cd87addb000f63 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Wed, 10 Jun 2020 16:45:04 -0700 Subject: [PATCH 40/80] Fix singular pull request, move tests to proper files --- GitHubPullRequests.ps1 | 6 +- Tests/GitHubAnalytics.tests.ps1 | 104 +--------------------------- Tests/GitHubOrganizations.tests.ps1 | 28 ++++++++ Tests/GitHubPullRequests.tests.ps1 | 15 ++++ 4 files changed, 48 insertions(+), 105 deletions(-) diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index d392c194..84c52899 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -91,7 +91,9 @@ filter Get-GitHubPullRequest [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(ValueFromPipelineByPropertyName)] + [Parameter( + ValueFromPipeline, + ValueFromPipelineByPropertyName)] [Alias('PullRequestNumber')] [int64] $PullRequest, @@ -127,7 +129,7 @@ filter Get-GitHubPullRequest $uriFragment = "/repos/$OwnerName/$RepositoryName/pulls" $description = "Getting pull requests for $RepositoryName" - if (-not [String]::IsNullOrEmpty($PullRequest)) + if ($PSBoundParameters.ContainsKey('PullRequest')) { $uriFragment = $uriFragment + "/$PullRequest" $description = "Getting pull request $PullRequest for $RepositoryName" diff --git a/Tests/GitHubAnalytics.tests.ps1 b/Tests/GitHubAnalytics.tests.ps1 index 4a8cd49a..1be29162 100644 --- a/Tests/GitHubAnalytics.tests.ps1 +++ b/Tests/GitHubAnalytics.tests.ps1 @@ -17,109 +17,7 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { - # TODO: Re-enable these tests once the module has sufficient support getting the repository into the - # required state for testing, and to recover back to the original state at the conclusion of the test. - - # Describe 'Obtaining pull requests for repository' { - # Context 'When no additional conditions specified' { - # $pullRequests = Get-GitHubPullRequest -Uri $script:repositoryUrl - - # It 'Should return expected number of PRs' { - # @($pullRequests).Count | Should -Be 2 - # } - # } - - # Context 'When state and time range specified' { - # $mergedStartDate = Get-Date -Date '2016-04-10' - # $mergedEndDate = Get-Date -Date '2016-05-07' - # $pullRequests = Get-GitHubPullRequest -Uri $script:repositoryUrl -State Closed | - # Where-Object { ($_.merged_at -ge $mergedStartDate) -and ($_.merged_at -le $mergedEndDate) } - - # It 'Should return expected number of PRs' { - # @($pullRequests).Count | Should -Be 3 - # } - # } - # } - - # Describe 'Obtaining repository with biggest number of pull requests' { - # Context 'When no additional conditions specified' { - # @($script:repositoryUrl, $script:repositoryUrl2) | - # ForEach-Object { - # $pullRequestCounts += ([PSCustomObject]@{ - # 'Uri' = $_; - # 'Count' = (Get-GitHubPullRequest -Uri $_).Count }) } - # $pullRequestCounts = $pullRequestCounts | Sort-Object -Property Count -Descending - - # It 'Should return expected number of pull requests for each repository' { - # @($pullRequestCounts[0].Count) | Should -Be 2 - # @($pullRequestCounts[1].Count) | Should -Be 0 - # } - - # It 'Should return expected repository names' { - # @($pullRequestCounts[0].Uri) | Should -Be $script:repositoryUrl - # @($pullRequestCounts[1].Uri) | Should -Be $script:repositoryUrl2 - # } - # } - - # Context 'When state and time range specified' { - # $mergedDate = Get-Date -Date '2015-04-20' - # $repos = @($script:repositoryUrl, $script:repositoryUrl2) - # $pullRequestCounts = @() - # $pullRequestSearchParams = @{ - # 'State' = 'closed' - # } - # $repos | - # ForEach-Object { - # $pullRequestCounts += ([PSCustomObject]@{ - # 'Uri' = $_; - # 'Count' = ( - # (Get-GitHubPullRequest -Uri $_ @pullRequestSearchParams) | - # Where-Object { $_.merged_at -ge $mergedDate } - # ).Count - # }) } - - # $pullRequestCounts = $pullRequestCounts | Sort-Object -Property Count -Descending - # $pullRequests = Get-GitHubTopPullRequestRepository -Uri @($script:repositoryUrl, $script:repositoryUrl2) -State Closed -MergedOnOrAfter - - # It 'Should return expected number of pull requests for each repository' { - # @($pullRequests[0].Count) | Should -Be 3 - # @($pullRequests[1].Count) | Should -Be 0 - # } - - # It 'Should return expected repository names' { - # @($pullRequests[0].Uri) | Should -Be $script:repositoryUrl - # @($pullRequests[1].Uri) | Should -Be $script:repositoryUrl2 - # } - # } - # } - - # TODO: Re-enable these tests once the module has sufficient support getting the Organization - # and repository into the required state for testing, and to recover back to the original state - # at the conclusion of the test. - - # Describe 'Obtaining organization members' { - # $members = Get-GitHubOrganizationMember -OrganizationName $script:organizationName - - # It 'Should return expected number of organization members' { - # @($members).Count | Should -Be 1 - # } - # } - - # Describe 'Obtaining organization teams' { - # $teams = Get-GitHubTeam -OrganizationName $script:organizationName - - # It 'Should return expected number of organization teams' { - # @($teams).Count | Should -Be 2 - # } - # } - - # Describe 'Obtaining organization team members' { - # $members = Get-GitHubTeamMember -OrganizationName $script:organizationName -TeamName $script:organizationTeamName - - # It 'Should return expected number of organization team members' { - # @($members).Count | Should -Be 1 - # } - # } + # TODO } finally { diff --git a/Tests/GitHubOrganizations.tests.ps1 b/Tests/GitHubOrganizations.tests.ps1 index 2fbf5fee..42bc547b 100644 --- a/Tests/GitHubOrganizations.tests.ps1 +++ b/Tests/GitHubOrganizations.tests.ps1 @@ -18,6 +18,34 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { # TODO once more capabilities exist in the module's API set + + # TODO: Re-enable these tests once the module has sufficient support getting the Organization + # and repository into the required state for testing, and to recover back to the original state + # at the conclusion of the test. + + # Describe 'Obtaining organization members' { + # $members = Get-GitHubOrganizationMember -OrganizationName $script:organizationName + + # It 'Should return expected number of organization members' { + # @($members).Count | Should -Be 1 + # } + # } + + # Describe 'Obtaining organization teams' { + # $teams = Get-GitHubTeam -OrganizationName $script:organizationName + + # It 'Should return expected number of organization teams' { + # @($teams).Count | Should -Be 2 + # } + # } + + # Describe 'Obtaining organization team members' { + # $members = Get-GitHubTeamMember -OrganizationName $script:organizationName -TeamName $script:organizationTeamName + + # It 'Should return expected number of organization team members' { + # @($members).Count | Should -Be 1 + # } + # } } finally { diff --git a/Tests/GitHubPullRequests.tests.ps1 b/Tests/GitHubPullRequests.tests.ps1 index 3da2a09f..8df52250 100644 --- a/Tests/GitHubPullRequests.tests.ps1 +++ b/Tests/GitHubPullRequests.tests.ps1 @@ -61,6 +61,21 @@ try } } } + + Describe 'Getting multiple pull requests from repository' { + BeforeAll { + $ownerName = 'microsoft' + $repositoryName = 'PowerShellForGitHub' + } + + Context 'All closed' { + $pullRequests = @(Get-GitHubPullRequest -OwnerName $ownerName -RepositoryName $repositoryName -State 'Closed') + + It 'Should return expected number of PRs' { + $pullRequests.Count | Should -BeGreaterOrEqual 140 + } + } + } } finally { From 2ba0e8ee037dd2a33e574ed34fe3e9c529d729b4 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Wed, 10 Jun 2020 16:51:21 -0700 Subject: [PATCH 41/80] Fixing repository (contributor) tests --- Tests/GitHubRepositories.tests.ps1 | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index b1e03b55..5d31cd5f 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -758,20 +758,11 @@ try } Context -Name 'Obtaining contributors for repository' -Fixture { - $contributors = @(Get-GitHubRepositoryContributor -Uri $repo.RepositoryUrl -IncludeStatistics) + $contributors = @(Get-GitHubRepositoryContributor -Uri $repo.RepositoryUrl) It 'Should return expected number of contributors' { $contributors.Count | Should -Be 1 - #$contributors[0].PSObject.TypeName = 'GitHub.User' - } - - It 'Should return expected number of unique contributors' { - $uniqueContributors = $contributors | - Select-Object -ExpandProperty author | - Select-Object -ExpandProperty login -Unique - Sort-Object - - $uniqueContributors.Count | Should -Be 1 + $contributors[0].PSObject.TypeName = 'GitHub.User' } } @@ -784,7 +775,7 @@ try } } - Context -Name 'Obtaining collaborator statistics for repository' -Fixture { + Context -Name 'Obtaining contributor statistics for repository' -Fixture { $stats = @(Get-GitHubRepositoryContributor -Uri $repo.RepositoryUrl -IncludeStatistics) It 'Should return expected number of contributors' { From 6344c48500b8dae6aa4281befa326715d40315ed Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Thu, 11 Jun 2020 01:28:14 -0700 Subject: [PATCH 42/80] Complete rewrite of milestone tests --- GitHubMilestones.ps1 | 49 ++-- Tests/GitHubMilestones.tests.ps1 | 384 ++++++++++++++++++++++++++----- 2 files changed, 362 insertions(+), 71 deletions(-) diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index 69f6154b..9aea3863 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -79,13 +79,27 @@ filter Get-GitHubMilestone [Parameter(Mandatory, ParameterSetName='RepositoryElements')] [string] $RepositoryName, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='MilestoneUri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='RepositoryUri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='MilestoneUri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='RepositoryUri')] [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='MilestoneUri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='MilestoneElements')] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName, + ParameterSetName='MilestoneUri')] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName, + ParameterSetName='MilestoneElements')] [Alias('MilestoneNumber')] [int64] $Milestone, @@ -140,16 +154,17 @@ filter Get-GitHubMilestone } $getParams += "sort=$($sortConverter[$Sort])" - } - if ($PSBoundParameters.ContainsKey('Direction')) - { - $directionConverter = @{ - 'Ascending' = 'asc' - 'Descending' = 'desc' - } + # We only look at this parameter if the user provided Sort as well. + if ($PSBoundParameters.ContainsKey('Direction')) + { + $directionConverter = @{ + 'Ascending' = 'asc' + 'Descending' = 'desc' + } - $getParams += "direction=$($directionConverter[$Direction])" + $getParams += "direction=$($directionConverter[$Direction])" + } } if ($PSBoundParameters.ContainsKey('State')) @@ -257,8 +272,14 @@ filter New-GitHubMilestone [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName='Uri')] - [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter( + Mandatory, + ValueFromPipeline, + ParameterSetName='Uri')] + [Parameter( + Mandatory, + ValueFromPipeline, + ParameterSetName='Elements')] [string] $Title, [ValidateSet('Open', 'Closed')] diff --git a/Tests/GitHubMilestones.tests.ps1 b/Tests/GitHubMilestones.tests.ps1 index 0f07dc75..a60d0fcf 100644 --- a/Tests/GitHubMilestones.tests.ps1 +++ b/Tests/GitHubMilestones.tests.ps1 @@ -19,116 +19,386 @@ try { # Define Script-scoped, readonly, hidden variables. @{ - defaultIssueTitle = "This is a test issue." - defaultMilestoneTitle1 = "This is a test milestone title #1." - defaultMilestoneTitle2 = "This is a test milestone title #2." - defaultMilestoneTitle3 = "This is a test milestone title #3." - defaultMilestoneTitle4 = "This is a test milestone title #4." - defaultEditedMilestoneTitle = "This is an edited milestone title." - defaultMilestoneDescription = "This is a test milestone description." - defaultEditedMilestoneDescription = "This is an edited milestone description." defaultMilestoneDueOn = (Get-Date).AddYears(1).ToUniversalTime() }.GetEnumerator() | ForEach-Object { Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value } - Describe 'Creating, modifying and deleting milestones' { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - $issue = New-GitHubIssue -Uri $repo.svn_url -Title $defaultIssueTitle + Describe 'Creating a milestone' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - Context 'For creating a new milestone' { - $newMilestone = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle1 -State "Closed" -DueOn $defaultMilestoneDueOn - $existingMilestone = Get-GitHubMilestone -Uri $repo.svn_url -Milestone $newMilestone.number + $commonParams = @{ + 'State' = 'Closed' + 'DueOn' = $script:defaultMilestoneDueOn + 'Description' = 'Milestone description' + } - # We'll be testing to make sure that regardless of the time in the timestamp, we'll get the desired date. - $newMilestoneDueOnEarlyMorning = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle2 -State "Closed" -DueOn $defaultMilestoneDueOn.date.AddHours(1) - $newMilestoneDueOnLateEvening = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle3 -State "Closed" -DueOn $defaultMilestoneDueOn.date.AddHours(23) + $title = 'Milestone title' + } + + AfterAll { + $repo | Remove-GitHubRepository -Force + } + + Context 'Using the parameter' { + BeforeAll { + $milestone = New-GitHubMilestone -OwnerName $repo.owner.login -RepositoryName $repo.name -Title $title @commonParams + } + + AfterAll { + $milestone | Remove-GitHubMilestone -Force + } + + $returned = Get-GitHubMilestone -OwnerName $repo.owner.login -RepositoryName $repo.name -Milestone $milestone.MilestoneNumber + + It 'Should exist' { + $returned.id | Should -Be $milestone.id + } + + It 'Should have the correct creation properties' { + $milestone.title | Should -Be $title + $milestone.state | Should -Be $commonParams['State'] + $milestone.description | Should -Be $commonParams['Description'] + + # GitHub drops the time that is attached to 'due_on', so it's only relevant + # to compare the dates against each other. + (Get-Date -Date $milestone.due_on).Date | Should -Be $commonParams['DueOn'].Date + } + + It 'Should have the expected type and additional properties' { + $milestone.PSObject.TypeNames[0] | Should -Be 'GitHub.Milestone' + $milestone.RepositoryUrl | Should -Be $repo.RepositoryUrl + $milestone.MilestoneId | Should -Be $milestone.id + $milestone.MilestoneNumber | Should -Be $milestone.number + $milestone.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Using the pipeline for the repo' { + BeforeAll { + $milestone = $repo | New-GitHubMilestone -Title $title @commonParams + } - It "Should have the expected title text" { - $existingMilestone.title | Should -Be $defaultMilestoneTitle1 + AfterAll { + $milestone | Remove-GitHubMilestone -Force } - It "Should have the expected state" { - $existingMilestone.state | Should -Be "closed" + $returned = $milestone | Get-GitHubMilestone + + It 'Should exist' { + $returned.id | Should -Be $milestone.id } - It "Should have the expected due_on date" { + It 'Should have the correct creation properties' { + $milestone.title | Should -Be $title + $milestone.state | Should -Be $commonParams['State'] + $milestone.description | Should -Be $commonParams['Description'] + # GitHub drops the time that is attached to 'due_on', so it's only relevant # to compare the dates against each other. - (Get-Date -Date $existingMilestone.due_on).Date | Should -Be $defaultMilestoneDueOn.Date + (Get-Date -Date $milestone.due_on).Date | Should -Be $commonParams['DueOn'].Date + } + + It 'Should have the expected type and additional properties' { + $milestone.PSObject.TypeNames[0] | Should -Be 'GitHub.Milestone' + $milestone.RepositoryUrl | Should -Be $repo.RepositoryUrl + $milestone.MilestoneId | Should -Be $milestone.id + $milestone.MilestoneNumber | Should -Be $milestone.number + $milestone.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' } + } + + Context 'Using the pipeline for the title' { + BeforeAll { + $milestone = $title | New-GitHubMilestone -OwnerName $repo.owner.login -RepositoryName $repo.name @commonParams + } + + AfterAll { + $milestone | Remove-GitHubMilestone -Force + } + + $returned = $repo | Get-GitHubMilestone -Milestone $milestone.MilestoneNumber + + It 'Should exist' { + $returned.id | Should -Be $milestone.id + } + + It 'Should have the correct creation properties' { + $milestone.title | Should -Be $title + $milestone.state | Should -Be $commonParams['State'] + $milestone.description | Should -Be $commonParams['Description'] + + # GitHub drops the time that is attached to 'due_on', so it's only relevant + # to compare the dates against each other. + (Get-Date -Date $milestone.due_on).Date | Should -Be $commonParams['DueOn'].Date + } + + It 'Should have the expected type and additional properties' { + $milestone.PSObject.TypeNames[0] | Should -Be 'GitHub.Milestone' + $milestone.RepositoryUrl | Should -Be $repo.RepositoryUrl + $milestone.MilestoneId | Should -Be $milestone.id + $milestone.MilestoneNumber | Should -Be $milestone.number + $milestone.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'That is due at different times of the day' { + # We'll be testing to make sure that regardless of the time in the timestamp, we'll get the desired date. + $title = 'Milestone title' It "Should have the expected due_on date even if early morning" { + $milestone = $repo | New-GitHubMilestone -Title 'Due early in the morning' -State "Closed" -DueOn $defaultMilestoneDueOn.date.AddHours(1) + # GitHub drops the time that is attached to 'due_on', so it's only relevant # to compare the dates against each other. - (Get-Date -Date $newMilestoneDueOnEarlyMorning.due_on).Date | Should -Be $defaultMilestoneDueOn.Date + (Get-Date -Date $milestone.due_on).Date | Should -Be $defaultMilestoneDueOn.Date } It "Should have the expected due_on date even if late evening" { + $milestone = $repo | New-GitHubMilestone -Title 'Due late in the evening' -State "Closed" -DueOn $defaultMilestoneDueOn.date.AddHours(23) + # GitHub drops the time that is attached to 'due_on', so it's only relevant # to compare the dates against each other. - (Get-Date -Date $newMilestoneDueOnLateEvening.due_on).Date | Should -Be $defaultMilestoneDueOn.Date + (Get-Date -Date $milestone.due_on).Date | Should -Be $defaultMilestoneDueOn.Date } + } + } - It "Should allow the addition of an existing issue" { - Update-GitHubIssue -Uri $repo.svn_url -Issue $issue.number -Milestone $existingMilestone.number - } + Describe 'Associating milestones with issues' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + $milestone = $repo | New-GitHubMilestone -Title 'Milestone Title' + $issue = $repo | New-GitHubIssue -Title 'Issue Title' } - Context 'For getting milestones from a repo' { - $existingMilestones =@(Get-GitHubMilestone -Uri $repo.svn_url -State Closed) + AfterAll { + $repo | Remove-GitHubRepository -Force + } + + Context 'Adding milestone to an issue' { + It 'Should not have any open issues associated with it' { + $issue.milestone | Should -BeNullOrEmpty + $milestone.open_issues | Should -Be 0 + } + + $issue = $issue | Update-GitHubIssue -Milestone $milestone.MilestoneNumber + $milestone = $milestone | Get-GitHubMilestone + It "Should be associated to the milestone now" { + $issue.milestone.number | Should -Be $milestone.MilestoneNumber + $milestone.open_issues | Should -Be 1 + } + + $issue = $issue | Update-GitHubIssue -Milestone 0 + $milestone = $milestone | Get-GitHubMilestone + It 'Should no longer be associated to the milestone' { + $issue.milestone | Should -BeNullOrEmpty + $milestone.open_issues | Should -Be 0 + } + + $issue = $issue | Update-GitHubIssue -Milestone $milestone.MilestoneNumber + $milestone = $milestone | Get-GitHubMilestone + It "Should be associated to the milestone again" { + $issue.milestone.number | Should -Be $milestone.MilestoneNumber + $milestone.open_issues | Should -Be 1 + } + + $milestone | Remove-GitHubMilestone -Force $issue = Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number + It 'Should have removed the association when the milestone was deleted' { + $issue.milestone | Should -BeNullOrEmpty + } + } + } + + Describe 'Getting milestones' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + $title = 'Milestone title' + } + + AfterAll { + $repo | Remove-GitHubRepository -Force + } + + Context 'Getting a specific milestone' { + BeforeAll { + $closedMilestone = 'C' | New-GitHubMilestone -Uri $repo.RepositoryUrl -State 'Closed' + $openMilestone = 'O' | New-GitHubMilestone -Uri $repo.RepositoryUrl -State 'Open' + } + + AfterAll { + $closedMilestone | Remove-GitHubMilestone -Force + $openMilestone | Remove-GitHubMilestone -Force + } + + It 'Should get the right milestone as a parameter' { + $milestone = $closedMilestone + $returned = Get-GitHubMilestone -Uri $repo.RepositoryUrl -Milestone $milestone.MilestoneNumber + + $returned.MilestoneId | Should -Be $milestone.MilestoneId + } + + It 'Should get the right milestone via the pipeline' { + $milestone = $openMilestone + $returned = $openMilestone | Get-GitHubMilestone + + $returned.MilestoneId | Should -Be $milestone.MilestoneId + } + } + + Context 'Getting multiple milestones' { + BeforeAll { + $today = (Get-Date).ToUniversalTime() + $nextWeek = (Get-Date).AddDays(7).ToUniversalTime() + $numClosedMilestones = 3 + $numOpenMilestones = 4 + $closed = 1..$numClosedMilestones | ForEach-Object { $repo | New-GitHubMilestone -Title "Closed $_" -State 'Closed' -DueOn $today } + $open = 1..$numOpenMilestones | ForEach-Object { $repo | New-GitHubMilestone -Title "Open $_" -State 'Open' -DueOn $nextWeek } + } + + AfterAll { + $closed | Remove-GitHubMilestone -Force + $open | Remove-GitHubMilestone -Force + } It 'Should have the expected number of milestones' { - $existingMilestones.Count | Should -Be 3 + $milestones = @(Get-GitHubMilestone -Uri $repo.RepositoryUrl -State 'All') + $milestones.Count | Should -Be ($numClosedMilestones + $numOpenMilestones) } - It 'Should have the expected title text on the first milestone' { - $existingMilestones[0].title | Should -Be $defaultMilestoneTitle1 + It 'Should have the expected number of open milestones' { + $milestones = @($repo | Get-GitHubMilestone -State 'Open') + $milestones.Count | Should -Be $numOpenMilestones } - It 'Should have the expected issue in the first milestone' { - $existingMilestones[0].open_issues | Should -Be 1 - $issue.milestone.number | Should -Be 1 + It 'Should have the expected number of closed milestones' { + $milestones = @(Get-GitHubMilestone -Uri $repo.RepositoryUrl -State 'Closed') + $milestones.Count | Should -Be $numClosedMilestones + } + + It 'Should sort them the right way | DueOn, Descending' { + $milestones = @(Get-GitHubMilestone -Uri $repo.RepositoryUrl -State 'All' -Sort 'DueOn' -Direction 'Descending') + $milestones[0].state | Should -Be 'Open' + } + + It 'Should sort them the right way | DueOn, Ascending' { + $milestones = @(Get-GitHubMilestone -Uri $repo.RepositoryUrl -State 'All' -Sort 'DueOn' -Direction 'Ascending') + $milestones[0].state | Should -Be 'Closed' } } + } - Context 'For editing a milestone' { - $newMilestone = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle4 -Description $defaultMilestoneDescription - $editedMilestone = Set-GitHubMilestone -Uri $repo.svn_url -Milestone $newMilestone.number -Title $defaultEditedMilestoneTitle -Description $defaultEditedMilestoneDescription + Describe 'Editing a milestone' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - It 'Should have a title/description that is not equal to the original title/description' { - $editedMilestone.title | Should -Not -Be $newMilestone.title - $editedMilestone.description | Should -Not -Be $newMilestone.description + $createParams = @{ + 'Title' = 'Created Title' + 'State' = 'Open' + 'Description' = 'Created Description' + 'DueOn' = (Get-Date).ToUniversalTime() } - It 'Should have the edited content' { - $editedMilestone.title | Should -Be $defaultEditedMilestoneTitle - $editedMilestone.description | Should -Be $defaultEditedMilestoneDescription + $editParams = @{ + 'Title' = 'Edited Title' + 'State' = 'Closed' + 'Description' = 'Edited Description' + 'DueOn' = (Get-Date).AddDays(7).ToUniversalTime() } } - Context 'For getting milestones from a repository and deleting them' { - $existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url -State All -Sort Completeness -Direction Descending) + AfterAll { + $repo | Remove-GitHubRepository -Force + } - It 'Should have the expected number of milestones' { - $existingMilestones.Count | Should -Be 4 + Context 'Using the parameter' { + BeforeAll { + $milestone = New-GitHubMilestone -OwnerName $repo.owner.login -RepositoryName $repo.name @createParams + $edited = Set-GitHubMilestone -Uri $milestone.RepositoryUrl -Milestone $milestone.MilestoneNumber @editParams } - foreach($milestone in $existingMilestones) { - Remove-GitHubMilestone -Uri $repo.svn_url -Milestone $milestone.number -Confirm:$false + AfterAll { + $milestone | Remove-GitHubMilestone -Force } - $existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url -State All) - $issue = Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number + It 'Should be editable via the parameter' { + $edited.id | Should -Be $milestone.id + $edited.title | Should -Be $editParams['Title'] + $edited.state | Should -Be $editParams['State'] + $edited.description | Should -Be $editParams['Description'] + + # GitHub drops the time that is attached to 'due_on', so it's only relevant + # to compare the dates against each other. + (Get-Date -Date $edited.due_on).Date | Should -Be $editParams['DueOn'].Date + } - It 'Should have no milestones' { - $existingMilestones.Count | Should -Be 0 - $issue.milestone | Should -Be $null + It 'Should have the expected type and additional properties' { + $edited.PSObject.TypeNames[0] | Should -Be 'GitHub.Milestone' + $edited.RepositoryUrl | Should -Be $repo.RepositoryUrl + $edited.MilestoneId | Should -Be $milestone.id + $edited.MilestoneNumber | Should -Be $milestone.number + $edited.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' } } - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + Context 'Using the pipeline' { + BeforeAll { + $milestone = New-GitHubMilestone -OwnerName $repo.owner.login -RepositoryName $repo.name @createParams + $edited = $milestone | Set-GitHubMilestone @editParams + } + + AfterAll { + $milestone | Remove-GitHubMilestone -Force + } + + It 'Should be editable via the pipeline' { + $edited.id | Should -Be $milestone.id + $edited.title | Should -Be $editParams['Title'] + $edited.state | Should -Be $editParams['State'] + $edited.description | Should -Be $editParams['Description'] + + # GitHub drops the time that is attached to 'due_on', so it's only relevant + # to compare the dates against each other. + (Get-Date -Date $edited.due_on).Date | Should -Be $editParams['DueOn'].Date + } + + It 'Should have the expected type and additional properties' { + $edited.PSObject.TypeNames[0] | Should -Be 'GitHub.Milestone' + $edited.RepositoryUrl | Should -Be $repo.RepositoryUrl + $edited.MilestoneId | Should -Be $milestone.id + $edited.MilestoneNumber | Should -Be $milestone.number + $edited.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + } + + Describe 'Deleting a milestone' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + } + + AfterAll { + $repo | Remove-GitHubRepository -Force + } + + Context 'Using the parameter' { + $milestone = $repo | New-GitHubMilestone -Title 'Milestone title' -State "Closed" -DueOn $defaultMilestoneDueOn + Remove-GitHubMilestone -OwnerName $repo.owner.login -RepositoryName $repo.name -Milestone $milestone.MilestoneNumber -Force + + It 'Should be deleted' { + { Get-GitHubMilestone -OwnerName $repo.owner.login -RepositoryName $repo.name -Milestone $milestone.MilestoneNumber } | Should -Throw + } + } + + Context 'Using the pipeline' { + $milestone = $repo | New-GitHubMilestone -Title 'Milestone title' -State "Closed" -DueOn $defaultMilestoneDueOn + $milestone | Remove-GitHubMilestone -Force + + It 'Should be deleted' { + { $milestone | Get-GitHubMilestone } | Should -Throw + } + } } } finally From 2644bd543c4e92266b5cd282b022ab6873481021 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Thu, 11 Jun 2020 01:28:34 -0700 Subject: [PATCH 43/80] nit --- GitHubOrganizations.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/GitHubOrganizations.ps1 b/GitHubOrganizations.ps1 index f5db66f9..26a31150 100644 --- a/GitHubOrganizations.ps1 +++ b/GitHubOrganizations.ps1 @@ -158,7 +158,6 @@ filter Test-GitHubOrganizationMember } } - filter Add-GitHubOrganizationAdditionalProperties { <# From 9c5a1b445e6302578962bbbba574c47cf325a010 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 12 Jun 2020 10:26:58 -0700 Subject: [PATCH 44/80] Add pipeline events tests --- GitHubEvents.ps1 | 79 +++++++++++++++++++++++++++-- GitHubIssues.ps1 | 21 +++----- GitHubLabels.ps1 | 6 ++- GitHubProjectColumns.ps1 | 1 + GitHubPullRequests.ps1 | 31 +++--------- GitHubRepositories.ps1 | 2 + Tests/GitHubEvents.tests.ps1 | 98 ++++++++++++++++++++++++++---------- 7 files changed, 168 insertions(+), 70 deletions(-) diff --git a/GitHubEvents.ps1 b/GitHubEvents.ps1 index 73632844..27930a99 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -171,14 +171,85 @@ filter Add-GitHubEventAdditionalProperties Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force Add-Member -InputObject $item -Name 'EventId' -Value $item.id -MemberType NoteProperty -Force - if ($null -ne $item.actor) - { - $null = Add-GitHubUserAdditionalProperties -InputObject $item.actor - } + @('actor', 'assignee', 'assigner', 'assignees', 'committer', 'requested_reviewer', 'review_requester', 'user') | + ForEach-Object { + if ($null -ne $item.$_) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.$_ + } + } if ($null -ne $item.issue) { $null = Add-GitHubIssueAdditionalProperties -InputObject $item.issue + Add-Member -InputObject $item -Name 'IssueId' -Value $item.issue.id -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'IssueNumber' -Value $item.issue.number -MemberType NoteProperty -Force + } + + if ($null -ne $item.label) + { + $null = Add-GitHubLabelAdditionalProperties -InputObject $item.label + } + + if ($null -ne $item.labels) + { + $null = Add-GitHubLabelAdditionalProperties -InputObject $item.labels + } + + if ($null -ne $item.milestone) + { + $null = Add-GitHubMilestoneAdditionalProperties -InputObject $item.milestone + } + + if ($null -ne $item.project_id) + { + Add-Member -InputObject $item -Name 'ProjectId' -Value $item.project_id -MemberType NoteProperty -Force + } + + if ($null -ne $item.project_card) + { + $null = Add-GitHubProjectCardAdditionalProperties -InputObject $item.project_card + Add-Member -InputObject $item -Name 'CardId' -Value $item.project_card.id -MemberType NoteProperty -Force + } + + if ($null -ne $item.column_name) + { + Add-Member -InputObject $item -Name 'ColumnName' -Value $item.column_name -MemberType NoteProperty -Force + } + + if ($null -ne $item.source) + { + $null = Add-GitHubIssueAdditionalProperties -InputObject $item.source + if ($item.source.PSObject.TypeNames[0] -eq 'GitHub.PullRequest') + { + Add-Member -InputObject $item -Name 'PullRequestId' -Value $item.source.id -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'PullRequestNumber' -Value $item.source.number -MemberType NoteProperty -Force + } + else + { + Add-Member -InputObject $item -Name 'IssueId' -Value $item.source.id -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'IssueNumber' -Value $item.source.number -MemberType NoteProperty -Force + } + } + + if ($item.issue_url -match '^.*/issues/(\d+)$') + { + $issueNumber = $Matches[1] + Add-Member -InputObject $item -Name 'IssueNumber' -Value $issueNumber -MemberType NoteProperty -Force + } + + if ($item.pull_request_url -match '^.*/pull/(\d+)$') + { + $pullRequestNumber = $Matches[1] + Add-Member -InputObject $item -Name 'PullRequestNumber' -Value $pullRequestNumber -MemberType NoteProperty -Force + } + + if ($null -ne $item.dismissed_review) + { + # TODO: Add dismissed_review (object) and dismissed_review[review_id] once Reviews are supported + + # $null = Add-GitHubPullRequestReviewAdditionalProperties -InputObject $item.dismissed_review + # Add-Member -InputObject $item -Name 'ReviewId' -Value $item.dismissed_review.review_id -MemberType NoteProperty -Force } } diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index 91419552..0c6a4671 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -1009,10 +1009,13 @@ filter Add-GitHubIssueAdditionalProperties Add-Member -InputObject $item -Name 'IssueId' -Value $item.id -MemberType NoteProperty -Force Add-Member -InputObject $item -Name 'IssueNumber' -Value $item.number -MemberType NoteProperty -Force - if ($null -ne $item.user) - { - $null = Add-GitHubUserAdditionalProperties -InputObject $item.user - } + @('assignee', 'assignees', 'user') | + ForEach-Object { + if ($null -ne $item.$_) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.$_ + } + } if ($null -ne $item.labels) { @@ -1024,16 +1027,6 @@ filter Add-GitHubIssueAdditionalProperties $null = Add-GitHubMilestoneAdditionalProperties -InputObject $item.milestone } - if ($null -ne $item.assignee) - { - $null = Add-GitHubUserAdditionalProperties -InputObject $item.assignee - } - - if ($null -ne $item.assignees) - { - $null = Add-GitHubUserAdditionalProperties -InputObject $item.assignees - } - if ($null -ne $item.closed_by) { $null = Add-GitHubUserAdditionalProperties -InputObject $item.closed_by diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 4c74bd62..8f8f0538 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -1080,7 +1080,11 @@ filter Add-GitHubLabelAdditionalProperties Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force } - Add-Member -InputObject $item -Name 'LabelId' -Value $item.id -MemberType NoteProperty -Force + if ($null -ne $item.id) + { + Add-Member -InputObject $item -Name 'LabelId' -Value $item.id -MemberType NoteProperty -Force + } + Add-Member -InputObject $item -Name 'LabelName' -Value $item.name -MemberType NoteProperty -Force } diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index c1499055..ca4cc861 100644 --- a/GitHubProjectColumns.ps1 +++ b/GitHubProjectColumns.ps1 @@ -493,6 +493,7 @@ filter Add-GitHubProjectColumnAdditionalProperties if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { Add-Member -InputObject $item -Name 'ColumnId' -Value $item.id -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'ColumnName' -Value $item.name -MemberType NoteProperty -Force } Write-Output $item diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index 84c52899..50fed095 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -448,10 +448,13 @@ filter Add-GitHubPullRequestAdditionalProperties Add-Member -InputObject $item -Name 'PullRequestId' -Value $item.id -MemberType NoteProperty -Force Add-Member -InputObject $item -Name 'PullRequestNumber' -Value $item.number -MemberType NoteProperty -Force - if ($null -ne $item.user) - { - $null = Add-GitHubUserAdditionalProperties -InputObject $item.user - } + @('assignee', 'assignees', 'requested_reviewers', 'merged_by', 'user') | + ForEach-Object { + if ($null -ne $item.$_) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.$_ + } + } if ($null -ne $item.labels) { @@ -463,31 +466,11 @@ filter Add-GitHubPullRequestAdditionalProperties $null = Add-GitHubMilestoneAdditionalProperties -InputObject $item.milestone } - if ($null -ne $item.assignee) - { - $null = Add-GitHubUserAdditionalProperties -InputObject $item.assignee - } - - if ($null -ne $item.assignees) - { - $null = Add-GitHubUserAdditionalProperties -InputObject $item.assignees - } - - if ($null -ne $item.requested_reviewers) - { - $null = Add-GitHubUserAdditionalProperties -InputObject $item.requested_reviewers - } - if ($null -ne $item.requested_teams) { $null = Add-GitHubTeamAdditionalProperties -InputObject $item.requested_teams } - if ($null -ne $item.merged_by) - { - $null = Add-GitHubUserAdditionalProperties -InputObject $item.merged_by - } - # TODO: What type are item.head and item.base? } diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 78d8f378..dd6da634 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -1301,6 +1301,7 @@ filter Get-GitHubRepositoryContributor .OUTPUTS GitHub.User + GitHub.RepositoryContributorStatistics .EXAMPLE Get-GitHubRepositoryContributor -OwnerName Microsoft -RepositoryName PowerShellForGitHub @@ -1312,6 +1313,7 @@ filter Get-GitHubRepositoryContributor SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubUserTypeName})] + [OutputType({$script:GitHubRepositoryContributorStatisticsTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] diff --git a/Tests/GitHubEvents.tests.ps1 b/Tests/GitHubEvents.tests.ps1 index 8976fd8c..ac16c25a 100644 --- a/Tests/GitHubEvents.tests.ps1 +++ b/Tests/GitHubEvents.tests.ps1 @@ -17,39 +17,61 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { - # All of these tests will fail without authentication. Let's just avoid the failures. - if (-not $accessTokenConfigured) { return } - Describe 'Getting events from repository' { - $repositoryName = [Guid]::NewGuid() - $null = New-GitHubRepository -RepositoryName $repositoryName + BeforeAll { + $repositoryName = [Guid]::NewGuid() + $repo = New-GitHubRepository -RepositoryName $repositoryName + } + + AfterAll { + $null = $repo | Remove-GitHubRepository -Force + } - Context 'For getting events from a new repository' { + Context 'For getting events from a new repository (via parameter)' { $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) - It 'Should have no events' { + It 'Should have no events (via parameter)' { $events.Count | Should -Be 0 } } - $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" - Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed + Context 'For getting events from a new repository (via pipeline)' { + $events = @($repo | Get-GitHubEvent) - Context 'For getting events from a repository' { - $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) + It 'Should have no events (via parameter)' { + $events.Count | Should -Be 0 + } + } + + Context 'For getting Issue events from a repository' { + $issue = $repo | New-GitHubIssue -Title 'New Issue' + $issue = $issue | Update-GitHubIssue -State Closed + $events = @($repo | Get-GitHubEvent) It 'Should have an event from closing an issue' { $events.Count | Should -Be 1 } - } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + It 'Should have the expected type and additional properties' { + $events[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Event' + $events[0].issue.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + $events[0].IssueId | Should -Be $events[0].issue.id + $events[0].IssueNumber | Should -Be $events[0].issue.number + $events[0].actor.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } } Describe 'Getting events from an issue' { - $repositoryName = [Guid]::NewGuid() - $null = New-GitHubRepository -RepositoryName $repositoryName - $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" + BeforeAll { + $repositoryName = [Guid]::NewGuid() + $repo = New-GitHubRepository -RepositoryName $repositoryName + $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" + } + + AfterAll { + $repo | Remove-GitHubRepository -Confirm:$false + } Context 'For getting events from a new issue' { $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) @@ -69,26 +91,48 @@ try } } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false } Describe 'Getting an event directly' { - $repositoryName = [Guid]::NewGuid() - $null = New-GitHubRepository -RepositoryName $repositoryName - $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" - Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed - Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Open - $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) - - Context 'For getting an event directly'{ + BeforeAll { + $repositoryName = [Guid]::NewGuid() + $repo = New-GitHubRepository -RepositoryName $repositoryName + $issue = $repo | New-GitHubIssue -Title 'New Issue' + $issue = $issue | Update-GitHubIssue -State Closed + $issue = $issue | Update-GitHubIssue -State Open + $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) + } + + AfterAll { + $repo | Remove-GitHubRepository -Confirm:$false + } + + Context 'For getting a single event directly by parameter'{ $singleEvent = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -EventID $events[0].id - It 'Should have the correct event type'{ + It 'Should have the correct event type' { $singleEvent.event | Should -Be 'reopened' } } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + Context 'For getting a single event directly by pipeline'{ + $singleEvent = $events[0] | Get-GitHubEvent + + It 'Should have the expected event type' { + $singleEvent.event | Should -Be $events[0].event + } + + It 'Should have the same id' { + $singleEvent.id | Should -Be $events[0].id + } + + It 'Should have the expected type and additional properties' { + $singleEvent.PSObject.TypeNames[0] | Should -Be 'GitHub.Event' + $singleEvent.RepositoryUrl | Should -Be $repo.RepositoryUrl + $singleEvent.EventId | Should -Be $singleEvent.id + $singleEvent.actor.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } } } finally From 354190847117aadfbd535f262389dc11b183a927 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 12 Jun 2020 13:10:54 -0700 Subject: [PATCH 45/80] Update projects tests --- GitHubProjects.ps1 | 34 +++- Tests/GitHubEvents.tests.ps1 | 6 +- Tests/GitHubProjects.tests.ps1 | 293 ++++++++++++++++++++++++++++++++- 3 files changed, 322 insertions(+), 11 deletions(-) diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index bbb8c649..5d75083f 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -99,6 +99,10 @@ filter Get-GitHubProject Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='ProjectObject')] [Alias('RepositoryUrl')] [string] $Uri, @@ -108,7 +112,15 @@ filter Get-GitHubProject [Parameter(Mandatory, ParameterSetName = 'User')] [string] $UserName, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'Project')] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName, + ParameterSetName = 'Project')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='ProjectObject')] [Alias('ProjectId')] [int64] $Project, @@ -126,7 +138,7 @@ filter Get-GitHubProject $uriFragment = [String]::Empty $description = [String]::Empty - if ($PSCmdlet.ParameterSetName -eq 'Project') + if ($PSCmdlet.ParameterSetName -in @('Project', 'ProjectObject')) { $telemetryProperties['Project'] = Get-PiiSafeString -PlainText $Project @@ -275,7 +287,9 @@ filter New-GitHubProject [Parameter(Mandatory, ParameterSetName = 'User')] [switch] $UserProject, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline)] [string] $Name, [string] $Description, @@ -399,7 +413,10 @@ filter Set-GitHubProject [OutputType({$script:GitHubPullRequestTypeName})] [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, ValueFromPipelineByPropertyName)] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName)] [Alias('ProjectId')] [int64] $Project, @@ -593,7 +610,14 @@ filter Add-GitHubProjectAdditionalProperties { $elements = Split-GitHubUri -Uri $item.html_url $repositoryUrl = Join-GitHubUri @elements - Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + + # A "user" project has no associated repository, and adding this in that scenario + # would cause API-level errors with piping further on, + if ($elements.OwnerName -ne 'users') + { + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + } + Add-Member -InputObject $item -Name 'ProjectId' -Value $item.id -MemberType NoteProperty -Force if ($null -ne $item.creator) diff --git a/Tests/GitHubEvents.tests.ps1 b/Tests/GitHubEvents.tests.ps1 index ac16c25a..43390e7a 100644 --- a/Tests/GitHubEvents.tests.ps1 +++ b/Tests/GitHubEvents.tests.ps1 @@ -82,8 +82,8 @@ try } Context 'For getting events from an issue' { - Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed - Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Open + $issue = $issue | Update-GitHubIssue -State Closed + $issue = $issue | Update-GitHubIssue -State Open $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should have two events from closing and opening the issue' { @@ -100,7 +100,7 @@ try $issue = $repo | New-GitHubIssue -Title 'New Issue' $issue = $issue | Update-GitHubIssue -State Closed $issue = $issue | Update-GitHubIssue -State Open - $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) + $events = @($repo | Get-GitHubEvent) } AfterAll { diff --git a/Tests/GitHubProjects.tests.ps1 b/Tests/GitHubProjects.tests.ps1 index eb896542..3cc2d694 100644 --- a/Tests/GitHubProjects.tests.ps1 +++ b/Tests/GitHubProjects.tests.ps1 @@ -65,6 +65,12 @@ try It 'Description is correct' { $results[0].body | Should -Be $defaultUserProjectDesc } + + It 'Should have the expected type and additional properties' { + $results[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $results[0].RepositoryUrl | Should -BeNullOrEmpty # no RepositoryUrl for user projects + $results[0].ProjectId | Should -Be $results[0].id + } } Context 'Get Organization projects' { @@ -92,6 +98,15 @@ try It 'Description is correct' { $results[0].body | Should -Be $defaultOrgProjectDesc } + + It 'Should have the expected type and additional properties' { + $elements = Split-GitHubUri -Uri $results[0].html_url + $repositoryUrl = Join-GitHubUri @elements + + $results[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $results[0].RepositoryUrl | Should -Be $repositoryUrl + $results[0].ProjectId | Should -Be $results[0].id + } } Context 'Get Repo projects' { @@ -119,11 +134,18 @@ try It 'Description is correct' { $results[0].body | Should -Be $defaultRepoProjectDesc } + + It 'Should have the expected type and additional properties' { + $results[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $results[0].RepositoryUrl | Should -Be $repo.RepositoryUrl + $results[0].ProjectId | Should -Be $results[0].id + $results[0].creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } - Context 'Get a closed Repo project' { + Context 'Get a closed Repo project (via pipeline)' { BeforeAll { - $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultProjectClosed -Description $defaultProjectClosedDesc + $project = $repo | New-GitHubProject -Name $defaultProjectClosed -Description $defaultProjectClosedDesc $null = Set-GitHubProject -Project $project.id -State Closed } @@ -131,7 +153,7 @@ try $null = Remove-GitHubProject -Project $project.id -Confirm:$false } - $results = @(Get-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -State 'Closed' | Where-Object Name -eq $defaultProjectClosed) + $results = @($repo | Get-GitHubProject -State 'Closed') It 'Should get project' { $results | Should -Not -BeNullOrEmpty } @@ -151,6 +173,87 @@ try It 'State is correct' { $results[0].state | Should -Be "Closed" } + + It 'Should have the expected type and additional properties' { + $results[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $results[0].RepositoryUrl | Should -Be $repo.RepositoryUrl + $results[0].ProjectId | Should -Be $results[0].id + $results[0].creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Get a specific project (by parameter)' { + BeforeAll { + $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultRepoProject -Description $defaultRepoProjectDesc + } + + AfterAll { + $null = Remove-GitHubProject -Project $project.id -Confirm:$false + } + + $result = Get-GitHubProject -Project $project.id + It 'Should get project' { + $result | Should -Not -BeNullOrEmpty + } + + It 'Name is correct' { + $result.name | Should -Be $defaultRepoProject + } + + It 'Description is correct' { + $result.body | Should -Be $defaultRepoProjectDesc + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.ProjectId | Should -Be $project.id + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Get a specific project (by pipeline object)' { + BeforeAll { + $project = $repo | New-GitHubProject -Name $defaultRepoProject -Description $defaultRepoProjectDesc + } + + AfterAll { + $project | Remove-GitHubProject -Force + } + + $result = $project | Get-GitHubProject + It 'Should get the right project' { + $result.id | Should -Be $project.id + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.ProjectId | Should -Be $project.id + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Get a specific project (with ID via pipeline)' { + BeforeAll { + $project = $repo | New-GitHubProject -Name $defaultRepoProject -Description $defaultRepoProjectDesc + } + + AfterAll { + $project | Remove-GitHubProject -Force + } + + $result = $project.id | Get-GitHubProject + It 'Should get the right project' { + $result.id | Should -Be $project.id + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.ProjectId | Should -Be $project.id + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } } @@ -177,6 +280,75 @@ try It 'Description should be updated' { $result.body | Should -Be $modifiedUserProjectDesc } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $result.RepositoryUrl | Should -BeNullOrEmpty # no RepositoryUrl for user projects + $result.ProjectId | Should -Be $result.id + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Modify User projects (via ID in pipeline)' { + BeforeAll { + $project = New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc + } + + AfterAll { + $null = Remove-GitHubProject -Project $project.id -Confirm:$false + } + + $null = $project.id | Set-GitHubProject -Description $modifiedUserProjectDesc + $result = Get-GitHubProject -Project $project.id + It 'Should get project' { + $result | Should -Not -BeNullOrEmpty + } + + It 'Name is correct' { + $result.name | Should -Be $defaultUserProject + } + + It 'Description should be updated' { + $result.body | Should -Be $modifiedUserProjectDesc + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $result.RepositoryUrl | Should -BeNullOrEmpty # no RepositoryUrl for user projects + $result.ProjectId | Should -Be $result.id + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Modify User projects (via object in pipeline)' { + BeforeAll { + $project = New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc + } + + AfterAll { + $null = Remove-GitHubProject -Project $project.id -Confirm:$false + } + + $null = $project | Set-GitHubProject -Description $modifiedUserProjectDesc + $result = Get-GitHubProject -Project $project.id + It 'Should get project' { + $result | Should -Not -BeNullOrEmpty + } + + It 'Name is correct' { + $result.name | Should -Be $defaultUserProject + } + + It 'Description should be updated' { + $result.body | Should -Be $modifiedUserProjectDesc + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $result.RepositoryUrl | Should -BeNullOrEmpty # no RepositoryUrl for user projects + $result.ProjectId | Should -Be $result.id + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } Context 'Modify Organization projects' { @@ -210,6 +382,15 @@ try $result.organization_permission | Should -Be 'admin' } + It 'Should have the expected type and additional properties' { + $elements = Split-GitHubUri -Uri $result.html_url + $repositoryUrl = Join-GitHubUri @elements + + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $result.RepositoryUrl | Should -Be $repositoryUrl + $result.ProjectId | Should -Be $result.id + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } Context 'Modify Repo projects' { @@ -234,6 +415,13 @@ try It 'Description should be updated' { $result.body | Should -Be $modifiedRepoProjectDesc } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.ProjectId | Should -Be $result.id + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } } @@ -261,6 +449,45 @@ try It 'Description should be updated' { $result.body | Should -Be $defaultUserProjectDesc } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $result.RepositoryUrl | Should -BeNullOrEmpty # no RepositoryUrl for user projects + $result.ProjectId | Should -Be $result.id + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Create User project (title on pipeline)' { + BeforeAll { + $project = @{id = 0} + } + + AfterAll { + $null = Remove-GitHubProject -Project $project.id -Confirm:$false + Remove-Variable project + } + + $project.id = ($defaultUserProject | New-GitHubProject -UserProject -Description $defaultUserProjectDesc).id + $result = Get-GitHubProject -Project $project.id + It 'Project exists' { + $result | Should -Not -BeNullOrEmpty + } + + It 'Name is correct' { + $result.name | Should -Be $defaultUserProject + } + + It 'Description should be updated' { + $result.body | Should -Be $defaultUserProjectDesc + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $result.RepositoryUrl | Should -BeNullOrEmpty # no RepositoryUrl for user projects + $result.ProjectId | Should -Be $result.id + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } Context 'Create Organization projects' { @@ -286,6 +513,16 @@ try It 'Description should be updated' { $result.body | Should -Be $defaultOrgProjectDesc } + + It 'Should have the expected type and additional properties' { + $elements = Split-GitHubUri -Uri $result.html_url + $repositoryUrl = Join-GitHubUri @elements + + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $result.RepositoryUrl | Should -Be $repositoryUrl + $result.ProjectId | Should -Be $result.id + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } Context 'Create Repo projects' { @@ -311,6 +548,45 @@ try It 'Description should be updated' { $result.body | Should -Be $defaultRepoProjectDesc } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.ProjectId | Should -Be $result.id + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Create Repo project (via pipeline)' { + BeforeAll { + $project = @{id = 0} + } + + AfterAll { + $null = Remove-GitHubProject -Project $project.id -Confirm:$false + Remove-Variable project + } + + $project.id = ($repo | New-GitHubProject -Name $defaultRepoProject -Description $defaultRepoProjectDesc).id + $result = Get-GitHubProject -Project $project.id + It 'Project Exists' { + $result | Should -Not -BeNullOrEmpty + } + + It 'Name is correct' { + $result.name | Should -Be $defaultRepoProject + } + + It 'Description should be updated' { + $result.body | Should -Be $defaultRepoProjectDesc + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Project' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.ProjectId | Should -Be $result.id + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } } @@ -347,6 +623,17 @@ try {Get-GitHubProject -Project $project.id} | Should -Throw } } + + Context 'Remove Repo project via pipeline' { + BeforeAll { + $project = $repo | New-GitHubProject -Name $defaultRepoProject -Description $defaultRepoProjectDesc + } + + $project | Remove-GitHubProject -Force + It 'Project should be removed' { + {$project | Get-GitHubProject} | Should -Throw + } + } } Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false From c5e070b261f0a3f06f6c85080b1c31712b2dc29c Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 12 Jun 2020 14:48:46 -0700 Subject: [PATCH 46/80] Update project column tests --- GitHubProjectColumns.ps1 | 5 +- Tests/GitHubProjectColumns.tests.ps1 | 146 +++++++++++++++++++++++++++ 2 files changed, 150 insertions(+), 1 deletion(-) diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index ca4cc861..9e347880 100644 --- a/GitHubProjectColumns.ps1 +++ b/GitHubProjectColumns.ps1 @@ -60,6 +60,7 @@ filter Get-GitHubProjectColumn [Parameter( Mandatory, + ValueFromPipeline, ValueFromPipelineByPropertyName, ParameterSetName = 'Column')] [Alias('ColumnId')] @@ -149,7 +150,9 @@ filter New-GitHubProjectColumn [Alias('ProjectId')] [int64] $Project, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline)] [string] $Name, [string] $AccessToken, diff --git a/Tests/GitHubProjectColumns.tests.ps1 b/Tests/GitHubProjectColumns.tests.ps1 index 6ce4a009..8cdbfdea 100644 --- a/Tests/GitHubProjectColumns.tests.ps1 +++ b/Tests/GitHubProjectColumns.tests.ps1 @@ -51,6 +51,61 @@ try It 'Name is correct' { $results[0].name | Should -Be $defaultColumn } + + It 'Should have the expected type and additional properties' { + $results[0].PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' + $results[0].ColumnId | Should -Be $results[0].id + $results[0].ColumnName | Should -Be $results[0].name + } + } + + Context 'Get columns for a project (via pipeline)' { + $results = @($project | Get-GitHubProjectColumn) + It 'Should get column' { + $results | Should -Not -BeNullOrEmpty + } + + It 'Should only have one column' { + $results.Count | Should -Be 1 + } + + It 'Name is correct' { + $results[0].name | Should -Be $defaultColumn + } + + It 'Should have the expected type and additional properties' { + $results[0].PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' + $results[0].ColumnId | Should -Be $results[0].id + $results[0].ColumnName | Should -Be $results[0].name + } + } + + Context 'Get specific column' { + $result = Get-GitHubProjectColumn -Column $column.id + + It 'Should be the right column' { + $result.id | Should -Be $column.id + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' + $result.ColumnId | Should -Be $result.id + $result.ColumnName | Should -Be $result.name + } + } + + Context 'Get specific column (via pipeline)' { + $result = $column | Get-GitHubProjectColumn + + It 'Should be the right column' { + $result.id | Should -Be $column.id + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' + $result.ColumnId | Should -Be $result.id + $result.ColumnName | Should -Be $result.name + } } } @@ -76,6 +131,12 @@ try It 'Name has been updated' { $result.name | Should -Be $defaultColumnUpdate } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' + $result.ColumnId | Should -Be $result.id + $result.ColumnName | Should -Be $result.name + } } Context 'Move column to first position' { @@ -89,6 +150,12 @@ try It 'Column is now in the first position' { $results[0].name | Should -Be $defaultColumnTwo } + + It 'Should have the expected type and additional properties' { + $results[0].PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' + $results[0].ColumnId | Should -Be $results[0].id + $results[0].ColumnName | Should -Be $results[0].name + } } Context 'Move column using after parameter' { @@ -98,6 +165,12 @@ try It 'Column is now not in the first position' { $results[1].name | Should -Be $defaultColumnTwo } + + It 'Should have the expected type and additional properties' { + $results[1].PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' + $results[1].ColumnId | Should -Be $columntwo.ColumnId + $results[1].ColumnName | Should -Be $columntwo.ColumnName + } } Context 'Move command throws appropriate error' { @@ -128,6 +201,68 @@ try It 'Name is correct' { $result.name | Should -Be $defaultColumn } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' + $result.ColumnId | Should -Be $result.id + $result.ColumnName | Should -Be $result.name + } + } + + Context 'Create project column (object via pipeline)' { + BeforeAll { + $column = @{id = 0} + } + + AfterAll { + $null = Remove-GitHubProjectColumn -Column $column.id -Force + Remove-Variable -Name column + } + + $column.id = ($project | New-GitHubProjectColumn -Name $defaultColumn).id + $result = Get-GitHubProjectColumn -Column $column.id + + It 'Column exists' { + $result | Should -Not -BeNullOrEmpty + } + + It 'Name is correct' { + $result.name | Should -Be $defaultColumn + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' + $result.ColumnId | Should -Be $result.id + $result.ColumnName | Should -Be $result.name + } + } + + Context 'Create project column (name via pipeline)' { + BeforeAll { + $column = @{id = 0} + } + + AfterAll { + $null = Remove-GitHubProjectColumn -Column $column.id -Force + Remove-Variable -Name column + } + + $column.id = ($defaultColumn | New-GitHubProjectColumn -Project $project.id).id + $result = Get-GitHubProjectColumn -Column $column.id + + It 'Column exists' { + $result | Should -Not -BeNullOrEmpty + } + + It 'Name is correct' { + $result.name | Should -Be $defaultColumn + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' + $result.ColumnId | Should -Be $result.id + $result.ColumnName | Should -Be $result.name + } } } @@ -142,6 +277,17 @@ try {Get-GitHubProjectColumn -Column $column.id} | Should -Throw } } + + Context 'Remove project column (via pipeline)' { + BeforeAll { + $column = New-GitHubProjectColumn -Project $project.id -Name $defaultColumn + } + + $column | Remove-GitHubProjectColumn -Force + It 'Project column should be removed' { + {$column | Get-GitHubProjectColumn} | Should -Throw + } + } } Remove-GitHubProject -Project $project.id -Confirm:$false From 07031e3408d4e6af148b646df200897a06eb4d67 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 12 Jun 2020 17:14:43 -0700 Subject: [PATCH 47/80] Update project card tests and improve project card function signatures --- GitHubProjectCards.ps1 | 128 ++++++++---- GitHubProjectColumns.ps1 | 8 +- Tests/GitHubProjectCards.tests.ps1 | 296 ++++++++++++++++++++++++++- Tests/GitHubProjectColumns.tests.ps1 | 10 + 4 files changed, 393 insertions(+), 49 deletions(-) diff --git a/GitHubProjectCards.ps1 b/GitHubProjectCards.ps1 index 984bf4c4..935ed73b 100644 --- a/GitHubProjectCards.ps1 +++ b/GitHubProjectCards.ps1 @@ -18,8 +18,8 @@ filter Get-GitHubProjectCard .PARAMETER Column ID of the column to retrieve cards for. - .PARAMETER ArchivedState - Only cards with this ArchivedState are returned. + .PARAMETER State + Only cards with this State are returned. Options are all, archived, or NotArchived (default). .PARAMETER AccessToken @@ -41,12 +41,12 @@ filter Get-GitHubProjectCard Get the the not_archived cards for column 999999. .EXAMPLE - Get-GitHubProjectCard -Column 999999 -ArchivedState All + Get-GitHubProjectCard -Column 999999 -State All - Gets all the cards for column 999999, no matter the ArchivedState. + Gets all the cards for column 999999, no matter the State. .EXAMPLE - Get-GitHubProjectCard -Column 999999 -ArchivedState Archived + Get-GitHubProjectCard -Column 999999 -State Archived Gets the archived cards for column 999999. @@ -57,7 +57,7 @@ filter Get-GitHubProjectCard #> [CmdletBinding( SupportsShouldProcess, - DefaultParameterSetName = 'Column')] + DefaultParameterSetName = 'Card')] [OutputType({$script:GitHubProjectCardTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( @@ -76,7 +76,8 @@ filter Get-GitHubProjectCard [int64] $Card, [ValidateSet('All', 'Archived', 'NotArchived')] - [string] $ArchivedState = 'NotArchived', + [Alias('ArchivedState')] + [string] $State = 'NotArchived', [string] $AccessToken, @@ -105,14 +106,14 @@ filter Get-GitHubProjectCard $description = "Getting project card $Card" } - if ($PSBoundParameters.ContainsKey('ArchivedState')) + if ($PSBoundParameters.ContainsKey('State')) { $getParams = @() - $Archived = $ArchivedState.ToLower().Replace('notarchived','not_archived') + $Archived = $State.ToLower().Replace('notarchived','not_archived') $getParams += "archived_state=$Archived" $uriFragment = "$uriFragment`?" + ($getParams -join '&') - $description += " with ArchivedState '$Archived'" + $description += " with State '$Archived'" } $params = @{ @@ -142,13 +143,13 @@ filter New-GitHubProjectCard .PARAMETER Note The name of the column to create. - .PARAMETER ContentId - The issue or pull request ID you want to associate with this card. + .PARAMETER IssueId + The ID of the issue you want to associate with this card (not to be confused with + the Issue _number_ which you see in the URL and can refer to with a hashtag). - .PARAMETER ContentType - The type of content you want to associate with this card. - Required if you provide ContentId. - Use Issue when ContentId is an issue ID and use PullRequest when ContentId is a pull request id. + .PARAMETER PullRequestId + The ID of the pull request you want to associate with this card (not to be confused with + the Pull Request _number_ which you see in the URL and can refer to with a hashtag). .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the @@ -169,19 +170,14 @@ filter New-GitHubProjectCard Creates a card on column 999999 with the note 'Note on card'. .EXAMPLE - New-GitHubProjectCard -Column 999999 -ContentId 888888 -ContentType Issue + New-GitHubProjectCard -Column 999999 -IssueId 888888 Creates a card on column 999999 for the issue with ID 888888. .EXAMPLE - New-GitHubProjectCard -Column 999999 -ContentId 888888 -ContentType Issue + New-GitHubProjectCard -Column 999999 -PullRequestId 888888 - Creates a card on column 999999 for the issue with ID 888888. - - .EXAMPLE - New-GitHubProjectCard -Column 999999 -ContentId 777777 -ContentType PullRequest - - Creates a card on column 999999 for the pull request with ID 777777. + Creates a card on column 999999 for the pull request with ID 888888. #> [CmdletBinding( SupportsShouldProcess, @@ -196,15 +192,23 @@ filter New-GitHubProjectCard [Alias('ColumnId')] [int64] $Column, - [Parameter(Mandatory, ParameterSetName = 'Note')] + [Parameter( + Mandatory, + ParameterSetName = 'Note')] + [Alias('Content')] [string] $Note, - [Parameter(Mandatory, ParameterSetName = 'Content')] - [int64] $ContentId, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName = 'Issue')] + [int64] $IssueId, - [Parameter(Mandatory, ParameterSetName = 'Content')] - [ValidateSet('Issue', 'PullRequest')] - [string] $ContentType, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName = 'PullRequest')] + [int64] $PullRequestId, [string] $AccessToken, @@ -226,13 +230,22 @@ filter New-GitHubProjectCard 'note' = $Note } } - elseif ($PSCmdlet.ParameterSetName -eq 'Content') + elseif ($PSCmdlet.ParameterSetName -in ('Issue', 'PullRequest')) { - $telemetryProperties['Content'] = $true + $contentType = $PSCmdlet.ParameterSetName + $telemetryProperties['ContentType'] = $contentType $hashBody = @{ - 'content_id' = $ContentId - 'content_type' = $ContentType + 'content_type' = $contentType + } + + if ($PSCmdlet.ParameterSetName -eq 'Issue') + { + $hashBody['content_id'] = $IssueId + } + else + { + $hashBody['content_id'] = $PullRequestId } } @@ -312,6 +325,7 @@ filter Set-GitHubProjectCard [Alias('CardId')] [int64] $Card, + [Alias('Content')] [string] $Note, [Parameter(ParameterSetName = 'Archive')] @@ -474,7 +488,7 @@ filter Move-GitHubProjectCard .PARAMETER After Moves the card to the position after the card ID specified. - .PARAMETER ColumnId + .PARAMETER Column The ID of a column in the same project to move the card to. .PARAMETER AccessToken @@ -504,7 +518,7 @@ filter Move-GitHubProjectCard Within the same column. .EXAMPLE - Move-GitHubProjectCard -Card 999999 -After 888888 -ColumnId 123456 + Move-GitHubProjectCard -Card 999999 -After 888888 -Column 123456 Moves the project card with ID 999999 to the position after the card ID 888888, in the column with ID 123456. @@ -524,7 +538,9 @@ filter Move-GitHubProjectCard [int64] $After, - [int64] $ColumnId, + [Parameter(ValueFromPipelineByPropertyName)] + [Alias('ColumnId')] + [int64] $Column, [string] $AccessToken, @@ -561,10 +577,10 @@ filter Move-GitHubProjectCard 'position' = $Position } - if ($PSBoundParameters.ContainsKey('ColumnId')) + if ($PSBoundParameters.ContainsKey('Column')) { - $telemetryProperties['ColumnId'] = $true - $hashBody.add('column_id', $ColumnId) + $telemetryProperties['Column'] = $true + $hashBody.add('column_id', $Column) } $params = @{ @@ -606,7 +622,7 @@ filter Add-GitHubProjectCardAdditionalProperties [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] - [string] $TypeName = $script:GitHubProjectColumnTypeName + [string] $TypeName = $script:GitHubProjectCardTypeName ) foreach ($item in $InputObject) @@ -617,6 +633,36 @@ filter Add-GitHubProjectCardAdditionalProperties { Add-Member -InputObject $item -Name 'CardId' -Value $item.id -MemberType NoteProperty -Force + if ($item.project_url -match '^.*/projects/(\d+)$') + { + $projectId = $Matches[1] + Add-Member -InputObject $item -Name 'ProjectId' -Value $projectId -MemberType NoteProperty -Force + } + + if ($item.column_url -match '^.*/columns/(\d+)$') + { + $columnId = $Matches[1] + Add-Member -InputObject $item -Name 'ColumnId' -Value $columnId -MemberType NoteProperty -Force + } + + if ($null -ne $item.content_url) + { + $elements = Split-GitHubUri -Uri $item.content_url + $repositoryUrl = Join-GitHubUri @elements + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + + if ($item.content_url -match '^.*/issues/(\d+)$') + { + $issueNumber = $Matches[1] + Add-Member -InputObject $item -Name 'IssueNumber' -Value $issueNumber -MemberType NoteProperty -Force + } + elseif ($item.content_url -match '^.*/pull/(\d+)$') + { + $pullRequestNumber = $Matches[1] + Add-Member -InputObject $item -Name 'PullRequestNumber' -Value $pullRequestNumber -MemberType NoteProperty -Force + } + } + if ($null -ne $item.creator) { $null = Add-GitHubUserAdditionalProperties -InputObject $item.creator diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index 9e347880..8932bfff 100644 --- a/GitHubProjectColumns.ps1 +++ b/GitHubProjectColumns.ps1 @@ -46,7 +46,7 @@ filter Get-GitHubProjectColumn #> [CmdletBinding( SupportsShouldProcess, - DefaultParameterSetName = 'Project')] + DefaultParameterSetName = 'Column')] [OutputType({$script:GitHubProjectColumnTypeName})] [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.")] @@ -497,6 +497,12 @@ filter Add-GitHubProjectColumnAdditionalProperties { Add-Member -InputObject $item -Name 'ColumnId' -Value $item.id -MemberType NoteProperty -Force Add-Member -InputObject $item -Name 'ColumnName' -Value $item.name -MemberType NoteProperty -Force + + if ($item.project_url -match '^.*/projects/(\d+)$') + { + $projectId = $Matches[1] + Add-Member -InputObject $item -Name 'ProjectId' -Value $projectId -MemberType NoteProperty -Force + } } Write-Output $item diff --git a/Tests/GitHubProjectCards.tests.ps1 b/Tests/GitHubProjectCards.tests.ps1 index 9c2d4075..4308783b 100644 --- a/Tests/GitHubProjectCards.tests.ps1 +++ b/Tests/GitHubProjectCards.tests.ps1 @@ -34,7 +34,7 @@ try } $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - $project = New-GitHubProject -Owner $script:ownerName -Repository $repo.name -Name $defaultProject + $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultProject $column = New-GitHubProjectColumn -Project $project.id -Name $defaultColumn $columntwo = New-GitHubProjectColumn -Project $project.id -Name $defaultColumnTwo @@ -54,24 +54,55 @@ try Context 'Get cards for a column' { $results = @(Get-GitHubProjectCard -Column $column.id) + It 'Should get cards' { $results | Should -Not -BeNullOrEmpty } + It 'Should only have one card (since it defaults to not archived)' { + $results.Count | Should -Be 1 + } + It 'Note is correct' { - $results.note | Should -Be $defaultCard + $results[0].note | Should -Be $defaultCard + } + + It 'Has the expected type and additional properties' { + $results[0].PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $results[0].CardId | Should -Be $results[0].id + $results[0].ProjectId | Should -Be $project.id + $results[0].ColumnId | Should -Be $column.id + $results[0].IssueNumber | Should -BeNullOrEmpty + $results[0].RepositoryUrl | Should -BeNullOrEmpty + $results[0].PullRequestNumber | Should -BeNullOrEmpty + $results[0].creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' } } Context 'Get all cards for a column' { - $results = @(Get-GitHubProjectCard -Column $column.id -ArchivedState All) + $results = @(Get-GitHubProjectCard -Column $column.id -State All) + It 'Should get all cards' { $results.Count | Should -Be 2 } + + It 'Has the expected type and additional properties' { + foreach ($item in $results) + { + $item.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $item.CardId | Should -Be $item.id + $item.ProjectId | Should -Be $project.id + $item.ColumnId | Should -Be $column.id + $item.IssueNumber | Should -BeNullOrEmpty + $item.RepositoryUrl | Should -BeNullOrEmpty + $item.PullRequestNumber | Should -BeNullOrEmpty + $item.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } } Context 'Get archived cards for a column' { - $result = Get-GitHubProjectCard -Column $column.id -ArchivedState Archived + $result = Get-GitHubProjectCard -Column $column.id -State Archived It 'Should get archived card' { $result | Should -Not -BeNullOrEmpty } @@ -83,6 +114,44 @@ try It 'Should be archived' { $result.Archived | Should -Be $true } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $result.CardId | Should -Be $result.id + $result.ProjectId | Should -Be $project.id + $result.ColumnId | Should -Be $column.id + $result.IssueNumber | Should -BeNullOrEmpty + $result.RepositoryUrl | Should -BeNullOrEmpty + $result.PullRequestNumber | Should -BeNullOrEmpty + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Get non-archived cards for a column (with column on pipeline)' { + $result = $column | Get-GitHubProjectCard -State NotArchived + + It 'Should get non-archived card' { + $result | Should -Not -BeNullOrEmpty + } + + It 'Should have the right ID' { + $result.id | Should -Be $card.id + } + + It 'Should not be archived' { + $result.Archived | Should -Be $false + } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $result.CardId | Should -Be $result.id + $result.ProjectId | Should -Be $project.id + $result.ColumnId | Should -Be $column.id + $result.IssueNumber | Should -BeNullOrEmpty + $result.RepositoryUrl | Should -BeNullOrEmpty + $result.PullRequestNumber | Should -BeNullOrEmpty + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } } @@ -108,6 +177,43 @@ try It 'Note has been updated' { $result.note | Should -Be $defaultCardUpdated } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $result.CardId | Should -Be $result.id + $result.ProjectId | Should -Be $project.id + $result.ColumnId | Should -Be $column.id + $result.IssueNumber | Should -BeNullOrEmpty + $result.RepositoryUrl | Should -BeNullOrEmpty + $result.PullRequestNumber | Should -BeNullOrEmpty + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Modify card note (via card on pipeline)' { + $result = $card | Get-GitHubProjectCard + + It 'Should have the expected Note value' { + $result.note | Should -Be $defaultCardUpdated + } + + $null = $card | Set-GitHubProjectCard -Note $defaultCard + $result = $card | Get-GitHubProjectCard + + It 'Should have the updated Note' { + $result.note | Should -Be $defaultCard + } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $result.CardId | Should -Be $result.id + $result.ProjectId | Should -Be $project.id + $result.ColumnId | Should -Be $column.id + $result.IssueNumber | Should -BeNullOrEmpty + $result.RepositoryUrl | Should -BeNullOrEmpty + $result.PullRequestNumber | Should -BeNullOrEmpty + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } Context 'Archive a card' { @@ -124,7 +230,7 @@ try } Context 'Restore a card' { - $null = Set-GitHubProjectCard -Card $cardArchived.id -Restore + $null = $cardArchived | Set-GitHubProjectCard -Restore $result = Get-GitHubProjectCard -Card $cardArchived.id It 'Should get card' { @@ -143,6 +249,17 @@ try It 'Card is now top' { $results[0].note | Should -Be $defaultCardTwo } + + It 'Has the expected type and additional properties' { + $results[0].PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $results[0].CardId | Should -Be $results[0].id + $results[0].ProjectId | Should -Be $project.id + $results[0].ColumnId | Should -Be $column.id + $results[0].IssueNumber | Should -BeNullOrEmpty + $results[0].RepositoryUrl | Should -BeNullOrEmpty + $results[0].PullRequestNumber | Should -BeNullOrEmpty + $results[0].creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } Context 'Move card using after parameter' { @@ -152,6 +269,37 @@ try It 'Card now exists in new column' { $results[1].note | Should -Be $defaultCardTwo } + + It 'Has the expected type and additional properties' { + $results[1].PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $results[1].CardId | Should -Be $results[1].id + $results[1].ProjectId | Should -Be $project.id + $results[1].ColumnId | Should -Be $column.id + $results[1].IssueNumber | Should -BeNullOrEmpty + $results[1].RepositoryUrl | Should -BeNullOrEmpty + $results[1].PullRequestNumber | Should -BeNullOrEmpty + $results[1].creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Move card using before parameter (card on pipeline)' { + $null = $cardTwo | Move-GitHubProjectCard -After $card.id + $results = @($column | Get-GitHubProjectCard) + + It 'Card now exists in new column' { + $results[1].note | Should -Be $defaultCardTwo + } + + It 'Has the expected type and additional properties' { + $results[1].PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $results[1].CardId | Should -Be $results[1].id + $results[1].ProjectId | Should -Be $project.id + $results[1].ColumnId | Should -Be $column.id + $results[1].IssueNumber | Should -BeNullOrEmpty + $results[1].RepositoryUrl | Should -BeNullOrEmpty + $results[1].PullRequestNumber | Should -BeNullOrEmpty + $results[1].creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } Context 'Move card to another column' { @@ -161,6 +309,37 @@ try It 'Card now exists in new column' { $results[0].note | Should -Be $defaultCardTwo } + + It 'Has the expected type and additional properties' { + $results[0].PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $results[0].CardId | Should -Be $results[0].id + $results[0].ProjectId | Should -Be $project.id + $results[0].ColumnId | Should -Be $columnTwo.id + $results[0].IssueNumber | Should -BeNullOrEmpty + $results[0].RepositoryUrl | Should -BeNullOrEmpty + $results[0].PullRequestNumber | Should -BeNullOrEmpty + $results[0].creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Move card to another column (with column on pipeline)' { + $null = ($column | Move-GitHubProjectCard -Card $cardTwo.id -Top) + $result = $cardTwo | Get-GitHubProjectCard + + It 'Card now exists in new column' { + $result.ColumnId | Should -Be $column.ColumnId + } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $result.CardId | Should -Be $result.id + $result.ProjectId | Should -Be $project.id + $result.ColumnId | Should -Be $column.id + $result.IssueNumber | Should -BeNullOrEmpty + $result.RepositoryUrl | Should -BeNullOrEmpty + $result.PullRequestNumber | Should -BeNullOrEmpty + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } Context 'Move command throws appropriate error' { @@ -170,7 +349,7 @@ try } } - Describe 'Create Project Cards' -tag new { + Describe 'Create Project Cards' { Context 'Create project card with note' { BeforeAll { $card = @{id = 0} @@ -191,6 +370,51 @@ try It 'Note is correct' { $result.note | Should -Be $defaultCard } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $result.CardId | Should -Be $result.id + $result.ProjectId | Should -Be $project.id + $result.ColumnId | Should -Be $column.id + $result.IssueNumber | Should -BeNullOrEmpty + $result.RepositoryUrl | Should -BeNullOrEmpty + $result.PullRequestNumber | Should -BeNullOrEmpty + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Create project card with note (with column object via pipeline)' { + BeforeAll { + $card = @{id = 0} + } + + AfterAll { + $null = Remove-GitHubProjectCard -Card $card.id -Confirm:$false + Remove-Variable -Name card + } + + $newCard = $column | New-GitHubProjectCard -Note $defaultCard + $card.id = $newCard.id + $result = $newCard | Get-GitHubProjectCard + + It 'Card exists' { + $result | Should -Not -BeNullOrEmpty + } + + It 'Note is correct' { + $result.note | Should -Be $defaultCard + } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $result.CardId | Should -Be $result.id + $result.ProjectId | Should -Be $project.id + $result.ColumnId | Should -Be $column.id + $result.IssueNumber | Should -BeNullOrEmpty + $result.RepositoryUrl | Should -BeNullOrEmpty + $result.PullRequestNumber | Should -BeNullOrEmpty + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } Context 'Create project card from issue' { @@ -203,7 +427,7 @@ try Remove-Variable -Name card } - $card.id = (New-GitHubProjectCard -Column $column.id -ContentId $issue.id -ContentType 'Issue').id + $card.id = (New-GitHubProjectCard -Column $column.id -IssueId $issue.id).id $result = Get-GitHubProjectCard -Card $card.id It 'Card exists' { @@ -213,7 +437,54 @@ try It 'Content url is for an issue' { $result.content_url | Should -Match 'issues' } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $result.CardId | Should -Be $result.id + $result.ProjectId | Should -Be $project.id + $result.ColumnId | Should -Be $column.id + $result.IssueNumber | Should -Be $issue.number + $result.RepositoryUrl | Should -Be $issue.RepositoryUrl + $result.PullRequestNumber | Should -BeNullOrEmpty + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } + + Context 'Create project card from issue (with issue object on pipeline)' { + BeforeAll { + $card = @{id = 0} + } + + AfterAll { + $null = Remove-GitHubProjectCard -Card $card.id -Force + Remove-Variable -Name card + } + + $newCard = $issue | New-GitHubProjectCard -Column $column.id + $card.id = $newCard.id + $result = $newCard | Get-GitHubProjectCard + + It 'Card exists' { + $result | Should -Not -BeNullOrEmpty + } + + It 'Content url is for an issue' { + $result.content_url | Should -Match 'issues' + } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectCard' + $result.CardId | Should -Be $result.id + $result.ProjectId | Should -Be $project.id + $result.ColumnId | Should -Be $column.id + $result.IssueNumber | Should -Be $issue.number + $result.RepositoryUrl | Should -Be $issue.RepositoryUrl + $result.PullRequestNumber | Should -BeNullOrEmpty + $result.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + # TODO: Create a test that verifies cards created based on a pull request } Describe 'Remove card' { @@ -227,6 +498,17 @@ try {Get-GitHubProjectCard -Card $card.id} | Should -Throw } } + + Context 'Remove card (via pipeline)' { + BeforeAll { + $card = $column | New-GitHubProjectCard -Note $defaultCard + } + + $null = $card | Remove-GitHubProjectCard -Force + It 'Project card should be removed' { + {$card | Get-GitHubProjectCard} | Should -Throw + } + } } Remove-GitHubProject -Project $project.id -Confirm:$false diff --git a/Tests/GitHubProjectColumns.tests.ps1 b/Tests/GitHubProjectColumns.tests.ps1 index 8cdbfdea..b9233134 100644 --- a/Tests/GitHubProjectColumns.tests.ps1 +++ b/Tests/GitHubProjectColumns.tests.ps1 @@ -56,6 +56,7 @@ try $results[0].PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' $results[0].ColumnId | Should -Be $results[0].id $results[0].ColumnName | Should -Be $results[0].name + $results[0].ProjectId | Should -Be $project.id } } @@ -77,6 +78,7 @@ try $results[0].PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' $results[0].ColumnId | Should -Be $results[0].id $results[0].ColumnName | Should -Be $results[0].name + $results[0].ProjectId | Should -Be $project.id } } @@ -91,6 +93,7 @@ try $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' $result.ColumnId | Should -Be $result.id $result.ColumnName | Should -Be $result.name + $result.ProjectId | Should -Be $project.id } } @@ -105,6 +108,7 @@ try $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' $result.ColumnId | Should -Be $result.id $result.ColumnName | Should -Be $result.name + $result.ProjectId | Should -Be $project.id } } } @@ -136,6 +140,7 @@ try $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' $result.ColumnId | Should -Be $result.id $result.ColumnName | Should -Be $result.name + $result.ProjectId | Should -Be $project.id } } @@ -155,6 +160,7 @@ try $results[0].PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' $results[0].ColumnId | Should -Be $results[0].id $results[0].ColumnName | Should -Be $results[0].name + $results[0].ProjectId | Should -Be $project.id } } @@ -170,6 +176,7 @@ try $results[1].PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' $results[1].ColumnId | Should -Be $columntwo.ColumnId $results[1].ColumnName | Should -Be $columntwo.ColumnName + $results[1].ProjectId | Should -Be $project.id } } @@ -206,6 +213,7 @@ try $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' $result.ColumnId | Should -Be $result.id $result.ColumnName | Should -Be $result.name + $result.ProjectId | Should -Be $project.id } } @@ -234,6 +242,7 @@ try $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' $result.ColumnId | Should -Be $result.id $result.ColumnName | Should -Be $result.name + $result.ProjectId | Should -Be $project.id } } @@ -262,6 +271,7 @@ try $result.PSObject.TypeNames[0] | Should -Be 'GitHub.ProjectColumn' $result.ColumnId | Should -Be $result.id $result.ColumnName | Should -Be $result.name + $result.ProjectId | Should -Be $project.id } } } From 237deee97d9a7525eb502ccfd0d1e4e10771b27e Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 13 Jun 2020 00:41:05 -0700 Subject: [PATCH 48/80] The OwnerName for "Microsoft" should be lowercase --- GitHubAssignees.ps1 | 12 ++++---- GitHubBranches.ps1 | 2 +- GitHubComments.ps1 | 12 ++++---- GitHubEvents.ps1 | 2 +- GitHubIssues.ps1 | 14 ++++----- GitHubMilestones.ps1 | 12 ++++---- GitHubMiscellaneous.ps1 | 4 +-- GitHubProjects.ps1 | 10 +++---- GitHubPullRequests.ps1 | 2 +- GitHubRepositories.ps1 | 16 +++++----- GitHubRepositoryForks.ps1 | 6 ++-- GitHubRepositoryTraffic.ps1 | 8 ++--- USAGE.md | 58 ++++++++++++++++++------------------- 13 files changed, 79 insertions(+), 79 deletions(-) diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index 388608aa..6fed5bb4 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -36,7 +36,7 @@ filter Get-GitHubAssignee GitHub.User .EXAMPLE - Get-GitHubAssigneeList -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubAssigneeList -OwnerName microsoft -RepositoryName PowerShellForGitHub Lists the available assignees for issues from the Microsoft\PowerShellForGitHub project. #> @@ -127,7 +127,7 @@ filter Test-GitHubAssignee If the assignee can be assigned to issues in the repository. .EXAMPLE - Test-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee "LoginID123" + Test-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee "LoginID123" Checks if a user has permission to be assigned to an issue from the Microsoft\PowerShellForGitHub project. #> @@ -235,7 +235,7 @@ filter New-GitHubAssignee GitHub.Issue .EXAMPLE - New-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignee + New-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee $assignee Lists the available assignees for issues from the Microsoft\PowerShellForGitHub project. #> @@ -354,17 +354,17 @@ filter Remove-GitHubAssignee GitHub.Issue .EXAMPLE - Remove-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees + Remove-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees Removes the available assignees for issues from the Microsoft\PowerShellForGitHub project. .EXAMPLE - Remove-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees -Confirm:$false + Remove-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees -Confirm:$false Removes the available assignees for issues from the Microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified. .EXAMPLE - Remove-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees -Force + Remove-GithubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees -Force Removes the available assignees for issues from the Microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Force was specified. #> diff --git a/GitHubBranches.ps1 b/GitHubBranches.ps1 index dda90050..32e78d72 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -49,7 +49,7 @@ filter Get-GitHubRepositoryBranch List of branches within the given repository. .EXAMPLE - Get-GitHubRepositoryBranch -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubRepositoryBranch -OwnerName microsoft -RepositoryName PowerShellForGitHub Gets all branches for the specified repository. diff --git a/GitHubComments.ps1 b/GitHubComments.ps1 index d8d5d88b..ecd0b1e1 100644 --- a/GitHubComments.ps1 +++ b/GitHubComments.ps1 @@ -65,7 +65,7 @@ filter Get-GitHubComment GitHub.Comment .EXAMPLE - Get-GitHubComment-OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubComment-OwnerName microsoft -RepositoryName PowerShellForGitHub Get the comments for the Microsoft\PowerShellForGitHub project. #> @@ -252,7 +252,7 @@ filter New-GitHubComment GitHub.Comment .EXAMPLE - New-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Body "Testing this API" + New-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Body "Testing this API" Creates a new GitHub comment in an issue for the Microsoft\PowerShellForGitHub project. #> @@ -373,7 +373,7 @@ filter Set-GitHubComment GitHub.Comment .EXAMPLE - Set-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Body "Testing this API" + Set-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Body "Testing this API" Update an existing comment in an issue for the Microsoft\PowerShellForGitHub project. #> @@ -483,17 +483,17 @@ filter Remove-GitHubComment If not supplied here, the DefaultNoStatus configuration property value will be used. .EXAMPLE - Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Comment 1 + Remove-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 Deletes a GitHub comment from the Microsoft\PowerShellForGitHub project. .EXAMPLE - Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Confirm:$false + Remove-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Confirm:$false Deletes a Github comment from the Microsoft\PowerShellForGitHub project without prompting confirmation. .EXAMPLE - Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Force + Remove-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Force Deletes a GitHub comment from the Microsoft\PowerShellForGitHub project without prompting confirmation. #> diff --git a/GitHubEvents.ps1 b/GitHubEvents.ps1 index 27930a99..214646bd 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -48,7 +48,7 @@ filter Get-GitHubEvent GitHub.Event .EXAMPLE - Get-GitHubEvent -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubEvent -OwnerName microsoft -RepositoryName PowerShellForGitHub Get the events for the Microsoft\PowerShellForGitHub project. #> diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index 0c6a4671..fd9ba50e 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -115,12 +115,12 @@ filter Get-GitHubIssue GitHub.Issue .EXAMPLE - Get-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -State Open + Get-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -State Open Gets all the currently open issues in the Microsoft\PowerShellForGitHub repository. .EXAMPLE - Get-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -State All -Assignee Octocat + Get-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -State All -Assignee Octocat Gets every issue in the Microsoft\PowerShellForGitHub repository that is assigned to Octocat. #> @@ -394,7 +394,7 @@ filter Get-GitHubIssueTimeline GitHub.Event .EXAMPLE - Get-GitHubIssueTimeline -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 24 + Get-GitHubIssueTimeline -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 24 #> [CmdletBinding( SupportsShouldProcess, @@ -512,7 +512,7 @@ filter New-GitHubIssue GitHub.Issue .EXAMPLE - New-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Title 'Test Issue' + New-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Title 'Test Issue' #> [CmdletBinding( SupportsShouldProcess, @@ -658,7 +658,7 @@ filter Update-GitHubIssue GitHub.Issue .EXAMPLE - Update-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 4 -Title 'Test Issue' -State Closed + Update-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 4 -Title 'Test Issue' -State Closed #> [CmdletBinding( SupportsShouldProcess, @@ -789,7 +789,7 @@ filter Lock-GitHubIssue If not supplied here, the DefaultNoStatus configuration property value will be used. .EXAMPLE - Lock-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 4 -Title 'Test Issue' -Reason Spam + Lock-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 4 -Title 'Test Issue' -Reason Spam #> [CmdletBinding( SupportsShouldProcess, @@ -904,7 +904,7 @@ filter Unlock-GitHubIssue If not supplied here, the DefaultNoStatus configuration property value will be used. .EXAMPLE - Unlock-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 4 + Unlock-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 4 #> [CmdletBinding( SupportsShouldProcess, diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index 9aea3863..f043227e 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -59,7 +59,7 @@ filter Get-GitHubMilestone GitHub.Milestone .EXAMPLE - Get-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub Get the milestones for the Microsoft\PowerShellForGitHub project. .EXAMPLE @@ -238,7 +238,7 @@ filter New-GitHubMilestone GitHub.Milestone .EXAMPLE - New-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Title "Testing this API" + New-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Title "Testing this API" Creates a new GitHub milestone for the Microsoft\PowerShellForGitHub project. @@ -400,7 +400,7 @@ filter Set-GitHubMilestone GitHub.Milestone .EXAMPLE - Set-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Title "Testing this API" + Set-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Title "Testing this API" Update an existing milestone for the Microsoft\PowerShellForGitHub project. @@ -554,18 +554,18 @@ filter Remove-GitHubMilestone If not supplied here, the DefaultNoStatus configuration property value will be used. .EXAMPLE - Remove-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 + Remove-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1 Deletes a GitHub milestone from the Microsoft\PowerShellForGitHub project. .EXAMPLE - Remove-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Confirm:$false + Remove-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Confirm:$false Deletes a Github milestone from the Microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified. .EXAMPLE - Remove-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Force + Remove-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Force Deletes a Github milestone from the Microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Force was specified. diff --git a/GitHubMiscellaneous.ps1 b/GitHubMiscellaneous.ps1 index dd492353..0229f203 100644 --- a/GitHubMiscellaneous.ps1 +++ b/GitHubMiscellaneous.ps1 @@ -243,7 +243,7 @@ filter Get-GitHubLicense Gets the content of the mit license file .EXAMPLE - Get-GitHubLicense -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubLicense -OwnerName microsoft -RepositoryName PowerShellForGitHub Gets the content of the license file for the Microsoft\PowerShellForGitHub repository. It may be necessary to convert the content of the file. Check the 'encoding' property of @@ -433,7 +433,7 @@ filter Get-GitHubCodeOfConduct Gets the content of the 'Citizen Code of Conduct' .EXAMPLE - Get-GitHubCodeOfConduct -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubCodeOfConduct -OwnerName microsoft -RepositoryName PowerShellForGitHub Gets the content of the Code of Conduct file for the Microsoft\PowerShellForGitHub repository if one is detected. diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 5d75083f..acb76f47 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -54,7 +54,7 @@ filter Get-GitHubProject GitHub.Project .EXAMPLE - Get-GitHubProject -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub Get the projects for the Microsoft\PowerShellForGitHub repository. @@ -74,7 +74,7 @@ filter Get-GitHubProject Get the projects for the user GitHubUser. .EXAMPLE - Get-GitHubProject -OwnerName Microsoft -RepositoryName PowerShellForGitHub -State Closed + Get-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub -State Closed Get closed projects from the Microsoft\PowerShellForGitHub repo. @@ -243,7 +243,7 @@ filter New-GitHubProject GitHub.Project .EXAMPLE - New-GitHubProject -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestProject + New-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub -Name TestProject Creates a project called 'TestProject' for the Microsoft\PowerShellForGitHub repository. @@ -403,7 +403,7 @@ filter Set-GitHubProject Set the project with ID '999999' to closed. .EXAMPLE - $project = Get-GitHubProject -OwnerName Microsoft -RepositoryName PowerShellForGitHub | Where-Object Name -eq 'TestProject' + $project = Get-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub | Where-Object Name -eq 'TestProject' Set-GitHubProject -Project $project.id -State Closed Get the ID for the 'TestProject' project for the Microsoft\PowerShellForGitHub @@ -523,7 +523,7 @@ filter Remove-GitHubProject Remove project with ID '4387531' without prompting for confirmation. .EXAMPLE - $project = Get-GitHubProject -OwnerName Microsoft -RepositoryName PowerShellForGitHub | Where-Object Name -eq 'TestProject' + $project = Get-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub | Where-Object Name -eq 'TestProject' Remove-GitHubProject -Project $project.id Get the ID for the 'TestProject' project for the Microsoft\PowerShellForGitHub diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index 50fed095..c0fb5415 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -71,7 +71,7 @@ filter Get-GitHubPullRequest $pullRequests = Get-GitHubPullRequest -Uri 'https://github.com/PowerShell/PowerShellForGitHub' .EXAMPLE - $pullRequests = Get-GitHubPullRequest -OwnerName Microsoft -RepositoryName PowerShellForGitHub -State Closed + $pullRequests = Get-GitHubPullRequest -OwnerName microsoft -RepositoryName PowerShellForGitHub -State Closed #> [CmdletBinding( SupportsShouldProcess, diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index dd6da634..061b0d62 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -863,7 +863,7 @@ filter Update-GitHubRepository GitHub.Repository .EXAMPLE - Update-GitHubRepository -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Description 'The best way to automate your GitHub interactions' + Update-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub -Description 'The best way to automate your GitHub interactions' Changes the description of the specified repository. @@ -1032,7 +1032,7 @@ filter Get-GitHubRepositoryTopic GitHub.RepositoryTopic .EXAMPLE - Get-GitHubRepositoryTopic -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubRepositoryTopic -OwnerName microsoft -RepositoryName PowerShellForGitHub .EXAMPLE Get-GitHubRepositoryTopic -Uri https://github.com/PowerShell/PowerShellForGitHub @@ -1131,7 +1131,7 @@ function Set-GitHubRepositoryTopic GitHub.RepositoryTopic .EXAMPLE - Set-GitHubRepositoryTopic -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Clear + Set-GitHubRepositoryTopic -OwnerName microsoft -RepositoryName PowerShellForGitHub -Clear .EXAMPLE Set-GitHubRepositoryTopic -Uri https://github.com/PowerShell/PowerShellForGitHub -Topic ('octocat', 'powershell', 'github') @@ -1304,7 +1304,7 @@ filter Get-GitHubRepositoryContributor GitHub.RepositoryContributorStatistics .EXAMPLE - Get-GitHubRepositoryContributor -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubRepositoryContributor -OwnerName microsoft -RepositoryName PowerShellForGitHub .EXAMPLE Get-GitHubRepositoryContributor -Uri 'https://github.com/PowerShell/PowerShellForGitHub' -IncludeStatistics @@ -1435,7 +1435,7 @@ filter Get-GitHubRepositoryCollaborator GitHub.User .EXAMPLE - Get-GitHubRepositoryCollaborator -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubRepositoryCollaborator -OwnerName microsoft -RepositoryName PowerShellForGitHub .EXAMPLE Get-GitHubRepositoryCollaborator -Uri 'https://github.com/PowerShell/PowerShellForGitHub' @@ -1533,7 +1533,7 @@ filter Get-GitHubRepositoryLanguage of bytes of code written in that language. .EXAMPLE - Get-GitHubRepositoryLanguage -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubRepositoryLanguage -OwnerName microsoft -RepositoryName PowerShellForGitHub .EXAMPLE Get-GitHubRepositoryLanguage -Uri https://github.com/PowerShell/PowerShellForGitHub @@ -1624,7 +1624,7 @@ filter Get-GitHubRepositoryTag GitHub.RepositoryTag .EXAMPLE - Get-GitHubRepositoryTag -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubRepositoryTag -OwnerName microsoft -RepositoryName PowerShellForGitHub .EXAMPLE Get-GitHubRepositoryTag -Uri https://github.com/PowerShell/PowerShellForGitHub @@ -1722,7 +1722,7 @@ filter Move-GitHubRepositoryOwnership GitHub.Repository .EXAMPLE - Move-GitHubRepositoryOwnership -OwnerName Microsoft -RepositoryName PowerShellForGitHub -NewOwnerName OctoCat + Move-GitHubRepositoryOwnership -OwnerName microsoft -RepositoryName PowerShellForGitHub -NewOwnerName OctoCat #> [CmdletBinding( SupportsShouldProcess, diff --git a/GitHubRepositoryForks.ps1 b/GitHubRepositoryForks.ps1 index 52450631..2829e1c6 100644 --- a/GitHubRepositoryForks.ps1 +++ b/GitHubRepositoryForks.ps1 @@ -42,7 +42,7 @@ filter Get-GitHubRepositoryFork GitHub.Repository .EXAMPLE - Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubRepositoryFork -OwnerName microsoft -RepositoryName PowerShellForGitHub Gets all of the forks for the Microsoft\PowerShellForGitHub repository. #> @@ -145,12 +145,12 @@ filter New-GitHubRepositoryFork GitHub.Repository .EXAMPLE - New-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub + New-GitHubRepositoryFork -OwnerName microsoft -RepositoryName PowerShellForGitHub Creates a fork of this repository under the current authenticated user's account. .EXAMPLE - New-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub -OrganizationName OctoLabs + New-GitHubRepositoryFork -OwnerName microsoft -RepositoryName PowerShellForGitHub -OrganizationName OctoLabs Creates a fork of this repository under the OctoLabs organization. #> diff --git a/GitHubRepositoryTraffic.ps1 b/GitHubRepositoryTraffic.ps1 index 930d7b60..833f0717 100644 --- a/GitHubRepositoryTraffic.ps1 +++ b/GitHubRepositoryTraffic.ps1 @@ -48,7 +48,7 @@ filter Get-GitHubReferrerTraffic GitHub.ReferrerTraffic .EXAMPLE - Get-GitHubReferrerTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubReferrerTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub Get the top 10 referrers over the last 14 days from the Microsoft\PowerShellForGitHub project. #> @@ -141,7 +141,7 @@ filter Get-GitHubPathTraffic GitHub.PathTraffic .EXAMPLE - Get-GitHubPathTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubPathTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub Get the top 10 popular contents over the last 14 days from the Microsoft\PowerShellForGitHub project. #> @@ -238,7 +238,7 @@ filter Get-GitHubViewTraffic GitHub.ViewTraffic .EXAMPLE - Get-GitHubViewTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubViewTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub Get the total number of views and breakdown per day or week for the last 14 days from the Microsoft\PowerShellForGitHub project. #> @@ -339,7 +339,7 @@ filter Get-GitHubCloneTraffic GitHub.CloneTraffic .EXAMPLE - Get-GitHubCloneTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubCloneTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub Get the total number of clones and breakdown per day or week for the last 14 days from the Microsoft\PowerShellForGitHub project. #> diff --git a/USAGE.md b/USAGE.md index f1363af1..a123a91f 100644 --- a/USAGE.md +++ b/USAGE.md @@ -205,7 +205,7 @@ $issueCounts | Sort-Object -Property Count -Descending ```powershell # Getting all of the pull requests from the Microsoft\PowerShellForGitHub repository -$issues = Get-GitHubIssue -OwnerName Microsoft -RepositoryName 'PowerShellForGitHub' +$issues = Get-GitHubIssue -OwnerName microsoft -RepositoryName 'PowerShellForGitHub' ``` ```powershell @@ -324,12 +324,12 @@ Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $repositoryNam #### Removing a Label From an Issue ```powershell -Remove-GitHubIssueLabel -OwnerName Microsoft -RepositoryName DesiredStateConfiguration -Name TestLabel -Issue 1 +Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName DesiredStateConfiguration -Name TestLabel -Issue 1 ``` #### Updating a Label With a New Name and Color ```powershell -Update-GitHubLabel -OwnerName Microsoft -RepositoryName DesiredStateConfiguration -Name TestLabel -NewName NewTestLabel -Color BBBB00 +Update-GitHubLabel -OwnerName microsoft -RepositoryName DesiredStateConfiguration -Name TestLabel -NewName NewTestLabel -Color BBBB00 ``` #### Bulk Updating Labels in a Repository @@ -369,12 +369,12 @@ Get-GitHubUser #### Get all the forks for a repository ```powershell -Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub +Get-GitHubRepositoryFork -OwnerName microsoft -RepositoryName PowerShellForGitHub ``` #### Create a new fork ```powershell -New-GitHubRepositoryForm -OwnerName Microsoft -RepositoryName PowerShellForGitHub +New-GitHubRepositoryForm -OwnerName microsoft -RepositoryName PowerShellForGitHub ``` ---------- @@ -383,22 +383,22 @@ New-GitHubRepositoryForm -OwnerName Microsoft -RepositoryName PowerShellForGitHu #### Get the referrer traffic for a repository ```powershell -Get-GitHubReferrerTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub +Get-GitHubReferrerTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub ``` #### Get the popular content for a repository ```powershell -Get-GitHubPathTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub +Get-GitHubPathTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub ``` #### Get the number of views for a repository ```powershell -Get-GitHubViewTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Per Week +Get-GitHubViewTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub -Per Week ``` #### Get the number of clones for a repository ```powershell -Get-GitHubCloneTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Per Day +Get-GitHubCloneTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub -Per Day ``` ---------- @@ -407,22 +407,22 @@ Get-GitHubCloneTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub #### Get assignees ```powershell -Get-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub +Get-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub ``` #### Check assignee permission ```powershell -$HasPermission = Test-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee "LoginID123" +$HasPermission = Test-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee "LoginID123" ``` #### Add assignee to an issue ```powershell -New-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1 +New-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1 ``` #### Remove assignee from an issue ```powershell -Remove-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1 +Remove-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1 ``` ---------- @@ -431,32 +431,32 @@ Remove-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub - #### Get comments from an issue ```powershell -Get-GitHubIssueComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 1 +Get-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 ``` #### Get comments from a repository ```powershell -Get-GitHubRepositoryComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Sort Created -Direction Ascending -Since '2011-04-14T16:00:49Z' +Get-GitHubRepositoryComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Sort Created -Direction Ascending -Since '2011-04-14T16:00:49Z' ``` #### Get a single comment ```powershell -Get-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1 +Get-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -CommentID 1 ``` #### Adding a new comment to an issue ```powershell -New-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Body "Testing this API" +New-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Body "Testing this API" ``` #### Editing an existing comment ```powershell -Set-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1 -Body "Testing this API" +Set-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -CommentID 1 -Body "Testing this API" ``` #### Removing a comment ```powershell -Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1 +Remove-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -CommentID 1 ``` ---------- @@ -465,28 +465,28 @@ Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -C #### Get milestones from a repository ```powershell -Get-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Sort DueOn -Direction Ascending -DueOn '2011-04-14T16:00:49Z' +Get-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Sort DueOn -Direction Ascending -DueOn '2011-04-14T16:00:49Z' ``` #### Get a single milestone ```powershell -Get-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 +Get-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1 ``` #### Assign an existing issue to a new milestone ```powershell -New-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Title "Testing this API" -Update-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 2 -Milestone 1 +New-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Title "Testing this API" +Update-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 2 -Milestone 1 ``` #### Editing an existing milestone ```powershell -Set-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Title "Testing this API edited" +Set-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Title "Testing this API edited" ``` #### Removing a milestone ```powershell -Remove-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 +Remove-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1 ``` ---------- @@ -495,17 +495,17 @@ Remove-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub #### Get events from a repository ```powershell -Get-GitHubEvent -OwnerName Microsoft -RepositoryName PowerShellForGitHub +Get-GitHubEvent -OwnerName microsoft -RepositoryName PowerShellForGitHub ``` #### Get events from an issue ```powershell -Get-GitHubEvent -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 1 +Get-GitHubEvent -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 ``` #### Get a single event ```powershell -Get-GitHubEvent -OwnerName Microsoft -RepositoryName PowerShellForGitHub -EventID 1 +Get-GitHubEvent -OwnerName microsoft -RepositoryName PowerShellForGitHub -EventID 1 ``` ---------- @@ -514,7 +514,7 @@ Get-GitHubEvent -OwnerName Microsoft -RepositoryName PowerShellForGitHub -EventI #### Get projects for a repository ```powershell -Get-GitHubProject -OwnerName Microsoft -RepositoryName PowerShellForGitHub +Get-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub ``` #### Get projects for a user From 12a088cc184bd3cef4b512f82b216400cf14745f Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 13 Jun 2020 01:15:59 -0700 Subject: [PATCH 49/80] Breaking change: have to rename 'Name' to 'Label' for label function parameters due to pipeline confusion --- GitHubLabels.ps1 | 263 ++++++--- Tests/GitHubLabels.tests.ps1 | 1074 +++++++++++++++++++++++++++++----- 2 files changed, 1106 insertions(+), 231 deletions(-) diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 8f8f0538..c8189b8b 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -55,19 +55,19 @@ filter Get-GitHubLabel GitHub.Label .EXAMPLE - Get-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub + Get-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub Gets the information for every label from the Microsoft\PowerShellForGitHub project. .EXAMPLE - Get-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -LabelName TestLabel + Get-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -LabelName TestLabel Gets the information for the label named "TestLabel" from the Microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, - DefaultParameterSetName='Elements')] + DefaultParameterSetName='NameUri')] [OutputType({$script:GitHubLabelTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( @@ -90,19 +90,20 @@ filter Get-GitHubLabel [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName='NameUri')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='NameUri')] [Parameter(Mandatory, ParameterSetName='NameElements')] + [ValidateNotNullOrEmpty()] [Alias('LabelName')] - [string] $Name, + [string] $Label, [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueElements')] - [Alias('IssueId')] + [Parameter(Mandatory, ParameterSetName='IssueElements')] + [Alias('IssueNumber')] [int64] $Issue, [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='MilestoneUri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='MilestoneElements')] - [Alias('MilestoneId')] + [Parameter(Mandatory, ParameterSetName='MilestoneElements')] + [Alias('MilestoneNumber')] [int64] $Milestone, [string] $AccessToken, @@ -132,15 +133,15 @@ filter Get-GitHubLabel elseif ($PSBoundParameters.ContainsKey('Milestone')) { $uriFragment = "/repos/$OwnerName/$RepositoryName/milestones/$Milestone/labels" - $description = "Getting labels for Milestone $Milestone in $RepositoryName" + $description = "Getting labels for issues in Milestone $Milestone in $RepositoryName" } else { - $uriFragment = "repos/$OwnerName/$RepositoryName/labels/$Name" + $uriFragment = "repos/$OwnerName/$RepositoryName/labels/$Label" if ($PSBoundParameters.ContainsKey('Name')) { - $description = "Getting label $Name for $RepositoryName" + $description = "Getting label $Label for $RepositoryName" } else { @@ -151,18 +152,13 @@ filter Get-GitHubLabel $params = @{ 'UriFragment' = $uriFragment 'Description' = $description - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'AcceptHeader' = $scrit:symmetraAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - if (-not [String]::IsNullOrWhiteSpace($Name)) - { - $params["Description"] = "Getting label $Name for $RepositoryName" - } - return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } @@ -196,7 +192,7 @@ filter New-GitHubLabel Emoji and codes are supported. For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ .PARAMETER Color - Color (in HEX) for the new label, without the leading # sign. + Color (in HEX) for the new label. .PARAMETER Description A short description of the label. @@ -215,7 +211,7 @@ filter New-GitHubLabel GitHub.Label .EXAMPLE - New-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -Color BBBBBB + New-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -Color BBBBBB Creates a new, grey-colored label called "TestLabel" in the PowerShellForGitHub project. #> @@ -239,9 +235,11 @@ filter New-GitHubLabel [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline)] [Alias('LabelName')] - [string] $Name, + [string] $Label, [Parameter(Mandatory)] [ValidateScript({if ($_ -match '^#?[ABCDEF0-9]{6}$') { $true } else { throw "Color must be provided in hex." }})] @@ -274,7 +272,7 @@ filter New-GitHubLabel } $hashBody = @{ - 'name' = $Name + 'name' = $Label 'color' = $Color 'description' = $Description } @@ -283,8 +281,8 @@ filter New-GitHubLabel 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels" 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Post' - 'Description' = "Creating label $Name in $RepositoryName" - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'Description' = "Creating label $Label in $RepositoryName" + 'AcceptHeader' = $script:symmetraAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -337,17 +335,17 @@ filter Remove-GitHubLabel If not supplied here, the DefaultNoStatus configuration property value will be used. .EXAMPLE - Remove-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel + Remove-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel Removes the label called "TestLabel" from the PowerShellForGitHub project. .EXAMPLE - Remove-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -Confirm:$false + Remove-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -Confirm:$false Removes the label called "TestLabel" from the PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified. .EXAMPLE - Remove-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -Force + Remove-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -Force Removes the label called "TestLabel" from the PowerShellForGitHub project. Will not prompt for confirmation, as -Force was specified. #> @@ -371,10 +369,13 @@ filter Remove-GitHubLabel [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [Alias('LabelName')] - [string] $Name, + [string] $Label, [switch] $Force, @@ -399,13 +400,13 @@ filter Remove-GitHubLabel $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($Name, "Remove label")) + if ($PSCmdlet.ShouldProcess($Label, "Remove label")) { $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Name" + 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Label" 'Method' = 'Delete' - 'Description' = "Deleting label $Name from $RepositoryName" - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'Description' = "Deleting label $Label from $RepositoryName" + 'AcceptHeader' = $script:symmetraAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -449,7 +450,7 @@ filter Update-GitHubLabel Emoji and codes are supported. For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ .PARAMETER Color - Color (in HEX) for the new label, without the leading # sign. + Color (in HEX) for the new label. .PARAMETER Description A short description of the label. @@ -468,7 +469,7 @@ filter Update-GitHubLabel GitHub.Label .EXAMPLE - Update-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -NewName NewTestLabel -LabelColor BBBB00 + Update-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -NewName NewTestLabel -LabelColor BBBB00 Updates the existing label called TestLabel in the PowerShellForGitHub project to be called 'NewTestLabel' and be colored yellow. @@ -492,15 +493,15 @@ filter Update-GitHubLabel [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] [Alias('LabelName')] - [string] $Name, + [string] $Label, - [Parameter(Mandatory)] [Alias('NewLabelName')] [string] $NewName, - [Parameter(Mandatory)] [Alias('LabelColor')] [ValidateScript({if ($_ -match '^#?[ABCDEF0-9]{6}$') { $true } else { throw "Color must be provided in hex." }})] [string] $Color = "EEEEEE", @@ -523,17 +524,24 @@ filter Update-GitHubLabel 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } + # Be robust to users who choose to provide a color in hex by specifying the leading # sign + # (by just stripping it out). + if ($Color.StartsWith('#')) + { + $Color = $Color.Substring(1) + } + $hashBody = @{} if ($PSBoundParameters.ContainsKey('NewName')) { $hashBody['name'] = $NewName } - if ($PSBoundParameters.ContainsKey('Color')) { $hashBody['color'] = $Color } if ($PSBoundParameters.ContainsKey('Description')) { $hashBody['description'] = $Description } + if ($PSBoundParameters.ContainsKey('Color')) { $hashBody['color'] = $Color } $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Name" + 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Label" 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Patch' - 'Description' = "Updating label $Name" - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'Description' = "Updating label $Label" + 'AcceptHeader' = $script:symmetraAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -596,7 +604,7 @@ filter Set-GitHubLabel removed (and thus unassigned from existing Issues) and then the new one created. .EXAMPLE - Set-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Label @(@{'name' = 'TestLabel'; 'color' = 'EEEEEE'}, @{'name' = 'critical'; 'color' = 'FF000000'; 'description' = 'Needs immediate attention'}) + Set-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label @(@{'name' = 'TestLabel'; 'color' = 'EEEEEE'}, @{'name' = 'critical'; 'color' = 'FF000000'; 'description' = 'Needs immediate attention'}) Removes any labels not in this Label array, ensure the current assigned color and descriptions match what's in the array for the labels that do already exist, and then creates new labels @@ -655,12 +663,12 @@ filter Set-GitHubLabel if ($labelToConfigure.name -notin $existingLabelNames) { # Create label if it doesn't exist - $null = New-GitHubLabel -Name $labelToConfigure.name -Color $labelToConfigure.color @commonParams + $null = New-GitHubLabel -Label $labelToConfigure.name -Color $labelToConfigure.color @commonParams } else { # Update label's color if it already exists - $null = Update-GitHubLabel -Name $labelToConfigure.name -NewName $labelToConfigure.name -Color $labelToConfigure.color @commonParams + $null = Update-GitHubLabel -Label $labelToConfigure.name -NewName $labelToConfigure.name -Color $labelToConfigure.color @commonParams } } @@ -669,7 +677,7 @@ filter Set-GitHubLabel if ($labelName -notin $labelNames) { # Remove label if it exists but is not in desired label list - $null = Remove-GitHubLabel -Name $labelName @commonParams -Confirm:$false + $null = Remove-GitHubLabel -Label $labelName @commonParams -Confirm:$false } } } @@ -715,7 +723,7 @@ filter Add-GitHubIssueLabel GitHub.Label .EXAMPLE - Add-GitHubIssueLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Name $labels + Add-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Label $labels Adds labels to an issue in the PowerShellForGitHub project. #> @@ -739,12 +747,19 @@ filter Add-GitHubIssueLabel [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('IssueNumber')] [int64] $Issue, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName)] [Alias('LabelName')] - [string[]] $Name, + [ValidateNotNullOrEmpty()] + [string[]] $Label, [string] $AccessToken, @@ -760,11 +775,11 @@ filter Add-GitHubIssueLabel $telemetryProperties = @{ 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) - 'LabelCount' = $Name.Count + 'LabelCount' = $Label.Count } $hashBody = @{ - 'labels' = $Name + 'labels' = $Label } $params = @{ @@ -772,7 +787,7 @@ filter Add-GitHubIssueLabel 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Post' 'Description' = "Adding labels to issue $Issue in $RepositoryName" - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'AcceptHeader' = $script:symmetraAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -783,7 +798,7 @@ filter Add-GitHubIssueLabel Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) } -filter Set-GitHubIssueLabel +function Set-GitHubIssueLabel { <# .DESCRIPTION @@ -810,6 +825,9 @@ filter Set-GitHubIssueLabel .PARAMETER LabelName Array of label names that will be set on the issue. + .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. @@ -824,13 +842,38 @@ filter Set-GitHubIssueLabel GitHub.Label .EXAMPLE - Set-GitHubIssueLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 1 -LabelName $labels + Set-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -LabelName $labels Replaces labels on an issue in the PowerShellForGitHub project. + + .EXAMPLE + ('help wanted', 'good first issue') | Set-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 + + Replaces labels on an issue in the PowerShellForGitHub project with 'help wanted' and 'good first issue'. + + .EXAMPLE + Set-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Confirm:$false + + Removes all labels from issue 1 in the PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified. + This is the same result as having called Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Confirm:$false + + .EXAMPLE + Set-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Force + + Removes all labels from issue 1 in the PowerShellForGitHub project. Will not prompt for confirmation, as -Force was specified. + This is the same result as having called Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Force + + .NOTES + This is implemented as a function rather than a filter because the ValueFromPipeline + parameter (Name) is itself an array which we want to ensure is processed only a single time. + This API endpoint doesn't add labels to a repository, it replaces the existing labels with + the new set provided, so we need to make sure that we have all the requested labels available + to us at the time that the API endpoint is called. #> [CmdletBinding( SupportsShouldProcess, - DefaultParameterSetName='Elements')] + DefaultParameterSetName='Elements', + ConfirmImpact='High')] [OutputType({$script:GitHubLabelTypeName})] [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.")] @@ -848,48 +891,79 @@ filter Set-GitHubIssueLabel [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('IssueNumber')] [int64] $Issue, - [Parameter(Mandatory)] + [Parameter(ValueFromPipeline)] [Alias('LabelName')] - [string[]] $Name, + [string[]] $Label, + + [switch] $Force, [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) - 'LabelCount' = $Name.Count + begin + { + $labelNames = @() } - $hashBody = @{ - 'labels' = $Name + process + { + foreach ($name in $Label) + { + $labelNames += $name + } } - $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/labels" - 'Body' = (ConvertTo-Json -InputObject $hashBody) - 'Method' = 'Put' - 'Description' = "Replacing labels to issue $Issue in $RepositoryName" - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - } + end + { + Write-InvocationLog - return (Invoke-GHRestMethod @params | - Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) + $elements = Resolve-RepositoryElements + $OwnerName = $elements.ownerName + $RepositoryName = $elements.repositoryName + + $telemetryProperties = @{ + 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) + 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) + 'LabelCount' = $Name.Count + } + + $hashBody = @{ + 'labels' = $labelNames + } + + if ($Force -and (-not $Confirm)) + { + $ConfirmPreference = 'None' + } + + if (($null -eq $Name) -and (-not $PSCmdlet.ShouldProcess($Issue, "Remove all labels from issue"))) + { + return + } + + $params = @{ + 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/labels" + 'Body' = (ConvertTo-Json -InputObject $hashBody) + 'Method' = 'Put' + 'Description' = "Replacing labels to issue $Issue in $RepositoryName" + 'AcceptHeader' = $script:symmetraAcceptHeader + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + } + + return (Invoke-GHRestMethod @params | + Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) + } } filter Remove-GitHubIssueLabel @@ -934,17 +1008,17 @@ filter Remove-GitHubIssueLabel If not supplied here, the DefaultNoStatus configuration property value will be used. .EXAMPLE - Remove-GitHubIssueLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -Issue 1 + Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -Issue 1 Removes the label called "TestLabel" from issue 1 in the PowerShellForGitHub project. .EXAMPLE - Remove-GitHubIssueLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -Issue 1 -Confirm:$false + Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -Issue 1 -Confirm:$false Removes the label called "TestLabel" from issue 1 in the PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified. .EXAMPLE - Remove-GitHubIssueLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -Issue 1 -Force + Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -Issue 1 -Force Removes the label called "TestLabel" from issue 1 in the PowerShellForGitHub project. Will not prompt for confirmation, as -Force was specified. #> @@ -971,9 +1045,15 @@ filter Remove-GitHubIssueLabel [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [Alias('IssueNumber')] [int64] $Issue, + [Parameter( + ValueFromPipeline, + ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [Alias('LabelName')] [string] $Name, @@ -997,7 +1077,6 @@ filter Remove-GitHubIssueLabel } $description = [String]::Empty - if ($PSBoundParameters.ContainsKey('Name')) { $description = "Deleting label $Name from issue $Issue in $RepositoryName" @@ -1018,7 +1097,7 @@ filter Remove-GitHubIssueLabel 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/labels/$Name" 'Method' = 'Delete' 'Description' = $description - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'AcceptHeader' = $script:symmetraAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index 744f3455..7e91ed06 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -17,10 +17,7 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { - # All of these tests will fail without authentication. Let's just avoid the failures. - if (-not $accessTokenConfigured) { return } - - $defaultLabels = @( + $defaultLabels = @( @{ 'name' = 'pri:lowest' 'color' = '4285F4' @@ -79,253 +76,1052 @@ try } ) - Describe 'Getting labels from repository' { - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName - Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels + Describe 'Getting labels from a repository' { + BeforeAll { + $repositoryName = [Guid]::NewGuid().Guid + $repo = New-GitHubRepository -RepositoryName $script:repositoryName + + Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $defaultLabels + } + + AfterAll { + $repo | Remove-GitHubRepository -Force + } Context 'When querying for all labels' { $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should return expected number of labels' { - $labels.Count | Should -Be $:defaultLabels.Count + $labels.Count | Should -Be $defaultLabels.Count + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $labels) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + } + + Context 'When querying for all labels (via repo on pipeline)' { + $labels = @($repo | Get-GitHubLabel) + + It 'Should return expected number of labels' { + $labels.Count | Should -Be $defaultLabels.Count + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $labels) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + } + + Context 'When pipeline properties are disabled' { + BeforeAll { + Set-GitHubConfiguration -DisablePipelineSupport + $labels = @($repo | Get-GitHubLabel) + } + + AfterAll { + Set-GitHubConfiguration -DisablePipelineSupport:$false + } + + It 'Should return expected number of labels' { + $labels.Count | Should -Be $defaultLabels.Count + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $labels) + { + $label.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Label' + $label.RepositoryUrl | Should -BeNullOrEmpty + $label.LabelId | Should -BeNullOrEmpty + $label.LabelName | Should -BeNullOrEmpty + } } } - Context 'When querying for specific label' { - $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name bug + Context 'When querying for a specific label' { + $labelName = 'bug' + $label = Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $labelName It 'Should return expected label' { - $label.name | Should -Be "bug" + $label.name | Should -Be $labelName + } + + It 'Should have the expected type and additional properties' { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name } } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + Context 'When querying for a specific label (via repo on pipeline)' { + $labelName = 'bug' + $label = $repo | Get-GitHubLabel -Label $labelName + + It 'Should return expected label' { + $label.name | Should -Be $labelName + } + + It 'Should have the expected type and additional properties' { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + + Context 'When querying for a specific label (via name on pipeline)' { + $labelName = 'bug' + $label = $labelName | Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName + + It 'Should return expected label' { + $label.name | Should -Be $labelName + } + + It 'Should have the expected type and additional properties' { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } } - Describe 'Creating new label' { - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName + Describe 'Creating a new label' { + BeforeAll { + $repositoryName = [Guid]::NewGuid().Guid + $repo = New-GitHubRepository -RepositoryName $script:repositoryName + } + + AfterAll { + $repo | Remove-GitHubRepository -Force + } - $labelName = [Guid]::NewGuid().Guid - New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB - $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName + Context 'On a repo with parameters' { + $labelName = [Guid]::NewGuid().Guid + $color = 'AAAAAA' + $label = New-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $labelName -Color $color - It 'New label should be created' { - $label.name | Should -Be $labelName + It 'New label should be created' { + $label.name | Should -Be $labelName + $label.color | Should -Be $color + } + + It 'Should have the expected type and additional properties' { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } } - AfterEach { - Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Confirm:$false + Context 'On a repo with and color starts with a #' { + $labelName = [Guid]::NewGuid().Guid + $color = '#AAAAAA' + $label = New-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $labelName -Color $color + + It 'New label should be created' { + $label.name | Should -Be $labelName + $label.color | Should -Be $color.Substring(1) + $label.description | Should -BeNullOrEmpty + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.LabelId | Should -Be $result.id + $result.LabelName | Should -Be $result.name + } } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + Context 'On a repo with the repo on the pipeline' { + $labelName = [Guid]::NewGuid().Guid + $color = 'BBBBBB' + $description = 'test description' + $label = $repo | New-GitHubLabel -Label $labelName -Color $color -Description $description + + It 'New label should be created' { + $label.name | Should -Be $labelName + $label.color | Should -Be $color + $label.description | Should -Be $description + } + + It 'Should have the expected type and additional properties' { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + + Context 'On a repo with the name on the pipeline' { + $labelName = [Guid]::NewGuid().Guid + $color = 'CCCCCC' + $label = $labelName | New-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Color $color + + It 'New label should be created' { + $label.name | Should -Be $labelName + $label.color | Should -Be $color + } + + It 'Should have the expected type and additional properties' { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } } - Describe 'Removing label' { - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName - Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels + Describe 'Removing a label' { + BeforeAll { + $repositoryName = [Guid]::NewGuid().Guid + $repo = New-GitHubRepository -RepositoryName $script:repositoryName + } + + AfterAll { + $repo | Remove-GitHubRepository -Force + } + + BeforeEach { + $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' + } - $labelName = [Guid]::NewGuid().Guid - New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB - $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) + Context 'Removing a label with parameters' { + Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $label.name -Force - It 'Should return increased number of labels' { - $labels.Count | Should -Be ($defaultLabels.Count + 1) + It 'Should be gone after being removed by parameter' { + { $label | Get-GitHubLabel } | Should -Throw + } } - Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Confirm:$false - $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) + Context 'Removing a label with the repo on the pipeline' { + $repo | Remove-GitHubLabel -Label $label.name -Confirm:$false - It 'Should return expected number of labels' { - $labels.Count | Should -Be $defaultLabels.Count + It 'Should be gone after being removed by parameter' { + { $label | Get-GitHubLabel } | Should -Throw + } } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + Context 'Removing a label with the name on the pipeline' { + $label.name | Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Force + + It 'Should be gone after being removed by parameter' { + { $label | Get-GitHubLabel } | Should -Throw + } + } } - Describe 'Updating label' { - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName + Describe 'Updating a label' { + BeforeAll { + $repositoryName = [Guid]::NewGuid().Guid + $repo = New-GitHubRepository -RepositoryName $script:repositoryName + } - $labelName = [Guid]::NewGuid().Guid + AfterAll { + $repo | Remove-GitHubRepository -Force + } - Context 'Updating label color' { - New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB - Update-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -NewName $labelName -Color AAAAAA - $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName + Context 'Updating label color with parameters' { + $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' - AfterEach { - Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Confirm:$false + $newColor = 'AAAAAA' + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $label.name -Color $newColor + + It 'Label should have different color' { + $result.name | Should -Be $label.name + $result.color | Should -Be $newColor + $result.description | Should -Be $label.description } + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.LabelId | Should -Be $result.id + $result.LabelName | Should -Be $result.name + } + } + + Context 'Updating label color (with #) with parameters' { + $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' + + $newColor = '#AAAAAA' + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $label.name -Color $newColor + It 'Label should have different color' { - $label.color | Should -Be AAAAAA + $result.name | Should -Be $label.name + $result.color | Should -Be $newColor.Substring(1) + $result.description | Should -Be $label.description + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.LabelId | Should -Be $result.id + $result.LabelName | Should -Be $result.name + } + } + + Context 'Updating label name with parameters' { + $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' + + $newName = [Guid]::NewGuid().Guid + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $label.name -NewName $newName + + It 'Label should have different name' { + $result.name | Should -Be $newName + $result.color | Should -Be $label.color + $result.description | Should -Be $label.description + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.LabelId | Should -Be $result.id + $result.LabelName | Should -Be $result.name } } - Context 'Updating label name' { - $newLabelName = $labelName + "2" - New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB - Update-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -NewName $newLabelName -Color BBBBBB - $label = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $newLabelName + Context 'Updating label description with parameters' { + $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' -Description 'test description' + + $newDescription = [Guid]::NewGuid().Guid + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $label.name -Description $newDescription - AfterEach { - Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $newLabelName -Confirm:$false + It 'Label should have different name' { + $result.name | Should -Be $label.name + $result.color | Should -Be $label.color + $result.description | Should -Be $newDescription } + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.LabelId | Should -Be $result.id + $result.LabelName | Should -Be $result.name + } + } + + Context 'Updating label name, color and description with parameters' { + $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' -Description 'test description' + + $newName = [Guid]::NewGuid().Guid + $newColor = 'AAAAAA' + $newDescription = [Guid]::NewGuid().Guid + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $label.name -NewName $newName -Color $newColor -Description $newDescription + + It 'Label should have different everything' { + $result.name | Should -Be $newName + $result.color | Should -Be $newColor + $result.description | Should -Be $newDescription + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.LabelId | Should -Be $result.id + $result.LabelName | Should -Be $result.name + } + + + } + + Context 'Updating label color with repo on the pipeline' { + $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' + + $newColor = 'AAAAAA' + $result = $repo | Update-GitHubLabel -Label $label.name -Color $newColor + It 'Label should have different color' { - $label | Should -Not -Be $null - $label.color | Should -Be BBBBBB + $result.name | Should -Be $label.name + $result.color | Should -Be $newColor + $result.description | Should -Be $label.description + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.LabelId | Should -Be $result.id + $result.LabelName | Should -Be $result.name } } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + Context 'Updating label name with the label on the pipeline' { + $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' + + $newName = [Guid]::NewGuid().Guid + $result = $label | Update-GitHubLabel -NewName $newName + + It 'Label should have different name' { + $result.name | Should -Be $newName + $result.color | Should -Be $label.color + $result.description | Should -Be $label.description + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.LabelId | Should -Be $result.id + $result.LabelName | Should -Be $result.name + } + } + + Context 'Updating label name, color and description with the label on the pipeline' { + $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' -Description 'test description' + + $newName = [Guid]::NewGuid().Guid + $newColor = 'AAAAAA' + $newDescription = [Guid]::NewGuid().Guid + $result = $label | Update-GitHubLabel -NewName $newName -Color $newColor -Description $newDescription + + It 'Label should have different everything' { + $result.name | Should -Be $newName + $result.color | Should -Be $newColor + $result.description | Should -Be $newDescription + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.LabelId | Should -Be $result.id + $result.LabelName | Should -Be $result.name + } + } } - Describe 'Applying set of labels on repository' { - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName + Describe 'Initializing the labels on a repository' { + BeforeAll { + $repositoryName = [Guid]::NewGuid().Guid + $repo = New-GitHubRepository -RepositoryName $script:repositoryName + } - $labelName = [Guid]::NewGuid().Guid - Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels + AfterAll { + $repo | Remove-GitHubRepository -Force + } - # Add new label - New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB - $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) + Context 'Applying a default set of labels' { + Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $defaultLabels - # Change color of existing label - Update-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "bug" -NewName "bug" -Color BBBBBB + $labels = @($repo | Get-GitHubLabel) - # Remove one of approved labels" - Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "discussion" -Confirm:$false + It 'Should return the expected number of labels' { + $labels.Count | Should -Be $defaultLabels.Count + } - It 'Should return increased number of labels' { - $($labels).Count | Should -Be ($defaultLabels.Count + 1) + It 'Should have the right set of labels' { + foreach ($item in $defaultLabels) + { + $label = $labels | Where-Object { $_.name -eq $item.name } + $item.name | Should -Be $label.name + $item.color | Should -Be $label.color + } + } } - Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels - $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) + Context 'Applying an overlapping set of labels' { + $newLabels = @( + @{ 'name' = $defaultLabels[0].name; 'color' = 'aaaaaa' }, + @{ 'name' = $defaultLabels[1].name; 'color' = 'bbbbbb' } + @{ 'name' = $defaultLabels[2].name; 'color' = $defaultLabels[2].color } + @{ 'name' = ([Guid]::NewGuid().Guid); 'color' = 'cccccc' } + @{ 'name' = ([Guid]::NewGuid().Guid); 'color' = 'dddddd' } + ) + + $originalLabels = @($repo | Get-GitHubLabel) + $null = $repo | Set-GitHubLabel -Label $newLabels + $labels = @($repo | Get-GitHubLabel) + + It 'Should return the expected number of labels' { + $labels.Count | Should -Be $newLabels.Count + } + + It 'Should have the right set of labels' { + foreach ($item in $newLabels) + { + $label = $labels | Where-Object { $_.name -eq $item.name } + $item.name | Should -Be $label.name + $item.color | Should -Be $label.color + } + } + + It 'Should have retained the ID''s of the pre-existing labels' { + $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[0].name } + $label = $labels | Where-Object { $_.name -eq $newLabels[0].name } + $label.id | Should -Be $originalLabel.id - It 'Should return expected number of labels' { - $labels.Count | Should -Be $defaultLabels.Count - $bugLabel = $labels | Where-Object {$_.name -eq "bug"} - $bugLabel.color | Should -Be "fc2929" + $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[1] } + $label = $labels | Where-Object { $_.name -eq $newLabels[1].name } + $label.id | Should -Be $originalLabel.id + + $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[2] } + $label = $labels | Where-Object { $_.name -eq $newLabels[2].name } + $label.id | Should -Be $originalLabel.id + + $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[3] } + $label = $labels | Where-Object { $_.name -eq $newLabels[3].name } + $originalLabel | Should -BeNullOrEmpty + $label | Should -Not -BeNullOrEmpty + + $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[4] } + $label = $labels | Where-Object { $_.name -eq $newLabels[4].name } + $originalLabel | Should -BeNullOrEmpty + $label | Should -Not -BeNullOrEmpty + } } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false } Describe 'Adding labels to an issue'{ - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName - Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels + BeforeAll { + $repositoryName = [Guid]::NewGuid().Guid + $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo | Set-GitHubLabel -Label $defaultLabels + } - $issueName = [Guid]::NewGuid().Guid - $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName + AfterAll { + $repo | Remove-GitHubRepository -Force + } Context 'Adding labels to an issue' { - $labelsToAdd = @('pri:lowest', 'pri:low', 'pri:medium', 'pri:high', 'pri:highest', 'bug', 'duplicate', - 'enhancement', 'up for grabs', 'question', 'discussion', 'wontfix', 'in progress', 'ready') - $addedLabels = @(Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd) + $expectedLabels = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[3].name) + $issue = $repo | New-GitHubIssue -Title 'test issue' + $result = @(Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number -LabelName $expectedLabels) + + It 'Should return the number of labels that were just added' { + $result.Count | Should -Be $expectedLabels.Count + } + + It 'Should be the right set of labels' { + foreach ($label in $expectedLabels) + { + $result | Should -Contant $label + } + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $result) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + + $issueLabels = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number + + It 'Should return the number of labels that were just added from querying the issue again' { + $issueLabels.Count | Should -Be $defaultLabels.Count + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $issueLabels) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + } + + Context 'Adding labels to an issue with the repo on the pipeline' { + $expectedLabels = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[3].name) + $issue = $repo | New-GitHubIssue -Title 'test issue' + $result = @($repo | Add-GitHubIssueLabel -Issue $issue.number -LabelName $expectedLabels) + + It 'Should return the number of labels that were just added' { + $result.Count | Should -Be $expectedLabels.Count + } + + It 'Should be the right set of labels' { + foreach ($label in $expectedLabels) + { + $result | Should -Contant $label + } + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $result) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + + $issueLabels = $repo | Get-GitHubLabel -Issue $issue.number + + It 'Should return the number of labels that were just added from querying the issue again' { + $issueLabels.Count | Should -Be $defaultLabels.Count + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $issueLabels) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + } + + Context 'Adding labels to an issue with the issue on the pipeline' { + $expectedLabels = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[3].name) + $issue = $repo | New-GitHubIssue -Title 'test issue' + $result = @($issue | Add-GitHubIssueLabel -LabelName $expectedLabels) It 'Should return the number of labels that were just added' { - $addedLabels.Count | Should -Be $defaultLabels.Count + $result.Count | Should -Be $expectedLabels.Count + } + + It 'Should be the right set of labels' { + foreach ($label in $expectedLabels) + { + $result | Should -Contant $label + } } - $labelIssues = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number + It 'Should have the expected type and additional properties' { + foreach ($label in $result) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + + $issueLabels = $issue | Get-GitHubLabel It 'Should return the number of labels that were just added from querying the issue again' { - $labelIssues.Count | Should -Be $defaultLabels.Count + $issueLabels.Count | Should -Be $defaultLabels.Count + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $issueLabels) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } } } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + Context 'Adding labels to an issue with the labels on the pipeline' { + $expectedLabels = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[3].name) + $issue = $repo | New-GitHubIssue -Title 'test issue' + $result = @($expectedLabels | Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number) + + It 'Should return the number of labels that were just added' { + $result.Count | Should -Be $expectedLabels.Count + } + + It 'Should be the right set of labels' { + foreach ($label in $expectedLabels) + { + $result | Should -Contant $label + } + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $result) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + + $issueLabels = $issue | Get-GitHubLabel + + It 'Should return the number of labels that were just added from querying the issue again' { + $issueLabels.Count | Should -Be $defaultLabels.Count + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $issueLabels) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + } } Describe 'Creating a new Issue with labels' { - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName - Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels + BeforeAll { + $repositoryName = [Guid]::NewGuid().Guid + $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo | Set-GitHubLabel -Label $defaultLabels + } + + AfterAll { + $repo | Remove-GitHubRepository -Force + } - $issueName = [Guid]::NewGuid().Guid - $issueLabels = @($defaultLabels[0].name, $defaultLabels[1].name) - $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName -Label $issueLabels + Context 'When creating a new issue using parameters' { + $issueName = [Guid]::NewGuid().Guid + $issueLabels = @($defaultLabels[0].name, $defaultLabels[1].name) + $issue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Title $issueName -Label $issueLabels - It 'Should return the number of labels that were just added' { - $issue.labels.Count | Should -Be $issueLabels.Count + It 'Should return the number of labels that were just added' { + $issue.labels.Count | Should -Be $issueLabels.Count + } + + It 'Should be the right set of labels' { + foreach ($label in $issueLabels) + { + $issue.labels.name | Should -Contain $issueLabel + } + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $issue.labels) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + Context 'When creating a new issue using the repo on the pipeline' { + $issueName = [Guid]::NewGuid().Guid + $issueLabels = @($defaultLabels[0].name, $defaultLabels[1].name) + $issue = $repo | New-GitHubIssue -Title $issueName -Label $issueLabels + + It 'Should return the number of labels that were just added' { + $issue.labels.Count | Should -Be $issueLabels.Count + } + + It 'Should be the right set of labels' { + foreach ($label in $issueLabels) + { + $issue.labels.name | Should -Contain $issueLabel + } + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $issue.labels) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + } } Describe 'Removing labels on an issue' { - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName + BeforeAll { + $repositoryName = [Guid]::NewGuid().Guid + $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo | Set-GitHubLabel -Label $defaultLabels + } + + AfterAll { + $repo | Remove-GitHubRepository -Force + } + + Context 'For removing an individual issue with parameters' { + $issueName = [Guid]::NewGuid().Guid + $issue = $repo | New-GitHubIssue -Title $issueName - $issueName = [Guid]::NewGuid().Guid - $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName + $labelsToAdd = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[2].name) + $issue | Add-GitHubIssueLabel -LabelName $labelsToAdd - $labelsToAdd = @('pri:lowest', 'pri:low', 'pri:medium', 'pri:high', 'pri:highest', 'bug', 'duplicate', - 'enhancement', 'up for grabs', 'question', 'discussion', 'wontfix', 'in progress', 'ready') - Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd + $issueLabels = @($issue | Get-GitHubLabel) + It 'Should have the expected number of labels' { + $issueLabels.Count | Should -Be $labelsToAdd.Count + } - Context 'For removing individual issues'{ - Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "discussion" -Issue $issue.number -Confirm:$false - Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "question" -Issue $issue.number -Force - Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "bug" -Issue $issue.number -Confirm:$false -Force - $labelIssues = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) + # Doing this manually instead of in a loop to try out different combinations of -Confirm:$false and -Force + Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $labelsToAdd[0] -Issue $issue.number -Confirm:$false + Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $labelsToAdd[1] -Issue $issue.number -Force + Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $labelsToAdd[2] -Issue $issue.number -Confirm:$false -Force - It 'Should have removed three labels from the issue' { - $labelIssues.Count | Should -Be ($defaultLabels.Count - 3) + $issueLabels = @($issue | Get-GitHubLabel) + It 'Should have removed all labels from the issue' { + $issueLabels.Count | Should -Be 0 } } - Context 'For removing all issues'{ - Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -Confirm:$false - $labelIssues = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) + Context 'For removing an individual issue using the repo on the pipeline' { + $issueName = [Guid]::NewGuid().Guid + $issue = $repo | New-GitHubIssue -Title $issueName - It 'Should have removed all labels from the issue' { - $labelIssues.Count | Should -Be 0 + $labelsToAdd = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[2].name, $defaultLabels[3].name) + $issue | Add-GitHubIssueLabel -LabelName $labelsToAdd + + $issueLabels = @($issue | Get-GitHubLabel) + It 'Should have the expected number of labels' { + $issueLabels.Count | Should -Be $labelsToAdd.Count + } + + $labelToRemove = $labelsToAdd[0] + $repo | Remove-GitHubIssueLabel -Label $labelToRemove -Issue $issue.number -Confirm:$false + + $issueLabels = @($issue | Get-GitHubLabel) + It 'Should have removed the expected label from the issue' { + $issueLabels.Count | Should -Be ($issueLables - 1) + $issueLabels.name | Should -Not -Contain $labelToRemove + } + } + + Context 'For removing an individual issue using the issue on the pipeline' { + $issueName = [Guid]::NewGuid().Guid + $issue = $repo | New-GitHubIssue -Title $issueName + + $labelsToAdd = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[2].name, $defaultLabels[3].name) + $issue | Add-GitHubIssueLabel -LabelName $labelsToAdd + + $issueLabels = @($issue | Get-GitHubLabel) + It 'Should have the expected number of labels' { + $issueLabels.Count | Should -Be $labelsToAdd.Count + } + + $labelToRemove = $labelsToAdd[1] + $issue | Remove-GitHubIssueLabel -Label $labelToRemove -Confirm:$false + + $issueLabels = @($issue | Get-GitHubLabel) + It 'Should have removed the expected label from the issue' { + $issueLabels.Count | Should -Be ($issueLables - 1) + $issueLabels.name | Should -Not -Contain $labelToRemove } } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + Context 'For removing an individual issue using the label name on the pipeline' { + $issueName = [Guid]::NewGuid().Guid + $issue = $repo | New-GitHubIssue -Title $issueName + + $labelsToAdd = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[2].name, $defaultLabels[3].name) + $issue | Add-GitHubIssueLabel -LabelName $labelsToAdd + + $issueLabels = @($issue | Get-GitHubLabel) + It 'Should have the expected number of labels' { + $issueLabels.Count | Should -Be $labelsToAdd.Count + } + + $labelToRemove = $labelsToAdd[2] + $labelToRemove | Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number -Confirm:$false + + $issueLabels = @($issue | Get-GitHubLabel) + It 'Should have removed the expected label from the issue' { + $issueLabels.Count | Should -Be ($issueLables - 1) + $issueLabels.name | Should -Not -Contain $labelToRemove + } + } + + Context 'For removing an individual issue using the label object on the pipeline' { + $issueName = [Guid]::NewGuid().Guid + $issue = $repo | New-GitHubIssue -Title $issueName + + $labelsToAdd = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[2].name, $defaultLabels[3].name) + $issue | Add-GitHubIssueLabel -LabelName $labelsToAdd + + $issueLabels = @($issue | Get-GitHubLabel) + It 'Should have the expected number of labels' { + $issueLabels.Count | Should -Be $labelsToAdd.Count + } + + $labelToRemove = $labelsToAdd[0] + $label = $repo | Get-GitHubLabel -Label $labelToRemove + $label | Remove-GitHubIssueLabel -Issue $issue.number -Confirm:$false + + $issueLabels = @($issue | Get-GitHubLabel) + It 'Should have removed the expected label from the issue' { + $issueLabels.Count | Should -Be ($issueLables - 1) + $issueLabels.name | Should -Not -Contain $labelToRemove + } + } + + Context 'For removing all issues' { + $issueName = [Guid]::NewGuid().Guid + $issue = $repo | New-GitHubIssue -Title $issueName + + $labelsToAdd = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[2].name, $defaultLabels[3].name) + $issue | Add-GitHubIssueLabel -LabelName $labelsToAdd + + $issueLabels = @($issue | Get-GitHubLabel) + It 'Should have the expected number of labels' { + $issueLabels.Count | Should -Be $labelsToAdd.Count + } + + $issue | Remove-GitHubIssueLabel -Confirm:$false + + $issueLabels = @($issue | Get-GitHubLabel) + It 'Should have removed all labels from the issue' { + $issueLabels.Count | Should -Be 0 + } + } } Describe 'Replacing labels on an issue'{ - $repositoryName = [Guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName + BeforeAll { + $repositoryName = [Guid]::NewGuid().Guid + $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo | Set-GitHubLabel -Label $defaultLabels + } - $issueName = [Guid]::NewGuid().Guid - $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName + AfterAll { + $repo | Remove-GitHubRepository -Force + } - $labelsToAdd = @('pri:lowest', 'pri:low', 'pri:medium', 'pri:high', 'pri:highest', 'bug', 'duplicate', - 'enhancement', 'up for grabs', 'question', 'discussion', 'wontfix', 'in progress', 'ready') + Context 'Change the set of labels with parameters' { + $labelsToAdd = @($defaultLabels[0].name, $defaultLabels[1].name) + $issue = $repo | New-GitHubIssue -Title ([Guid]::NewGuid().Guid) -Label $labelsToAdd - Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName 'pri:medium' + It 'Should have assigned the expected labels' { + $issue.labels.Count | Should -Be $labelsToAdd.Count + foreach ($label in $labelsToAdd) + { + $issue.labels | Should -Contain $label + } + } + + $newIssueLabels = @($defaultLabels[0].name, $defaultLabels[5].name) + $result = @(Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number -Label $newIssueLabels) - $addedLabels = @(Set-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd) + It 'Should have the expected labels' { + $result.labels.Count | Should -Be $newIssueLabels.Count + foreach ($label in $newIssueLabels) + { + $result.labels | Should -Contain $label + } + } - It 'Should return the issue with 14 labels' { - $addedLabels.Count | Should -Be $labelsToAdd.Count + It 'Should have the expected type and additional properties' { + foreach ($label in $result) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } } - $labelIssues = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number + Context 'Change the set of labels with the repo on the pipeline' { + $labelsToAdd = @($defaultLabels[0].name, $defaultLabels[1].name) + $issue = $repo | New-GitHubIssue -Title ([Guid]::NewGuid().Guid) -Label $labelsToAdd - It 'Should have 14 labels after querying the issue' { - $labelIssues.Count | Should -Be $defaultLabels.Count + It 'Should have assigned the expected labels' { + $issue.labels.Count | Should -Be $labelsToAdd.Count + foreach ($label in $labelsToAdd) + { + $issue.labels | Should -Contain $label + } + } + + $newIssueLabels = @($defaultLabels[0].name, $defaultLabels[5].name) + $result = @($repo | Set-GitHubIssueLabel -Issue $issue.number -Label $newIssueLabels) + + It 'Should have the expected labels' { + $result.labels.Count | Should -Be $newIssueLabels.Count + foreach ($label in $newIssueLabels) + { + $result.labels | Should -Contain $label + } + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $result) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } } - $updatedIssueLabels = $labelsToAdd[0] - $updatedIssue = Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -Label $updatedIssueLabels + Context 'Change the set of labels with the issue on the pipeline' { + $labelsToAdd = @($defaultLabels[0].name, $defaultLabels[1].name) + $issue = $repo | New-GitHubIssue -Title ([Guid]::NewGuid().Guid) -Label $labelsToAdd + + It 'Should have assigned the expected labels' { + $issue.labels.Count | Should -Be $labelsToAdd.Count + foreach ($label in $labelsToAdd) + { + $issue.labels | Should -Contain $label + } + } + + $newIssueLabels = @($defaultLabels[0].name, $defaultLabels[5].name) + $result = @($issue | Set-GitHubIssueLabel -Label $newIssueLabels) + + It 'Should have the expected labels' { + $result.labels.Count | Should -Be $newIssueLabels.Count + foreach ($label in $newIssueLabels) + { + $result.labels | Should -Contain $label + } + } - It 'Should have 1 label after updating the issue' { - $updatedIssue.labels.Count | Should -Be $updatedIssueLabels.Count + It 'Should have the expected type and additional properties' { + foreach ($label in $result) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } } - $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName -Confirm:$false + Context 'Change the set of labels with parameters with the labels on the pipeline' { + $labelsToAdd = @($defaultLabels[0].name, $defaultLabels[1].name) + $issue = $repo | New-GitHubIssue -Title ([Guid]::NewGuid().Guid) -Label $labelsToAdd + + It 'Should have assigned the expected labels' { + $issue.labels.Count | Should -Be $labelsToAdd.Count + foreach ($label in $labelsToAdd) + { + $issue.labels | Should -Contain $label + } + } + + $newIssueLabels = @($defaultLabels[0].name, $defaultLabels[5].name) + $result = @($newIssueLabels | Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number) + + It 'Should have the expected labels' { + $result.labels.Count | Should -Be $newIssueLabels.Count + foreach ($label in $newIssueLabels) + { + $result.labels | Should -Contain $label + } + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $result) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + } } } finally From 492e3967d5d3c31bf765766bf2ebdff5e0ef4dec Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 13 Jun 2020 12:46:43 -0700 Subject: [PATCH 50/80] Finishing migration of Name->Label --- GitHubLabels.ps1 | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index c8189b8b..f70c0040 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -31,7 +31,7 @@ filter Get-GitHubLabel The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER Name + .PARAMETER Label Name of the specific label to be retrieved. If not supplied, all labels will be retrieved. Emoji and codes are supported. For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ @@ -187,7 +187,7 @@ filter New-GitHubLabel The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER Name + .PARAMETER Label Name of the label to be created. Emoji and codes are supported. For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ @@ -317,7 +317,7 @@ filter Remove-GitHubLabel The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER Name + .PARAMETER Label Name of the label to be deleted. Emoji and codes are supported. For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ @@ -441,7 +441,7 @@ filter Update-GitHubLabel The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER Name + .PARAMETER Label Current name of the label to be updated. Emoji and codes are supported. For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ @@ -706,7 +706,7 @@ filter Add-GitHubIssueLabel .PARAMETER Issue Issue number to add the label to. - .PARAMETER Name + .PARAMETER Label Array of label names to add to the issue .PARAMETER AccessToken @@ -932,7 +932,7 @@ function Set-GitHubIssueLabel $telemetryProperties = @{ 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) - 'LabelCount' = $Name.Count + 'LabelCount' = $Label.Count } $hashBody = @{ @@ -944,7 +944,7 @@ function Set-GitHubIssueLabel $ConfirmPreference = 'None' } - if (($null -eq $Name) -and (-not $PSCmdlet.ShouldProcess($Issue, "Remove all labels from issue"))) + if (($null -eq $Label) -and (-not $PSCmdlet.ShouldProcess($Issue, "Remove all labels from issue"))) { return } @@ -990,7 +990,7 @@ filter Remove-GitHubIssueLabel .PARAMETER Issue Issue number to remove the label from. - .PARAMETER Name + .PARAMETER Label Name of the label to be deleted. If not provided, will delete all labels on the issue. Emoji and codes are supported. For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ @@ -1056,7 +1056,7 @@ filter Remove-GitHubIssueLabel ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [Alias('LabelName')] - [string] $Name, + [string] $Label, [switch] $Force, @@ -1077,9 +1077,9 @@ filter Remove-GitHubIssueLabel } $description = [String]::Empty - if ($PSBoundParameters.ContainsKey('Name')) + if ($PSBoundParameters.ContainsKey('Label')) { - $description = "Deleting label $Name from issue $Issue in $RepositoryName" + $description = "Deleting label $Label from issue $Issue in $RepositoryName" } else { @@ -1091,10 +1091,10 @@ filter Remove-GitHubIssueLabel $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($Name, "Remove label")) + if ($PSCmdlet.ShouldProcess($Label, "Remove label")) { $params = @{ - 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/labels/$Name" + 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/labels/$Label" 'Method' = 'Delete' 'Description' = $description 'AcceptHeader' = $script:symmetraAcceptHeader From d2474d0d6d8e566d071f7cfb9e614d9d3208b09c Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 13 Jun 2020 13:09:52 -0700 Subject: [PATCH 51/80] Fixing CBH --- GitHubLabels.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index f70c0040..179e3817 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -60,7 +60,7 @@ filter Get-GitHubLabel Gets the information for every label from the Microsoft\PowerShellForGitHub project. .EXAMPLE - Get-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -LabelName TestLabel + Get-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel Gets the information for the label named "TestLabel" from the Microsoft\PowerShellForGitHub project. @@ -469,7 +469,7 @@ filter Update-GitHubLabel GitHub.Label .EXAMPLE - Update-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -NewName NewTestLabel -LabelColor BBBB00 + Update-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -NewName NewTestLabel -Color BBBB00 Updates the existing label called TestLabel in the PowerShellForGitHub project to be called 'NewTestLabel' and be colored yellow. @@ -842,7 +842,7 @@ function Set-GitHubIssueLabel GitHub.Label .EXAMPLE - Set-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -LabelName $labels + Set-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Label $labels Replaces labels on an issue in the PowerShellForGitHub project. From da4e010dd7102cb68d623b05c6227af646ef3675 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 13 Jun 2020 14:52:09 -0700 Subject: [PATCH 52/80] Simplifying parameter sets in Get-GitHubLabel to get it working with the pipeline --- GitHubLabels.ps1 | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 179e3817..d06ddef4 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -38,8 +38,8 @@ filter Get-GitHubLabel .PARAMETER Issue If provided, will return all of the labels for this particular issue. - .PARAMETER Milestone - If provided, will return all of the labels for this particular milestone. + .PARAMETER MilestoneNumber + If provided, will return all of the labels assigned to issues for this particular milestone. .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the @@ -72,39 +72,26 @@ filter Get-GitHubLabel [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')] - [Parameter(Mandatory, ParameterSetName='NameElements')] - [Parameter(Mandatory, ParameterSetName='IssueElements')] - [Parameter(Mandatory, ParameterSetName='MilestoneElements')] [string] $OwnerName, [Parameter(Mandatory, ParameterSetName='Elements')] - [Parameter(Mandatory, ParameterSetName='NameElements')] - [Parameter(Mandatory, ParameterSetName='IssueElements')] - [Parameter(Mandatory, ParameterSetName='MilestoneElements')] [string] $RepositoryName, [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='Uri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='NameUri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='MilestoneUri')] [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='NameUri')] - [Parameter(Mandatory, ParameterSetName='NameElements')] + [Parameter(ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [Alias('LabelName')] [string] $Label, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] - [Parameter(Mandatory, ParameterSetName='IssueElements')] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('IssueNumber')] [int64] $Issue, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='MilestoneUri')] - [Parameter(Mandatory, ParameterSetName='MilestoneElements')] - [Alias('MilestoneNumber')] - [int64] $Milestone, + [Parameter(ValueFromPipelineByPropertyName)] + [int64] $MilestoneNumber, [string] $AccessToken, @@ -122,6 +109,23 @@ filter Get-GitHubLabel 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } + # There were a lot of complications trying to get pipelining working right when using all of + # the necessary ParameterSets, so we'll do internal parameter validation instead until someone + # can figure out the right way to do the parameter sets here _with_ pipeline support. + if ($PSBoundParameters.ContainsKey('Label') -or + $PSBoundParameters.ContainsKey('Issue') -or + $PSBoundParameters.ContainsKey('MilestoneNumber')) + { + if (-not ($PSBoundParameters.ContainsKey('Label') -xor + $PSBoundParameters.ContainsKey('Issue') -xor + $PSBoundParameters.ContainsKey('MilestoneNumber'))) + { + $message = 'Label, Issue and Milestone are mutually exclusive. Only one can be specified in a single command.' + Write-Log -Message $message -Level Error + throw $message + } + } + $uriFragment = [String]::Empty $description = [String]::Empty @@ -130,10 +134,10 @@ filter Get-GitHubLabel $uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$Issue/labels" $description = "Getting labels for Issue $Issue in $RepositoryName" } - elseif ($PSBoundParameters.ContainsKey('Milestone')) + elseif ($PSBoundParameters.ContainsKey('MilestoneNumber')) { - $uriFragment = "/repos/$OwnerName/$RepositoryName/milestones/$Milestone/labels" - $description = "Getting labels for issues in Milestone $Milestone in $RepositoryName" + $uriFragment = "/repos/$OwnerName/$RepositoryName/milestones/$MilestoneNumber/labels" + $description = "Getting labels for issues in Milestone $MilestoneNumber in $RepositoryName" } else { From d1d47d18124371ef1edaabd7fb38c4f01ee3094d Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 13 Jun 2020 16:33:58 -0700 Subject: [PATCH 53/80] Some fixes for the label UT's. still have some failures to investigate. --- Tests/GitHubLabels.tests.ps1 | 102 ++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index 7e91ed06..e116cd12 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -141,7 +141,7 @@ try It 'Should have the expected type and additional properties' { foreach ($label in $labels) { - $label.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Label' + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' $label.RepositoryUrl | Should -BeNullOrEmpty $label.LabelId | Should -BeNullOrEmpty $label.LabelName | Should -BeNullOrEmpty @@ -181,21 +181,23 @@ try } } - Context 'When querying for a specific label (via name on pipeline)' { - $labelName = 'bug' - $label = $labelName | Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName - - It 'Should return expected label' { - $label.name | Should -Be $labelName - } - - It 'Should have the expected type and additional properties' { - $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' - $label.RepositoryUrl | Should -Be $repo.RepositoryUrl - $label.LabelId | Should -Be $label.id - $label.LabelName | Should -Be $label.name - } - } + # This test has been disabled until we can figure out how to fix the parameter sets for + # Get-GitHubLabel pipelining to still support Label this way. + # Context 'When querying for a specific label (via Label on pipeline)' { + # $labelName = 'bug' + # $label = $labelName | Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName + + # It 'Should return expected label' { + # $label.name | Should -Be $labelName + # } + + # It 'Should have the expected type and additional properties' { + # $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + # $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + # $label.LabelId | Should -Be $label.id + # $label.LabelName | Should -Be $label.name + # } + # } } Describe 'Creating a new label' { @@ -238,10 +240,10 @@ try } It 'Should have the expected type and additional properties' { - $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' - $result.RepositoryUrl | Should -Be $repo.RepositoryUrl - $result.LabelId | Should -Be $result.id - $result.LabelName | Should -Be $result.name + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name } } @@ -294,11 +296,8 @@ try $repo | Remove-GitHubRepository -Force } - BeforeEach { - $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' - } - Context 'Removing a label with parameters' { + $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $label.name -Force It 'Should be gone after being removed by parameter' { @@ -307,6 +306,7 @@ try } Context 'Removing a label with the repo on the pipeline' { + $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' $repo | Remove-GitHubLabel -Label $label.name -Confirm:$false It 'Should be gone after being removed by parameter' { @@ -315,6 +315,7 @@ try } Context 'Removing a label with the name on the pipeline' { + $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' $label.name | Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Force It 'Should be gone after being removed by parameter' { @@ -560,20 +561,20 @@ try $label = $labels | Where-Object { $_.name -eq $newLabels[0].name } $label.id | Should -Be $originalLabel.id - $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[1] } + $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[1].name } $label = $labels | Where-Object { $_.name -eq $newLabels[1].name } $label.id | Should -Be $originalLabel.id - $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[2] } + $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[2].name } $label = $labels | Where-Object { $_.name -eq $newLabels[2].name } $label.id | Should -Be $originalLabel.id - $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[3] } + $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[3].name } $label = $labels | Where-Object { $_.name -eq $newLabels[3].name } $originalLabel | Should -BeNullOrEmpty $label | Should -Not -BeNullOrEmpty - $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[4] } + $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[4].name } $label = $labels | Where-Object { $_.name -eq $newLabels[4].name } $originalLabel | Should -BeNullOrEmpty $label | Should -Not -BeNullOrEmpty @@ -605,7 +606,7 @@ try It 'Should be the right set of labels' { foreach ($label in $expectedLabels) { - $result | Should -Contant $label + $result.name | Should -Contain $label } } @@ -622,7 +623,7 @@ try $issueLabels = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number It 'Should return the number of labels that were just added from querying the issue again' { - $issueLabels.Count | Should -Be $defaultLabels.Count + $issueLabels.Count | Should -Be $expectedLabels.Count } It 'Should have the expected type and additional properties' { @@ -648,7 +649,7 @@ try It 'Should be the right set of labels' { foreach ($label in $expectedLabels) { - $result | Should -Contant $label + $result.name | Should -Contain $label } } @@ -665,7 +666,7 @@ try $issueLabels = $repo | Get-GitHubLabel -Issue $issue.number It 'Should return the number of labels that were just added from querying the issue again' { - $issueLabels.Count | Should -Be $defaultLabels.Count + $issueLabels.Count | Should -Be $expectedLabels.Count } It 'Should have the expected type and additional properties' { @@ -691,7 +692,7 @@ try It 'Should be the right set of labels' { foreach ($label in $expectedLabels) { - $result | Should -Contant $label + $result.name | Should -Contain $label } } @@ -708,7 +709,7 @@ try $issueLabels = $issue | Get-GitHubLabel It 'Should return the number of labels that were just added from querying the issue again' { - $issueLabels.Count | Should -Be $defaultLabels.Count + $issueLabels.Count | Should -Be $expectedLabels.Count } It 'Should have the expected type and additional properties' { @@ -734,7 +735,7 @@ try It 'Should be the right set of labels' { foreach ($label in $expectedLabels) { - $result | Should -Contant $label + $result.name | Should -Contain $label } } @@ -751,7 +752,7 @@ try $issueLabels = $issue | Get-GitHubLabel It 'Should return the number of labels that were just added from querying the issue again' { - $issueLabels.Count | Should -Be $defaultLabels.Count + $issueLabels.Count | Should -Be $expectedLabels.Count } It 'Should have the expected type and additional properties' { @@ -789,7 +790,7 @@ try It 'Should be the right set of labels' { foreach ($label in $issueLabels) { - $issue.labels.name | Should -Contain $issueLabel + $issue.labels.name | Should -Contain $label } } @@ -816,7 +817,7 @@ try It 'Should be the right set of labels' { foreach ($label in $issueLabels) { - $issue.labels.name | Should -Contain $issueLabel + $issue.labels.name | Should -Contain $label } } @@ -883,7 +884,7 @@ try $issueLabels = @($issue | Get-GitHubLabel) It 'Should have removed the expected label from the issue' { - $issueLabels.Count | Should -Be ($issueLables - 1) + $issueLabels.Count | Should -Be ($issueLabels.Count - 1) $issueLabels.name | Should -Not -Contain $labelToRemove } } @@ -905,7 +906,7 @@ try $issueLabels = @($issue | Get-GitHubLabel) It 'Should have removed the expected label from the issue' { - $issueLabels.Count | Should -Be ($issueLables - 1) + $issueLabels.Count | Should -Be ($issueLabels.Count - 1) $issueLabels.name | Should -Not -Contain $labelToRemove } } @@ -927,7 +928,7 @@ try $issueLabels = @($issue | Get-GitHubLabel) It 'Should have removed the expected label from the issue' { - $issueLabels.Count | Should -Be ($issueLables - 1) + $issueLabels.Count | Should -Be ($issueLabels.Count - 1) $issueLabels.name | Should -Not -Contain $labelToRemove } } @@ -950,7 +951,7 @@ try $issueLabels = @($issue | Get-GitHubLabel) It 'Should have removed the expected label from the issue' { - $issueLabels.Count | Should -Be ($issueLables - 1) + $issueLabels.Count | Should -Be ($issueLabels.Count - 1) $issueLabels.name | Should -Not -Contain $labelToRemove } } @@ -995,7 +996,7 @@ try $issue.labels.Count | Should -Be $labelsToAdd.Count foreach ($label in $labelsToAdd) { - $issue.labels | Should -Contain $label + $issue.labels.name | Should -Contain $label } } @@ -1003,10 +1004,11 @@ try $result = @(Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number -Label $newIssueLabels) It 'Should have the expected labels' { + Write-Host "Expected labels: $($newIssueLabels.name). Returned labels: $($result.name)" $result.labels.Count | Should -Be $newIssueLabels.Count foreach ($label in $newIssueLabels) { - $result.labels | Should -Contain $label + $result.labels.name | Should -Contain $label } } @@ -1029,7 +1031,7 @@ try $issue.labels.Count | Should -Be $labelsToAdd.Count foreach ($label in $labelsToAdd) { - $issue.labels | Should -Contain $label + $issue.labels.name | Should -Contain $label } } @@ -1040,7 +1042,7 @@ try $result.labels.Count | Should -Be $newIssueLabels.Count foreach ($label in $newIssueLabels) { - $result.labels | Should -Contain $label + $result.labels.name | Should -Contain $label } } @@ -1063,7 +1065,7 @@ try $issue.labels.Count | Should -Be $labelsToAdd.Count foreach ($label in $labelsToAdd) { - $issue.labels | Should -Contain $label + $issue.labels.name | Should -Contain $label } } @@ -1074,7 +1076,7 @@ try $result.labels.Count | Should -Be $newIssueLabels.Count foreach ($label in $newIssueLabels) { - $result.labels | Should -Contain $label + $result.labels.name | Should -Contain $label } } @@ -1097,7 +1099,7 @@ try $issue.labels.Count | Should -Be $labelsToAdd.Count foreach ($label in $labelsToAdd) { - $issue.labels | Should -Contain $label + $issue.labels.name | Should -Contain $label } } @@ -1108,7 +1110,7 @@ try $result.labels.Count | Should -Be $newIssueLabels.Count foreach ($label in $newIssueLabels) { - $result.labels | Should -Contain $label + $result.labels.name | Should -Contain $label } } From e1b7a0cbfaf6416de3b5ad51063a3525049f23e3 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sun, 14 Jun 2020 11:23:09 -0700 Subject: [PATCH 54/80] All labels tests passing --- GitHubIssues.ps1 | 2 + GitHubLabels.ps1 | 120 +++++++++++----------- Tests/GitHubLabels.tests.ps1 | 193 ++++++++++++++++++++++++++++++----- 3 files changed, 228 insertions(+), 87 deletions(-) diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index fd9ba50e..110b583c 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -541,6 +541,8 @@ filter New-GitHubIssue [string[]] $Assignee, + [Parameter(ValueFromPipelineByPropertyName)] + [Alias('MilestoneNumber')] [int64] $Milestone, [string[]] $Label, diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index d06ddef4..0d13da25 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -163,8 +163,7 @@ filter Get-GitHubLabel 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethodMultipleResult @params | - Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubLabelAdditionalProperties) } filter New-GitHubLabel @@ -293,8 +292,7 @@ filter New-GitHubLabel 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethod @params | - Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) + return (Invoke-GHRestMethod @params | Add-GitHubLabelAdditionalProperties) } filter Remove-GitHubLabel @@ -552,8 +550,7 @@ filter Update-GitHubLabel 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethod @params | - Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) + return (Invoke-GHRestMethod @params | Add-GitHubLabelAdditionalProperties) } filter Set-GitHubLabel @@ -633,6 +630,7 @@ filter Set-GitHubLabel [Alias('RepositoryUrl')] [string] $Uri, + [Parameter(ValueFromPipelineByPropertyName)] [object[]] $Label, [string] $AccessToken, @@ -686,7 +684,7 @@ filter Set-GitHubLabel } } -filter Add-GitHubIssueLabel +function Add-GitHubIssueLabel { <# .DESCRIPTION @@ -730,6 +728,13 @@ filter Add-GitHubIssueLabel Add-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Label $labels Adds labels to an issue in the PowerShellForGitHub project. + + .NOTES + This is implemented as a function rather than a filter because the ValueFromPipeline + parameter (Name) is itself an array which we want to ensure is processed only a single time. + This API endpoint doesn't add labels to a repository, it replaces the existing labels with + the new set provided, so we need to make sure that we have all the requested labels available + to us at the time that the API endpoint is called. #> [CmdletBinding( SupportsShouldProcess, @@ -770,36 +775,51 @@ filter Add-GitHubIssueLabel [switch] $NoStatus ) - Write-InvocationLog - - $elements = Resolve-RepositoryElements - $OwnerName = $elements.ownerName - $RepositoryName = $elements.repositoryName - - $telemetryProperties = @{ - 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) - 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) - 'LabelCount' = $Label.Count + begin + { + $labelNames = @() } - $hashBody = @{ - 'labels' = $Label + process + { + foreach ($name in $Label) + { + $labelNames += $name + } } - $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/labels" - 'Body' = (ConvertTo-Json -InputObject $hashBody) - 'Method' = 'Post' - 'Description' = "Adding labels to issue $Issue in $RepositoryName" - 'AcceptHeader' = $script:symmetraAcceptHeader - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - } + end + { + Write-InvocationLog - return (Invoke-GHRestMethod @params | - Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) + $elements = Resolve-RepositoryElements + $OwnerName = $elements.ownerName + $RepositoryName = $elements.repositoryName + + $telemetryProperties = @{ + 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) + 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) + 'LabelCount' = $Label.Count + } + + $hashBody = @{ + 'labels' = $labelNames + } + + $params = @{ + 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/labels" + 'Body' = (ConvertTo-Json -InputObject $hashBody) + 'Method' = 'Post' + 'Description' = "Adding labels to issue $Issue in $RepositoryName" + 'AcceptHeader' = $script:symmetraAcceptHeader + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + } + + return (Invoke-GHRestMethod @params | Add-GitHubLabelAdditionalProperties) + } } function Set-GitHubIssueLabel @@ -826,7 +846,7 @@ function Set-GitHubIssueLabel .PARAMETER Issue Issue number to replace the labels. - .PARAMETER LabelName + .PARAMETER Label Array of label names that will be set on the issue. .PARAMETER Force @@ -901,7 +921,7 @@ function Set-GitHubIssueLabel [Alias('IssueNumber')] [int64] $Issue, - [Parameter(ValueFromPipeline)] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('LabelName')] [string[]] $Label, @@ -948,7 +968,7 @@ function Set-GitHubIssueLabel $ConfirmPreference = 'None' } - if (($null -eq $Label) -and (-not $PSCmdlet.ShouldProcess($Issue, "Remove all labels from issue"))) + if (($labelNames.Count -eq 0) -and (-not $PSCmdlet.ShouldProcess($Issue, "Remove all labels from issue"))) { return } @@ -965,8 +985,7 @@ function Set-GitHubIssueLabel 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethod @params | - Add-GitHubLabelAdditionalProperties -TypeName $script:GitHubLabelTypeName -OwnerName $OwnerName -RepositoryName $RepositoryName) + return (Invoke-GHRestMethod @params | Add-GitHubLabelAdditionalProperties) } } @@ -1055,9 +1074,7 @@ filter Remove-GitHubIssueLabel [Alias('IssueNumber')] [int64] $Issue, - [Parameter( - ValueFromPipeline, - ValueFromPipelineByPropertyName)] + [Parameter(ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [Alias('LabelName')] [string] $Label, @@ -1123,14 +1140,6 @@ filter Add-GitHubLabelAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. - - .PARAMETER OwnerName - Owner of the repository. This information might be obtainable from InputObject, so this - is optional based on what InputObject contains. - - .PARAMETER RepositoryName - Name of the repository. This information might be obtainable from InputObject, so this - is optional based on what InputObject contains. #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] @@ -1143,11 +1152,7 @@ filter Add-GitHubLabelAdditionalProperties [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] - [string] $TypeName = $script:GitHubLabelTypeName, - - [string] $OwnerName, - - [string] $RepositoryName + [string] $TypeName = $script:GitHubLabelTypeName ) foreach ($item in $InputObject) @@ -1156,12 +1161,9 @@ filter Add-GitHubLabelAdditionalProperties if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { - if ($PSBoundParameters.ContainsKey('OwnerName') -and - $PSBoundParameters.ContainsKey('RepositoryName')) - { - $repositoryUrl = (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName) - Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force - } + $elements = Split-GitHubUri -Uri $item.url + $repositoryUrl = Join-GitHubUri @elements + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force if ($null -ne $item.id) { diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index e116cd12..4b1ae3f5 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -181,8 +181,9 @@ try } } - # This test has been disabled until we can figure out how to fix the parameter sets for - # Get-GitHubLabel pipelining to still support Label this way. + # TODO: This test has been disabled until we can figure out how to fix the parameter sets + # for Get-GitHubLabel pipelining to still support Label this way. + # # Context 'When querying for a specific label (via Label on pipeline)' { # $labelName = 'bug' # $label = $labelName | Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName @@ -583,7 +584,7 @@ try } - Describe 'Adding labels to an issue'{ + Describe 'Adding labels to an issue' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $script:repositoryName @@ -884,7 +885,7 @@ try $issueLabels = @($issue | Get-GitHubLabel) It 'Should have removed the expected label from the issue' { - $issueLabels.Count | Should -Be ($issueLabels.Count - 1) + $issueLabels.Count | Should -Be ($labelsToAdd.Count - 1) $issueLabels.name | Should -Not -Contain $labelToRemove } } @@ -906,12 +907,37 @@ try $issueLabels = @($issue | Get-GitHubLabel) It 'Should have removed the expected label from the issue' { - $issueLabels.Count | Should -Be ($issueLabels.Count - 1) + $issueLabels.Count | Should -Be ($labelsToAdd.Count - 1) $issueLabels.name | Should -Not -Contain $labelToRemove } } - Context 'For removing an individual issue using the label name on the pipeline' { + # TODO: This has been disabled for now, as ValueFromPipeline has been disabled until we + # sort out some complication issues with the ParameterSets + # + # Context 'For removing an individual issue using the label name on the pipeline' { + # $issueName = [Guid]::NewGuid().Guid + # $issue = $repo | New-GitHubIssue -Title $issueName + + # $labelsToAdd = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[2].name, $defaultLabels[3].name) + # $issue | Add-GitHubIssueLabel -LabelName $labelsToAdd + + # $issueLabels = @($issue | Get-GitHubLabel) + # It 'Should have the expected number of labels' { + # $issueLabels.Count | Should -Be $labelsToAdd.Count + # } + + # $labelToRemove = $labelsToAdd[2] + # $labelToRemove | Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number -Confirm:$false + + # $issueLabels = @($issue | Get-GitHubLabel) + # It 'Should have removed the expected label from the issue' { + # $issueLabels.Count | Should -Be ($labelsToAdd.Count - 1) + # $issueLabels.name | Should -Not -Contain $labelToRemove + # } + # } + + Context 'For removing an individual issue using the label object on the pipeline' { $issueName = [Guid]::NewGuid().Guid $issue = $repo | New-GitHubIssue -Title $issueName @@ -923,17 +949,18 @@ try $issueLabels.Count | Should -Be $labelsToAdd.Count } - $labelToRemove = $labelsToAdd[2] - $labelToRemove | Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number -Confirm:$false + $labelToRemove = $labelsToAdd[0] + $label = $repo | Get-GitHubLabel -Label $labelToRemove + $label | Remove-GitHubIssueLabel -Issue $issue.number -Confirm:$false $issueLabels = @($issue | Get-GitHubLabel) It 'Should have removed the expected label from the issue' { - $issueLabels.Count | Should -Be ($issueLabels.Count - 1) + $issueLabels.Count | Should -Be ($labelsToAdd.Count - 1) $issueLabels.name | Should -Not -Contain $labelToRemove } } - Context 'For removing an individual issue using the label object on the pipeline' { + Context 'For removing all issues' { $issueName = [Guid]::NewGuid().Guid $issue = $repo | New-GitHubIssue -Title $issueName @@ -945,18 +972,15 @@ try $issueLabels.Count | Should -Be $labelsToAdd.Count } - $labelToRemove = $labelsToAdd[0] - $label = $repo | Get-GitHubLabel -Label $labelToRemove - $label | Remove-GitHubIssueLabel -Issue $issue.number -Confirm:$false + $issue | Remove-GitHubIssueLabel -Confirm:$false $issueLabels = @($issue | Get-GitHubLabel) - It 'Should have removed the expected label from the issue' { - $issueLabels.Count | Should -Be ($issueLabels.Count - 1) - $issueLabels.name | Should -Not -Contain $labelToRemove + It 'Should have removed all labels from the issue' { + $issueLabels.Count | Should -Be 0 } } - Context 'For removing all issues' { + Context 'For removing all issues using Set-GitHubIssueLabel with the Issue on the pipeline' { $issueName = [Guid]::NewGuid().Guid $issue = $repo | New-GitHubIssue -Title $issueName @@ -968,7 +992,7 @@ try $issueLabels.Count | Should -Be $labelsToAdd.Count } - $issue | Remove-GitHubIssueLabel -Confirm:$false + $issue | Set-GitHubIssueLabel -Confirm:$false -verbose $issueLabels = @($issue | Get-GitHubLabel) It 'Should have removed all labels from the issue' { @@ -977,7 +1001,7 @@ try } } - Describe 'Replacing labels on an issue'{ + Describe 'Replacing labels on an issue' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $script:repositoryName @@ -1004,11 +1028,10 @@ try $result = @(Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number -Label $newIssueLabels) It 'Should have the expected labels' { - Write-Host "Expected labels: $($newIssueLabels.name). Returned labels: $($result.name)" $result.labels.Count | Should -Be $newIssueLabels.Count foreach ($label in $newIssueLabels) { - $result.labels.name | Should -Contain $label + $result.name | Should -Contain $label } } @@ -1042,7 +1065,7 @@ try $result.labels.Count | Should -Be $newIssueLabels.Count foreach ($label in $newIssueLabels) { - $result.labels.name | Should -Contain $label + $result.name | Should -Contain $label } } @@ -1076,7 +1099,7 @@ try $result.labels.Count | Should -Be $newIssueLabels.Count foreach ($label in $newIssueLabels) { - $result.labels.name | Should -Contain $label + $result.name | Should -Contain $label } } @@ -1103,14 +1126,15 @@ try } } - $newIssueLabels = @($defaultLabels[0].name, $defaultLabels[5].name) - $result = @($newIssueLabels | Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number) + $newIssueLabelNames = @($defaultLabels[0].name, $defaultLabels[5].name) + $issueLabels = @($newIssueLabelNames | ForEach-Object { $repo | Get-GitHubLabel -Label $_ }) + $result = @($issueLabels | Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number) It 'Should have the expected labels' { - $result.labels.Count | Should -Be $newIssueLabels.Count - foreach ($label in $newIssueLabels) + $result.labels.Count | Should -Be $newIssueLabelNames.Count + foreach ($label in $newIssueLabelNames) { - $result.labels.name | Should -Contain $label + $result.name | Should -Contain $label } } @@ -1125,6 +1149,119 @@ try } } } + + Describe 'Labels and Milestones' { + BeforeAll { + $repositoryName = [Guid]::NewGuid().Guid + $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo | Set-GitHubLabel -Label $defaultLabels + + $milestone = $repo | New-GitHubMilestone -Title 'test milestone' + + $issueLabels = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[3].name) + $issue = $milestone | New-GitHubIssue -Title 'test issue' -Label $issueLabels + + $issueLabels2 = @($defaultLabels[4].name, $defaultLabels[5].name) + $issue2 = $milestone | New-GitHubIssue -Title 'test issue' -Label $issueLabels2 + } + + AfterAll { + $repo | Remove-GitHubRepository -Force + } + + Context 'Getting labels for issues in a milestone with parameters' { + It 'Should return the number of labels that were just added to the issue' { + $issue.labels.Count | Should -Be $issueLabels.Count + $issue2.labels.Count | Should -Be $issueLabels2.Count + } + + $milestoneLabels = Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Milestone $milestone.number + + It 'Should return the same number of labels in the issue that were assigned to the milestone' { + $milestoneLabels.Count | Should -Be ($issue.labels.Count + $issue2.labels.Count) + } + + It 'Should be the right set of labels' { + $allLabels = $issue.labels.name + $issue2.labels.name + foreach ($label in $allLabels) + { + $milestoneLabels.name | Should -Contain $label + } + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $milestoneLabels) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + } + + Context 'Getting labels for issues in a milestone with the repo on the pipeline' { + It 'Should return the number of labels that were just added to the issue' { + $issue.labels.Count | Should -Be $issueLabels.Count + $issue2.labels.Count | Should -Be $issueLabels2.Count + } + + $milestoneLabels = $repo | Get-GitHubLabel -Milestone $milestone.number + + It 'Should return the same number of labels in the issues that were assigned to the milestone' { + $milestoneLabels.Count | Should -Be ($issue.labels.Count + $issue2.labels.Count) + } + + It 'Should be the right set of labels' { + $allLabels = $issue.labels.name + $issue2.labels.name + foreach ($label in $allLabels) + { + $milestoneLabels.name | Should -Contain $label + } + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $milestoneLabels) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + } + + Context 'Getting labels for issues in a milestone on the pipeline' { + It 'Should return the number of labels that were just added to the issue' { + $issue.labels.Count | Should -Be $issueLabels.Count + $issue2.labels.Count | Should -Be $issueLabels2.Count + } + + $milestoneLabels = $milestone | Get-GitHubLabel + + It 'Should return the same number of labels in the issue that is assigned to the milestone' { + $milestoneLabels.Count | Should -Be ($issue.labels.Count + $issue2.labels.Count) + } + + It 'Should be the right set of labels' { + $allLabels = $issue.labels.name + $issue2.labels.name + foreach ($label in $allLabels) + { + $milestoneLabels.name | Should -Contain $label + } + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $milestoneLabels) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + } + } } finally { From a8f03069eb792b7e4402a77e71caa23149b5d2ed Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 15 Jun 2020 10:50:24 -0700 Subject: [PATCH 55/80] Completing label ut's --- GitHubLabels.ps1 | 12 +++++ Tests/GitHubLabels.tests.ps1 | 85 +++++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 0d13da25..ccc3d168 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -64,6 +64,11 @@ filter Get-GitHubLabel Gets the information for the label named "TestLabel" from the Microsoft\PowerShellForGitHub project. + + .NOTES + There were a lot of complications with the ParameterSets with this function due to pipeline + input. For the time being, the ParameterSets have been simplified and the validation of + parameter combinations is happening within the function itself. #> [CmdletBinding( SupportsShouldProcess, @@ -341,6 +346,13 @@ filter Remove-GitHubLabel Removes the label called "TestLabel" from the PowerShellForGitHub project. + .EXAMPLE + $label = $repo | Get-GitHubLabel -Label 'Test Label' -Color '#AAAAAA' + $label | Remove-GitHubLabel + + Removes the label we just created using the pipeline, but will prompt for confirmation + because neither -Confirm:$false nor -Force was specified. + .EXAMPLE Remove-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -Confirm:$false diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index 4b1ae3f5..8c1eb205 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -285,6 +285,34 @@ try $label.LabelName | Should -Be $label.name } } + + Context 'On a repo with three names on the pipeline' { + $labelNames = @(([Guid]::NewGuid().Guid), ([Guid]::NewGuid().Guid), ([Guid]::NewGuid().Guid)) + $color = 'CCCCCC' + $labels = @($labelNames | New-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Color $color) + + It 'Has the right count of labels' { + $labels.Count | Should -Be $labelNames.Count + } + + It 'Has the right label details' { + foreach ($label in $labels) + { + $labelNames | Should -Contain $label.name + $label.color | Should -Be $color + } + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $labels) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + } } Describe 'Removing a label' { @@ -323,6 +351,15 @@ try { $label | Get-GitHubLabel } | Should -Throw } } + + Context 'Removing a label with the label object on the pipeline' { + $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' + $label | Remove-GitHubLabel -Force + + It 'Should be gone after being removed by parameter' { + { $label | Get-GitHubLabel } | Should -Throw + } + } } Describe 'Updating a label' { @@ -724,7 +761,7 @@ try } } - Context 'Adding labels to an issue with the labels on the pipeline' { + Context 'Adding labels to an issue with the label names on the pipeline' { $expectedLabels = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[3].name) $issue = $repo | New-GitHubIssue -Title 'test issue' $result = @($expectedLabels | Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number) @@ -766,6 +803,50 @@ try } } } + + Context 'Adding labels to an issue with the label object on the pipeline' { + $expectedLabels = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[3].name) + $issue = $repo | New-GitHubIssue -Title 'test issue' + $labels = @($expectedLabels | ForEach-Object { Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $_ } ) + $result = @($labels | Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number) + + It 'Should return the number of labels that were just added' { + $result.Count | Should -Be $expectedLabels.Count + } + + It 'Should be the right set of labels' { + foreach ($label in $expectedLabels) + { + $result.name | Should -Contain $label + } + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $result) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + + $issueLabels = $issue | Get-GitHubLabel + + It 'Should return the number of labels that were just added from querying the issue again' { + $issueLabels.Count | Should -Be $expectedLabels.Count + } + + It 'Should have the expected type and additional properties' { + foreach ($label in $issueLabels) + { + $label.PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + $label.RepositoryUrl | Should -Be $repo.RepositoryUrl + $label.LabelId | Should -Be $label.id + $label.LabelName | Should -Be $label.name + } + } + } } Describe 'Creating a new Issue with labels' { @@ -992,7 +1073,7 @@ try $issueLabels.Count | Should -Be $labelsToAdd.Count } - $issue | Set-GitHubIssueLabel -Confirm:$false -verbose + $issue | Set-GitHubIssueLabel -Confirm:$false $issueLabels = @($issue | Get-GitHubLabel) It 'Should have removed all labels from the issue' { From cff60618587dd43a4d9e962e0db4f6e9f3edb923 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 15 Jun 2020 11:05:49 -0700 Subject: [PATCH 56/80] Slight update to milestone tests --- Tests/GitHubMilestones.tests.ps1 | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Tests/GitHubMilestones.tests.ps1 b/Tests/GitHubMilestones.tests.ps1 index a60d0fcf..048e5dac 100644 --- a/Tests/GitHubMilestones.tests.ps1 +++ b/Tests/GitHubMilestones.tests.ps1 @@ -232,19 +232,33 @@ try $openMilestone | Remove-GitHubMilestone -Force } + $milestone = $closedMilestone + $returned = Get-GitHubMilestone -Uri $repo.RepositoryUrl -Milestone $milestone.MilestoneNumber It 'Should get the right milestone as a parameter' { - $milestone = $closedMilestone - $returned = Get-GitHubMilestone -Uri $repo.RepositoryUrl -Milestone $milestone.MilestoneNumber - $returned.MilestoneId | Should -Be $milestone.MilestoneId } - It 'Should get the right milestone via the pipeline' { - $milestone = $openMilestone - $returned = $openMilestone | Get-GitHubMilestone + It 'Should have the expected type and additional properties' { + $returned.PSObject.TypeNames[0] | Should -Be 'GitHub.Milestone' + $returned.RepositoryUrl | Should -Be $repo.RepositoryUrl + $returned.MilestoneId | Should -Be $returned.id + $returned.MilestoneNumber | Should -Be $returned.number + $returned.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + $milestone = $openMilestone + $returned = $openMilestone | Get-GitHubMilestone + It 'Should get the right milestone via the pipeline' { $returned.MilestoneId | Should -Be $milestone.MilestoneId } + + It 'Should have the expected type and additional properties' { + $returned.PSObject.TypeNames[0] | Should -Be 'GitHub.Milestone' + $returned.RepositoryUrl | Should -Be $repo.RepositoryUrl + $returned.MilestoneId | Should -Be $returned.id + $returned.MilestoneNumber | Should -Be $returned.number + $returned.creator.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } Context 'Getting multiple milestones' { From ab6e58e48b4362dc03c1c464d4cba4a963e630c5 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 15 Jun 2020 12:15:49 -0700 Subject: [PATCH 57/80] Update contents tests --- GitHubContents.ps1 | 11 +++++++- Tests/GitHubContents.tests.ps1 | 51 +++++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/GitHubContents.ps1 b/GitHubContents.ps1 index 6a75d81e..c222479b 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -59,6 +59,16 @@ filter Get-GitHubContent Get-GitHubContent -OwnerName microsoft -RepositoryName PowerShellForGitHub -Path Tests List the files within the "Tests" path of the repository + + .EXAMPLE + $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub + $repo | Get-GitHubContent -Path Tests + + List the files within the "Tests" path of the repository + + .NOTES + Unable to specify Path as ValueFromPipeline because a Repository object may be incorrectly + coerced into a string used for Path, thus confusing things. #> [CmdletBinding( SupportsShouldProcess, @@ -78,7 +88,6 @@ filter Get-GitHubContent [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(ValueFromPipeline)] [string] $Path, [ValidateSet('Raw', 'Html', 'Object')] diff --git a/Tests/GitHubContents.tests.ps1 b/Tests/GitHubContents.tests.ps1 index 3685a552..bd372626 100644 --- a/Tests/GitHubContents.tests.ps1 +++ b/Tests/GitHubContents.tests.ps1 @@ -34,25 +34,34 @@ try } Describe 'Getting file and folder content' { - # AutoInit will create a readme with the GUID of the repo name - $repo = New-GitHubRepository -RepositoryName ($repoGuid) -AutoInit + BeforeAll { + # AutoInit will create a readme with the GUID of the repo name + $repo = New-GitHubRepository -RepositoryName ($repoGuid) -AutoInit + } - Context 'For getting folder contents' { + AfterAll { + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + } + Context 'For getting folder contents with parameters' { $folderOutput = Get-GitHubContent -OwnerName $script:ownerName -RepositoryName $repo.name It "Should have the expected name" { - $folderOutput.name | Should -Be "" + $folderOutput.name | Should -BeNullOrEmpty } + It "Should have the expected path" { - $folderOutput.path | Should -Be "" + $folderOutput.path | Should -BeNullOrEmpty } + It "Should have the expected type" { $folderOutput.type | Should -Be "dir" } + It "Should have the expected entries" { $folderOutput.entries.length | Should -Be 1 } + It "Should have the expected entry data" { $folderOutput.entries[0].name | Should -Be $readmeFileName $folderOutput.entries[0].path | Should -Be $readmeFileName @@ -60,14 +69,13 @@ try } Context 'For getting folder contents via URL' { - $folderOutput = Get-GitHubContent -Uri "https://github.com/$($script:ownerName)/$($repo.name)" It "Should have the expected name" { - $folderOutput.name | Should -Be "" + $folderOutput.name | Should -BeNullOrEmpty } It "Should have the expected path" { - $folderOutput.path | Should -Be "" + $folderOutput.path | Should -BeNullOrEmpty } It "Should have the expected type" { $folderOutput.type | Should -Be "dir" @@ -81,6 +89,31 @@ try } } + Context 'For getting folder contents with the repo on the pipeline' { + $folderOutput = $repo | Get-GitHubContent + + It "Should have the expected name" { + $folderOutput.name | Should -BeNullOrEmpty + } + + It "Should have the expected path" { + $folderOutput.path | Should -BeNullOrEmpty + } + + It "Should have the expected type" { + $folderOutput.type | Should -Be "dir" + } + + It "Should have the expected entries" { + $folderOutput.entries.length | Should -Be 1 + } + + It "Should have the expected entry data" { + $folderOutput.entries[0].name | Should -Be $readmeFileName + $folderOutput.entries[0].path | Should -Be $readmeFileName + } + } + Context 'For getting raw (byte) file contents' { $readmeFileBytes = Get-GitHubContent -OwnerName $script:ownerName -RepositoryName $repo.name -Path $readmeFileName -MediaType Raw @@ -174,8 +207,6 @@ try $readmeFileObject.contentAsString | Should -Be $rawOutput } } - - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } } finally From f61318224bb6fa1d9f119adf382709736267a8f2 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 15 Jun 2020 12:22:52 -0700 Subject: [PATCH 58/80] Fixing repositoryName parameter --- Tests/GitHubLabels.tests.ps1 | 74 ++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index 8c1eb205..85d4556a 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -79,9 +79,9 @@ try Describe 'Getting labels from a repository' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo = New-GitHubRepository -RepositoryName repositoryName - Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $defaultLabels + Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $defaultLabels } AfterAll { @@ -151,7 +151,7 @@ try Context 'When querying for a specific label' { $labelName = 'bug' - $label = Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $labelName + $label = Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $labelName It 'Should return expected label' { $label.name | Should -Be $labelName @@ -186,7 +186,7 @@ try # # Context 'When querying for a specific label (via Label on pipeline)' { # $labelName = 'bug' - # $label = $labelName | Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName + # $label = $labelName | Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName # It 'Should return expected label' { # $label.name | Should -Be $labelName @@ -204,7 +204,7 @@ try Describe 'Creating a new label' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo = New-GitHubRepository -RepositoryName repositoryName } AfterAll { @@ -214,7 +214,7 @@ try Context 'On a repo with parameters' { $labelName = [Guid]::NewGuid().Guid $color = 'AAAAAA' - $label = New-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $labelName -Color $color + $label = New-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $labelName -Color $color It 'New label should be created' { $label.name | Should -Be $labelName @@ -232,7 +232,7 @@ try Context 'On a repo with and color starts with a #' { $labelName = [Guid]::NewGuid().Guid $color = '#AAAAAA' - $label = New-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $labelName -Color $color + $label = New-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $labelName -Color $color It 'New label should be created' { $label.name | Should -Be $labelName @@ -271,7 +271,7 @@ try Context 'On a repo with the name on the pipeline' { $labelName = [Guid]::NewGuid().Guid $color = 'CCCCCC' - $label = $labelName | New-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Color $color + $label = $labelName | New-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Color $color It 'New label should be created' { $label.name | Should -Be $labelName @@ -289,7 +289,7 @@ try Context 'On a repo with three names on the pipeline' { $labelNames = @(([Guid]::NewGuid().Guid), ([Guid]::NewGuid().Guid), ([Guid]::NewGuid().Guid)) $color = 'CCCCCC' - $labels = @($labelNames | New-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Color $color) + $labels = @($labelNames | New-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Color $color) It 'Has the right count of labels' { $labels.Count | Should -Be $labelNames.Count @@ -318,7 +318,7 @@ try Describe 'Removing a label' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo = New-GitHubRepository -RepositoryName repositoryName } AfterAll { @@ -327,7 +327,7 @@ try Context 'Removing a label with parameters' { $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' - Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $label.name -Force + Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $label.name -Force It 'Should be gone after being removed by parameter' { { $label | Get-GitHubLabel } | Should -Throw @@ -345,7 +345,7 @@ try Context 'Removing a label with the name on the pipeline' { $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' - $label.name | Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Force + $label.name | Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Force It 'Should be gone after being removed by parameter' { { $label | Get-GitHubLabel } | Should -Throw @@ -365,7 +365,7 @@ try Describe 'Updating a label' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo = New-GitHubRepository -RepositoryName repositoryName } AfterAll { @@ -376,7 +376,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' $newColor = 'AAAAAA' - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $label.name -Color $newColor + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $label.name -Color $newColor It 'Label should have different color' { $result.name | Should -Be $label.name @@ -396,7 +396,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' $newColor = '#AAAAAA' - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $label.name -Color $newColor + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $label.name -Color $newColor It 'Label should have different color' { $result.name | Should -Be $label.name @@ -416,7 +416,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' $newName = [Guid]::NewGuid().Guid - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $label.name -NewName $newName + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $label.name -NewName $newName It 'Label should have different name' { $result.name | Should -Be $newName @@ -436,7 +436,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' -Description 'test description' $newDescription = [Guid]::NewGuid().Guid - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $label.name -Description $newDescription + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $label.name -Description $newDescription It 'Label should have different name' { $result.name | Should -Be $label.name @@ -458,7 +458,7 @@ try $newName = [Guid]::NewGuid().Guid $newColor = 'AAAAAA' $newDescription = [Guid]::NewGuid().Guid - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $label.name -NewName $newName -Color $newColor -Description $newDescription + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $label.name -NewName $newName -Color $newColor -Description $newDescription It 'Label should have different everything' { $result.name | Should -Be $newName @@ -542,7 +542,7 @@ try Describe 'Initializing the labels on a repository' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo = New-GitHubRepository -RepositoryName repositoryName } AfterAll { @@ -550,7 +550,7 @@ try } Context 'Applying a default set of labels' { - Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $defaultLabels + Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $defaultLabels $labels = @($repo | Get-GitHubLabel) @@ -624,7 +624,7 @@ try Describe 'Adding labels to an issue' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo = New-GitHubRepository -RepositoryName repositoryName $repo | Set-GitHubLabel -Label $defaultLabels } @@ -635,7 +635,7 @@ try Context 'Adding labels to an issue' { $expectedLabels = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[3].name) $issue = $repo | New-GitHubIssue -Title 'test issue' - $result = @(Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number -LabelName $expectedLabels) + $result = @(Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Issue $issue.number -LabelName $expectedLabels) It 'Should return the number of labels that were just added' { $result.Count | Should -Be $expectedLabels.Count @@ -764,7 +764,7 @@ try Context 'Adding labels to an issue with the label names on the pipeline' { $expectedLabels = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[3].name) $issue = $repo | New-GitHubIssue -Title 'test issue' - $result = @($expectedLabels | Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number) + $result = @($expectedLabels | Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Issue $issue.number) It 'Should return the number of labels that were just added' { $result.Count | Should -Be $expectedLabels.Count @@ -807,8 +807,8 @@ try Context 'Adding labels to an issue with the label object on the pipeline' { $expectedLabels = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[3].name) $issue = $repo | New-GitHubIssue -Title 'test issue' - $labels = @($expectedLabels | ForEach-Object { Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $_ } ) - $result = @($labels | Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number) + $labels = @($expectedLabels | ForEach-Object { Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $_ } ) + $result = @($labels | Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Issue $issue.number) It 'Should return the number of labels that were just added' { $result.Count | Should -Be $expectedLabels.Count @@ -852,7 +852,7 @@ try Describe 'Creating a new Issue with labels' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo = New-GitHubRepository -RepositoryName repositoryName $repo | Set-GitHubLabel -Label $defaultLabels } @@ -863,7 +863,7 @@ try Context 'When creating a new issue using parameters' { $issueName = [Guid]::NewGuid().Guid $issueLabels = @($defaultLabels[0].name, $defaultLabels[1].name) - $issue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Title $issueName -Label $issueLabels + $issue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName repositoryName -Title $issueName -Label $issueLabels It 'Should return the number of labels that were just added' { $issue.labels.Count | Should -Be $issueLabels.Count @@ -918,7 +918,7 @@ try Describe 'Removing labels on an issue' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo = New-GitHubRepository -RepositoryName repositoryName $repo | Set-GitHubLabel -Label $defaultLabels } @@ -939,9 +939,9 @@ try } # Doing this manually instead of in a loop to try out different combinations of -Confirm:$false and -Force - Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $labelsToAdd[0] -Issue $issue.number -Confirm:$false - Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $labelsToAdd[1] -Issue $issue.number -Force - Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Label $labelsToAdd[2] -Issue $issue.number -Confirm:$false -Force + Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $labelsToAdd[0] -Issue $issue.number -Confirm:$false + Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $labelsToAdd[1] -Issue $issue.number -Force + Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $labelsToAdd[2] -Issue $issue.number -Confirm:$false -Force $issueLabels = @($issue | Get-GitHubLabel) It 'Should have removed all labels from the issue' { @@ -1009,7 +1009,7 @@ try # } # $labelToRemove = $labelsToAdd[2] - # $labelToRemove | Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number -Confirm:$false + # $labelToRemove | Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Issue $issue.number -Confirm:$false # $issueLabels = @($issue | Get-GitHubLabel) # It 'Should have removed the expected label from the issue' { @@ -1085,7 +1085,7 @@ try Describe 'Replacing labels on an issue' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo = New-GitHubRepository -RepositoryName repositoryName $repo | Set-GitHubLabel -Label $defaultLabels } @@ -1106,7 +1106,7 @@ try } $newIssueLabels = @($defaultLabels[0].name, $defaultLabels[5].name) - $result = @(Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number -Label $newIssueLabels) + $result = @(Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Issue $issue.number -Label $newIssueLabels) It 'Should have the expected labels' { $result.labels.Count | Should -Be $newIssueLabels.Count @@ -1209,7 +1209,7 @@ try $newIssueLabelNames = @($defaultLabels[0].name, $defaultLabels[5].name) $issueLabels = @($newIssueLabelNames | ForEach-Object { $repo | Get-GitHubLabel -Label $_ }) - $result = @($issueLabels | Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Issue $issue.number) + $result = @($issueLabels | Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Issue $issue.number) It 'Should have the expected labels' { $result.labels.Count | Should -Be $newIssueLabelNames.Count @@ -1234,7 +1234,7 @@ try Describe 'Labels and Milestones' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName $script:repositoryName + $repo = New-GitHubRepository -RepositoryName repositoryName $repo | Set-GitHubLabel -Label $defaultLabels $milestone = $repo | New-GitHubMilestone -Title 'test milestone' @@ -1256,7 +1256,7 @@ try $issue2.labels.Count | Should -Be $issueLabels2.Count } - $milestoneLabels = Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $script:repositoryName -Milestone $milestone.number + $milestoneLabels = Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Milestone $milestone.number It 'Should return the same number of labels in the issue that were assigned to the milestone' { $milestoneLabels.Count | Should -Be ($issue.labels.Count + $issue2.labels.Count) From 23177305d54d0cd8f552a28c2ab148acc05c9d7c Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 15 Jun 2020 12:48:59 -0700 Subject: [PATCH 59/80] Update branches tests --- GitHubBranches.ps1 | 27 ++++++++-- Tests/GitHubBranches.tests.ps1 | 90 +++++++++++++++++++++++++++++++--- 2 files changed, 105 insertions(+), 12 deletions(-) diff --git a/GitHubBranches.ps1 b/GitHubBranches.ps1 index 32e78d72..606c4e11 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -54,9 +54,29 @@ filter Get-GitHubRepositoryBranch Gets all branches for the specified repository. .EXAMPLE - Get-GitHubRepositoryBranch -Uri 'https://github.com/PowerShell/PowerShellForGitHub' -Name master + $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub + $repo | Get-GitHubRepositoryBranch + + Gets all branches for the specified repository. + + .EXAMPLE + Get-GitHubRepositoryBranch -Uri 'https://github.com/PowerShell/PowerShellForGitHub' -BranchName master Gets information only on the master branch for the specified repository. + + .EXAMPLE + $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub + $repo | Get-GitHubRepositoryBranch -BranchName master + + Gets information only on the master branch for the specified repository. + + .EXAMPLE + $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub + $branch = $repo | Get-GitHubRepositoryBranch -BranchName master + $branch | Get-GitHubRepositoryBranch + + Gets information only on the master branch for the specified repository, and then does it + again. #> [CmdletBinding( SupportsShouldProcess, @@ -80,8 +100,7 @@ filter Get-GitHubRepositoryBranch [string] $Uri, [Parameter(ValueFromPipelineByPropertyName)] - [Alias('BranchName')] - [string] $Name, + [string] $BranchName, [switch] $ProtectedOnly, @@ -102,7 +121,7 @@ filter Get-GitHubRepositoryBranch } $uriFragment = "repos/$OwnerName/$RepositoryName/branches" - if (-not [String]::IsNullOrEmpty($Name)) { $uriFragment = $uriFragment + "/$Name" } + if (-not [String]::IsNullOrEmpty($BranchName)) { $uriFragment = $uriFragment + "/$BranchName" } $getParams = @() if ($ProtectedOnly) { $getParams += 'protected=true' } diff --git a/Tests/GitHubBranches.tests.ps1 b/Tests/GitHubBranches.tests.ps1 index 6fa36a20..f0df1ca9 100644 --- a/Tests/GitHubBranches.tests.ps1 +++ b/Tests/GitHubBranches.tests.ps1 @@ -18,20 +18,94 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { Describe 'Getting branches for repository' { - $repositoryName = [guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit + BeforeAll { + $repositoryName = [guid]::NewGuid().Guid + $repo = New-GitHubRepository -RepositoryName $repositoryName -AutoInit + $branchName = 'master' + } + + AfterAll { + $repo | Remove-GitHubRepository -Confirm:$false + } + + Context 'Getting all branches for a repository with parameters' { + $branches = @(Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName) + + It 'Should return expected number of repository branches' { + $branches.Count | Should -Be 1 + } - $branches = @(Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName) + It 'Should return the name of the expected branch' { + $branches.name | Should -Contain $branchName + } - It 'Should return expected number of repository branches' { - $branches.Count | Should -Be 1 + It 'Should have the exected type and addititional properties' { + $branches[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Branch' + $branches[0].RepositoryUrl | Should -Be $repo.RepositoryUrl + $branches[0].BranchName | Should -Be $branches[0].name + } } - It 'Should return the name of the branches' { - $branches[0].name | Should -Be 'master' + Context 'Getting all branches for a repository with the repo on the pipeline' { + $branches = @($repo | Get-GitHubRepositoryBranch) + + It 'Should return expected number of repository branches' { + $branches.Count | Should -Be 1 + } + + It 'Should return the name of the expected branch' { + $branches.name | Should -Contain $branchName + } + + It 'Should have the exected type and addititional properties' { + $branches[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Branch' + $branches[0].RepositoryUrl | Should -Be $repo.RepositoryUrl + $branches[0].BranchName | Should -Be $branches[0].name + } } - $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName -Confirm:$false + Context 'Getting a specific branch for a repository with parameters' { + $branch = Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName -BranchName $branchName + + It 'Should return the expected branch name' { + $branch.name | Should -Be $branchName + } + + It 'Should have the exected type and addititional properties' { + $branch.PSObject.TypeNames[0] | Should -Be 'GitHub.Branch' + $branch.RepositoryUrl | Should -Be $repo.RepositoryUrl + $branch.BranchName | Should -Be $branch.name + } + } + + Context 'Getting a specific branch for a repository with the repo on the pipeline' { + $branch = $repo | Get-GitHubRepositoryBranch -BranchName $branchName + + It 'Should return the expected branch name' { + $branch.name | Should -Be $branchName + } + + It 'Should have the exected type and addititional properties' { + $branch.PSObject.TypeNames[0] | Should -Be 'GitHub.Branch' + $branch.RepositoryUrl | Should -Be $repo.RepositoryUrl + $branch.BranchName | Should -Be $branch.name + } + } + + Context 'Getting a specific branch for a repository with the branch object on the pipeline' { + $branch = Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName -BranchName $branchName + $branchAgain = $branch | Get-GitHubRepositoryBranch + + It 'Should return the expected branch name' { + $branchAgain.name | Should -Be $branchName + } + + It 'Should have the exected type and addititional properties' { + $branchAgain.PSObject.TypeNames[0] | Should -Be 'GitHub.Branch' + $branchAgain.RepositoryUrl | Should -Be $repo.RepositoryUrl + $branchAgain.BranchName | Should -Be $branchAgain.name + } + } } } finally From 80334d25f76188a348ec8bf001f0b3fa09e04586 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 15 Jun 2020 13:46:39 -0700 Subject: [PATCH 60/80] Updated the assignees tests --- GitHubAssignees.ps1 | 228 ++++++++++++++++++++---------- Tests/GitHubAssignees.tests.ps1 | 236 +++++++++++++++++++++++--------- 2 files changed, 331 insertions(+), 133 deletions(-) diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index 6fed5bb4..6e47d229 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -38,6 +38,12 @@ filter Get-GitHubAssignee .EXAMPLE Get-GitHubAssigneeList -OwnerName microsoft -RepositoryName PowerShellForGitHub + Lists the available assignees for issues from the Microsoft\PowerShellForGitHub project. + + .EXAMPLE + $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub + $repo | Get-GitHubAssigneeList + Lists the available assignees for issues from the Microsoft\PowerShellForGitHub project. #> [CmdletBinding( @@ -129,6 +135,18 @@ filter Test-GitHubAssignee .EXAMPLE Test-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee "LoginID123" + Checks if a user has permission to be assigned to an issue from the Microsoft\PowerShellForGitHub project. + + .EXAMPLE + $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub + $repo | Test-GitHubAssignee -Assignee 'octocat' + + Checks if a user has permission to be assigned to an issue from the Microsoft\PowerShellForGitHub project. + + .EXAMPLE + $octocat = Get-GitHubUser -UserName 'octocat' + $repo = $octocat | Test-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub + Checks if a user has permission to be assigned to an issue from the Microsoft\PowerShellForGitHub project. #> [CmdletBinding( @@ -151,6 +169,7 @@ filter Test-GitHubAssignee [Alias('RepositoryUrl')] [string] $Uri, + [Parameter(ValueFromPipelineByPropertyName)] [Alias('UserName')] [string] $Assignee, @@ -193,7 +212,7 @@ filter Test-GitHubAssignee } } -filter New-GitHubAssignee +function New-GitHubAssignee { <# .DESCRIPTION @@ -235,9 +254,31 @@ filter New-GitHubAssignee GitHub.Issue .EXAMPLE - New-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee $assignee + $assignees = @('octocat') + New-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Assignee $assignee - Lists the available assignees for issues from the Microsoft\PowerShellForGitHub project. + Additionally assigns the usernames in $assignee to Issue #1 from the Microsoft\PowerShellForGitHub project. + + .EXAMPLE + $assignees = @('octocat') + $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub + $repo | New-GitHubAssignee -Issue 1 -Assignee $assignee + + Additionally assigns the usernames in $assignee to Issue #1 from the Microsoft\PowerShellForGitHub project. + + .EXAMPLE + $assignees = @('octocat') + Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub | + Get-GitHubIssue -Issue 1 | + New-GitHubAssignee -Assignee $assignee + + Additionally assigns the usernames in $assignee to Issue #1 from the Microsoft\PowerShellForGitHub project. + + .EXAMPLE + $octocat = Get-GitHubUser -UserName 'octocat' + $octocat | New-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 + + Additionally assigns the user 'octocat' to Issue #1 from the Microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -262,12 +303,11 @@ filter New-GitHubAssignee [Parameter( Mandatory, ValueFromPipelineByPropertyName)] - [Alias('IssueId')] + [Alias('IssueNumber')] [int64] $Issue, [Parameter( Mandatory, - ValueFromPipeline, ValueFromPipelineByPropertyName)] [ValidateCount(1, 10)] [Alias('UserName')] @@ -278,39 +318,55 @@ filter New-GitHubAssignee [switch] $NoStatus ) - Write-InvocationLog - - $elements = Resolve-RepositoryElements - $OwnerName = $elements.ownerName - $RepositoryName = $elements.repositoryName - - $telemetryProperties = @{ - 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) - 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) - 'AssigneeCount' = $Assignee.Count - 'Issue' = (Get-PiiSafeString -PlainText $Issue) + begin + { + $userNames = @() } - $hashBody = @{ - 'assignees' = $Assignee + process + { + foreach ($name in $Assignee) + { + $userNames += $name + } } - $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/assignees" - 'Body' = (ConvertTo-Json -InputObject $hashBody) - 'Method' = 'Post' - 'Description' = "Add assignees to issue $Issue for $RepositoryName" - 'AccessToken' = $AccessToken - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - } + end + { + Write-InvocationLog + + $elements = Resolve-RepositoryElements + $OwnerName = $elements.ownerName + $RepositoryName = $elements.repositoryName + + $telemetryProperties = @{ + 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) + 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) + 'AssigneeCount' = $userNames.Count + 'Issue' = (Get-PiiSafeString -PlainText $Issue) + } + + $hashBody = @{ + 'assignees' = $userNames + } - return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) + $params = @{ + 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/assignees" + 'Body' = (ConvertTo-Json -InputObject $hashBody) + 'Method' = 'Post' + 'Description' = "Add assignees to issue $Issue for $RepositoryName" + 'AccessToken' = $AccessToken + 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + } + + return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) + } } -filter Remove-GitHubAssignee +function Remove-GitHubAssignee { <# .DESCRIPTION @@ -335,7 +391,7 @@ filter Remove-GitHubAssignee Issue number to remove the assignees from. .PARAMETER Assignee - Usernames of assignees to remove from an issue. NOTE: Only users with push access can remove assignees from an issue. Assignees are silently ignored otherwise. + Usernames of assignees to remove from an issue. .PARAMETER Force If this switch is specified, you will not be prompted for confirmation of command execution. @@ -354,19 +410,37 @@ filter Remove-GitHubAssignee GitHub.Issue .EXAMPLE - Remove-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees + $assignees = @('octocat') + Remove-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Assignee $assignee - Removes the available assignees for issues from the Microsoft\PowerShellForGitHub project. + Removes the specified usernames from the assignee list for Issue #1 in the Microsoft\PowerShellForGitHub project. .EXAMPLE - Remove-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees -Confirm:$false + $assignees = @('octocat') + $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub + $repo | Remove-GitHubAssignee -Issue 1 -Assignee $assignee - Removes the available assignees for issues from the Microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified. + Removes the specified usernames from the assignee list for Issue #1 in the Microsoft\PowerShellForGitHub project. + Will not prompt for confirmation because -Confirm:$false was specified .EXAMPLE - Remove-GithubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees -Force + $assignees = @('octocat') + Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub | + Get-GitHubIssue -Issue 1 | + Remove-GitHubAssignee -Assignee $assignee - Removes the available assignees for issues from the Microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Force was specified. + Removes the specified usernames from the assignee list for Issue #1 in the Microsoft\PowerShellForGitHub project. + Will not prompt for confirmation because -Force was specified + + .EXAMPLE + $octocat = Get-GitHubUser -UserName 'octocat' + $octocat | Remove-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 + + Removes the specified usernames from the assignee list for Issue #1 in the Microsoft\PowerShellForGitHub project. + + .NOTES + Only users with push access can remove assignees from an issue. + Assignees are silently ignored otherwise. #> [CmdletBinding( SupportsShouldProcess, @@ -391,13 +465,13 @@ filter Remove-GitHubAssignee [Parameter( Mandatory, ValueFromPipelineByPropertyName)] - [Alias('IssueId')] + [Alias('IssueNumber')] [int64] $Issue, [Parameter( Mandatory, - ValueFromPipeline, ValueFromPipelineByPropertyName)] + [ValidateNotNullOrEmpty()] [Alias('UserName')] [string[]] $Assignee, @@ -408,42 +482,58 @@ filter Remove-GitHubAssignee [switch] $NoStatus ) - Write-InvocationLog - - $elements = Resolve-RepositoryElements - $OwnerName = $elements.ownerName - $RepositoryName = $elements.repositoryName - - $telemetryProperties = @{ - 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) - 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) - 'AssigneeCount' = $Assignee.Count - 'Issue' = (Get-PiiSafeString -PlainText $Issue) - } - - $hashBody = @{ - 'assignees' = $Assignee + begin + { + $userNames = @() } - if ($Force -and (-not $Confirm)) + process { - $ConfirmPreference = 'None' + foreach ($name in $Assignee) + { + $userNames += $name + } } - if ($PSCmdlet.ShouldProcess($Assignee -join ', ', "Remove assignee(s)")) + end { - $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/assignees" - 'Body' = (ConvertTo-Json -InputObject $hashBody) - 'Method' = 'Delete' - 'Description' = "Removing assignees from issue $Issue for $RepositoryName" - 'AccessToken' = $AccessToken - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + Write-InvocationLog + + $elements = Resolve-RepositoryElements + $OwnerName = $elements.ownerName + $RepositoryName = $elements.repositoryName + + $telemetryProperties = @{ + 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) + 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) + 'AssigneeCount' = $Assignee.Count + 'Issue' = (Get-PiiSafeString -PlainText $Issue) } - return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) + $hashBody = @{ + 'assignees' = $userNames + } + + if ($Force -and (-not $Confirm)) + { + $ConfirmPreference = 'None' + } + + if ($PSCmdlet.ShouldProcess($userNames -join ', ', "Remove assignee(s)")) + { + $params = @{ + 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/assignees" + 'Body' = (ConvertTo-Json -InputObject $hashBody) + 'Method' = 'Delete' + 'Description' = "Removing assignees from issue $Issue for $RepositoryName" + 'AccessToken' = $AccessToken + 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + } + + return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) + } } } diff --git a/Tests/GitHubAssignees.tests.ps1 b/Tests/GitHubAssignees.tests.ps1 index 25f74af3..d9eeb61c 100644 --- a/Tests/GitHubAssignees.tests.ps1 +++ b/Tests/GitHubAssignees.tests.ps1 @@ -17,131 +17,239 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { - Describe 'Getting a valid assignee' { + Describe 'Getting an Assignee' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - $issue = New-GitHubIssue -Uri $repo.RepositoryUrl -Title "Test issue" } AfterAll { - Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + $repo | Remove-GitHubRepository -Confirm:$false } - Context 'For getting a valid assignee' { - $assigneeList = @(Get-GitHubAssignee -Uri $repo.RepositoryUrl) + Context 'For getting assignees in a repository via parameters' { + $assigneeList = @(Get-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name) It 'Should have returned the one assignee' { $assigneeList.Count | Should -Be 1 } - $assigneeUserName = $assigneeList[0].login - - It 'Should have returned an assignee with a login'{ - $assigneeUserName | Should -Not -Be $null + It 'Should have the expected type' { + $assigneeList[0].PSObject.TypeNames[0] | Should -Be 'GitHub.User' } + } - $hasPermission = Test-GitHubAssignee -Uri $repo.RepositoryUrl -Assignee $assigneeUserName + Context 'For getting assignees in a repository with the repo on the pipeline' { + $assigneeList = @($repo | Get-GitHubAssignee) - It 'Should have returned an assignee with permission to be assigned to an issue'{ - $hasPermission | Should -Be $true + It 'Should have returned the one assignee' { + $assigneeList.Count | Should -Be 1 } + It 'Should have the expected type' { + $assigneeList[0].PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } } } - Describe 'Adding and removing an assignee to an issue'{ + Describe 'Testing for a valid Assignee' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - $issue = New-GitHubIssue -Uri $repo.RepositoryUrl -Title "Test issue" + $octocat = Get-GitHubUser -UserName 'octocat' + $owner = Get-GitHubUser -UserName $script:ownerName } AfterAll { - Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + $repo | Remove-GitHubRepository -Confirm:$false + } + + Context 'For testing valid owner with parameters' { + $hasPermission = Test-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name -Assignee $script:ownerName + + It 'Should consider the owner of the repo to be a valid assignee' { + $hasPermission | Should -BeTrue + } + } + + Context 'For testing valid owner with the repo on the pipeline' { + $hasPermission = $repo | Test-GitHubAssignee -Assignee $script:ownerName + + It 'Should consider the owner of the repo to be a valid assignee' { + $hasPermission | Should -BeTrue + } } - Context 'For adding an assignee to an issue'{ - $assigneeList = @(Get-GitHubAssignee -Uri $repo.RepositoryUrl) - $assignees = $assigneeList[0].UserName - $null = New-GitHubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Assignee $assignees - $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.number + Context 'For testing valid owner with a user object on the pipeline' { + $hasPermission = $owner | Test-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name - It 'Should have assigned the user to the issue' { - $issue.assignee.login | Should -Be $assigneeUserName + It 'Should consider the owner of the repo to be a valid assignee' { + $hasPermission | Should -BeTrue } + } - Remove-GitHubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Assignee $assignees -Confirm:$false - $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.number + Context 'For testing invalid owner with a user object on the pipeline' { + $hasPermission = $octocat | Test-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name - It 'Should have removed the user from issue' { - $issue.assignees.Count | Should -Be 0 + It 'Should consider the owner of the repo to be a valid assignee' { + $hasPermission | Should -BeFalse } } } - Describe 'Adding and removing an assignee to an issue via the pipeline'{ + Describe 'Adding and Removing Assignees from an Issue' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + $owner = Get-GitHubUser -UserName $script:ownerName } - BeforeEach { - $issue = New-GitHubIssue -Uri $repo.RepositoryUrl -Title "Test issue" + AfterAll { + $repo | Remove-GitHubRepository -Confirm:$false } - AfterAll { - Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + Context 'Adding and removing an assignee via parameters' { + $issue = $repo | New-GitHubIssue -Title "Test issue" + It 'Should have no assignees when created' { + $issue.assignee.login | Should -BeNullOrEmpty + $issue.assignees | Should -BeNullOrEmpty + } + + $updatedIssue = New-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number -Assignee $owner.login + It 'Should have returned the same issue' { + $updatedIssue.number | Should -Be $issue.number + } + + It 'Should have added the requested Assignee to the issue' { + $updatedIssue.assignees.Count | Should -Be 1 + $updatedIssue.assignee.login | Should -Be $owner.login + $updatedIssue.assignees[0].login | Should -Be $owner.login + } + + It 'Should be of the expected type' { + $updatedIssue.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + } + + $updatedIssue = Remove-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number -Assignee $owner.login -Confirm:$false + It 'Should have returned the same issue' { + $updatedIssue.number | Should -Be $issue.number + } + + It 'Should have added the requested Assignee to the issue' { + $updatedIssue.assignee.login | Should -BeNullOrEmpty + $updatedIssue.assignees | Should -BeNullOrEmpty + } + + It 'Should be of the expected type' { + $updatedIssue.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + } } - Context 'For adding an assignee to an issue - pipe in the repo'{ - $assigneeList = @($repo | Get-GitHubAssignee) - $assignees = $assigneeList[0].UserName - $null = $repo | New-GitHubAssignee -Issue $issue.IssueNumber -Assignee $assignees - $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.number + Context 'Adding an assignee with the repo on the pipeline' { + $issue = $repo | New-GitHubIssue -Title "Test issue" + It 'Should have no assignees when created' { + $issue.assignee.login | Should -BeNullOrEmpty + $issue.assignees | Should -BeNullOrEmpty + } + + $updatedIssue = $repo | New-GitHubAssignee -Issue $issue.number -Assignee $owner.login + It 'Should have returned the same issue' { + $updatedIssue.number | Should -Be $issue.number + } + + It 'Should have added the requested Assignee to the issue' { + $updatedIssue.assignees.Count | Should -Be 1 + $updatedIssue.assignee.login | Should -Be $owner.login + $updatedIssue.assignees[0].login | Should -Be $owner.login + } + + It 'Should be of the expected type' { + $updatedIssue.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + } - It 'Should have assigned the user to the issue' { - $issue.assignee.UserName | Should -Be $assigneeUserName + $updatedIssue = $repo | Remove-GitHubAssignee -Issue $issue.number -Assignee $owner.login -Force -Confirm:$false + It 'Should have returned the same issue' { + $updatedIssue.number | Should -Be $issue.number } - $repo | Remove-GitHubAssignee -Issue $issue.IssueNumber -Assignee $assignees -Confirm:$false - $issue = $repo | Get-GitHubIssue -Issue $issue.IssueNumber + It 'Should have added the requested Assignee to the issue' { + $updatedIssue.assignee.login | Should -BeNullOrEmpty + $updatedIssue.assignees | Should -BeNullOrEmpty + } - It 'Should have removed the user from issue' { - $issue.assignees.Count | Should -Be 0 + It 'Should be of the expected type' { + $updatedIssue.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' } } - Context 'For adding an assignee to an issue - pipe in the issue'{ - $assigneeList = @(Get-GitHubAssignee -Uri $repo.RepositoryUrl) - $assignees = $assigneeList[0].UserName - $null = $issue | New-GitHubAssignee -Assignee $assignees - $issue = $issue | Get-GitHubIssue + Context 'Adding an assignee with the issue on the pipeline' { + $issue = $repo | New-GitHubIssue -Title "Test issue" + It 'Should have no assignees when created' { + $issue.assignee.login | Should -BeNullOrEmpty + $issue.assignees | Should -BeNullOrEmpty + } - It 'Should have assigned the user to the issue' { - $issue.assignee.UserName | Should -Be $assigneeUserName + $updatedIssue = $issue | New-GitHubAssignee -Assignee $owner.login + It 'Should have returned the same issue' { + $updatedIssue.number | Should -Be $issue.number } - $issue | Remove-GitHubAssignee -Assignee $assignees -Confirm:$false - $issue = $issue | Get-GitHubIssue + It 'Should have added the requested Assignee to the issue' { + $updatedIssue.assignees.Count | Should -Be 1 + $updatedIssue.assignee.login | Should -Be $owner.login + $updatedIssue.assignees[0].login | Should -Be $owner.login + } - It 'Should have removed the user from issue' { - $issue.assignees.Count | Should -Be 0 + It 'Should be of the expected type' { + $updatedIssue.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + } + + $updatedIssue = $issue | Remove-GitHubAssignee -Assignee $owner.login -Force + It 'Should have returned the same issue' { + $updatedIssue.number | Should -Be $issue.number + } + + It 'Should have added the requested Assignee to the issue' { + $updatedIssue.assignee.login | Should -BeNullOrEmpty + $updatedIssue.assignees | Should -BeNullOrEmpty + } + + It 'Should be of the expected type' { + $updatedIssue.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' } } - Context 'For adding an assignee to an issue - pipe in the assignee'{ - $assigneeList = @(Get-GitHubAssignee -Uri $repo.RepositoryUrl) - $assignees = $assigneeList[0].UserName - $null = $assignees | New-GitHubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number - $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.IssueNumber + Context 'Adding an assignee with the assignee user object on the pipeline' { + $issue = $repo | New-GitHubIssue -Title "Test issue" + It 'Should have no assignees when created' { + $issue.assignee.login | Should -BeNullOrEmpty + $issue.assignees | Should -BeNullOrEmpty + } - It 'Should have assigned the user to the issue' { - $issue.assignee.UserName | Should -Be $assigneeUserName + $updatedIssue = $owner | New-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number + It 'Should have returned the same issue' { + $updatedIssue.number | Should -Be $issue.number } - $assignees | Remove-GitHubAssignee -Uri $repo.RepositoryUrl -Issue $issue.number -Confirm:$false - $issue = Get-GitHubIssue -Uri $repo.RepositoryUrl -Issue $issue.IssueNumber + It 'Should have added the requested Assignee to the issue' { + $updatedIssue.assignees.Count | Should -Be 1 + $updatedIssue.assignee.login | Should -Be $owner.login + $updatedIssue.assignees[0].login | Should -Be $owner.login + } + + It 'Should be of the expected type' { + $updatedIssue.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + } + + $updatedIssue = $owner | Remove-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number -Force + It 'Should have returned the same issue' { + $updatedIssue.number | Should -Be $issue.number + } + + It 'Should have added the requested Assignee to the issue' { + $updatedIssue.assignee.login | Should -BeNullOrEmpty + $updatedIssue.assignees | Should -BeNullOrEmpty + } - It 'Should have removed the user from issue' { - $issue.assignees.Count | Should -Be 0 + It 'Should be of the expected type' { + $updatedIssue.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' } } } From 667132ae5a722eed2f27341eabb58c59933f171c Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 15 Jun 2020 13:47:07 -0700 Subject: [PATCH 61/80] Fixing some casing in the CBH --- GitHubAssignees.ps1 | 26 +++++++++++++------------- GitHubComments.ps1 | 12 ++++++------ GitHubEvents.ps1 | 2 +- GitHubIssues.ps1 | 4 ++-- GitHubLabels.ps1 | 4 ++-- GitHubMilestones.ps1 | 14 +++++++------- GitHubMiscellaneous.ps1 | 4 ++-- GitHubProjects.ps1 | 14 +++++++------- GitHubRepositoryForks.ps1 | 2 +- GitHubRepositoryTraffic.ps1 | 8 ++++---- USAGE.md | 2 +- 11 files changed, 46 insertions(+), 46 deletions(-) diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index 6e47d229..b5845d2d 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -38,13 +38,13 @@ filter Get-GitHubAssignee .EXAMPLE Get-GitHubAssigneeList -OwnerName microsoft -RepositoryName PowerShellForGitHub - Lists the available assignees for issues from the Microsoft\PowerShellForGitHub project. + Lists the available assignees for issues from the microsoft\PowerShellForGitHub project. .EXAMPLE $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub $repo | Get-GitHubAssigneeList - Lists the available assignees for issues from the Microsoft\PowerShellForGitHub project. + Lists the available assignees for issues from the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -135,19 +135,19 @@ filter Test-GitHubAssignee .EXAMPLE Test-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee "LoginID123" - Checks if a user has permission to be assigned to an issue from the Microsoft\PowerShellForGitHub project. + Checks if a user has permission to be assigned to an issue from the microsoft\PowerShellForGitHub project. .EXAMPLE $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub $repo | Test-GitHubAssignee -Assignee 'octocat' - Checks if a user has permission to be assigned to an issue from the Microsoft\PowerShellForGitHub project. + Checks if a user has permission to be assigned to an issue from the microsoft\PowerShellForGitHub project. .EXAMPLE $octocat = Get-GitHubUser -UserName 'octocat' $repo = $octocat | Test-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub - Checks if a user has permission to be assigned to an issue from the Microsoft\PowerShellForGitHub project. + Checks if a user has permission to be assigned to an issue from the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -257,14 +257,14 @@ function New-GitHubAssignee $assignees = @('octocat') New-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Assignee $assignee - Additionally assigns the usernames in $assignee to Issue #1 from the Microsoft\PowerShellForGitHub project. + Additionally assigns the usernames in $assignee to Issue #1 from the microsoft\PowerShellForGitHub project. .EXAMPLE $assignees = @('octocat') $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub $repo | New-GitHubAssignee -Issue 1 -Assignee $assignee - Additionally assigns the usernames in $assignee to Issue #1 from the Microsoft\PowerShellForGitHub project. + Additionally assigns the usernames in $assignee to Issue #1 from the microsoft\PowerShellForGitHub project. .EXAMPLE $assignees = @('octocat') @@ -272,13 +272,13 @@ function New-GitHubAssignee Get-GitHubIssue -Issue 1 | New-GitHubAssignee -Assignee $assignee - Additionally assigns the usernames in $assignee to Issue #1 from the Microsoft\PowerShellForGitHub project. + Additionally assigns the usernames in $assignee to Issue #1 from the microsoft\PowerShellForGitHub project. .EXAMPLE $octocat = Get-GitHubUser -UserName 'octocat' $octocat | New-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 - Additionally assigns the user 'octocat' to Issue #1 from the Microsoft\PowerShellForGitHub project. + Additionally assigns the user 'octocat' to Issue #1 from the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -413,14 +413,14 @@ function Remove-GitHubAssignee $assignees = @('octocat') Remove-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Assignee $assignee - Removes the specified usernames from the assignee list for Issue #1 in the Microsoft\PowerShellForGitHub project. + Removes the specified usernames from the assignee list for Issue #1 in the microsoft\PowerShellForGitHub project. .EXAMPLE $assignees = @('octocat') $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub $repo | Remove-GitHubAssignee -Issue 1 -Assignee $assignee - Removes the specified usernames from the assignee list for Issue #1 in the Microsoft\PowerShellForGitHub project. + Removes the specified usernames from the assignee list for Issue #1 in the microsoft\PowerShellForGitHub project. Will not prompt for confirmation because -Confirm:$false was specified .EXAMPLE @@ -429,14 +429,14 @@ function Remove-GitHubAssignee Get-GitHubIssue -Issue 1 | Remove-GitHubAssignee -Assignee $assignee - Removes the specified usernames from the assignee list for Issue #1 in the Microsoft\PowerShellForGitHub project. + Removes the specified usernames from the assignee list for Issue #1 in the microsoft\PowerShellForGitHub project. Will not prompt for confirmation because -Force was specified .EXAMPLE $octocat = Get-GitHubUser -UserName 'octocat' $octocat | Remove-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 - Removes the specified usernames from the assignee list for Issue #1 in the Microsoft\PowerShellForGitHub project. + Removes the specified usernames from the assignee list for Issue #1 in the microsoft\PowerShellForGitHub project. .NOTES Only users with push access can remove assignees from an issue. diff --git a/GitHubComments.ps1 b/GitHubComments.ps1 index ecd0b1e1..37068a53 100644 --- a/GitHubComments.ps1 +++ b/GitHubComments.ps1 @@ -67,7 +67,7 @@ filter Get-GitHubComment .EXAMPLE Get-GitHubComment-OwnerName microsoft -RepositoryName PowerShellForGitHub - Get the comments for the Microsoft\PowerShellForGitHub project. + Get the comments for the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -254,7 +254,7 @@ filter New-GitHubComment .EXAMPLE New-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Body "Testing this API" - Creates a new GitHub comment in an issue for the Microsoft\PowerShellForGitHub project. + Creates a new GitHub comment in an issue for the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -375,7 +375,7 @@ filter Set-GitHubComment .EXAMPLE Set-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Body "Testing this API" - Update an existing comment in an issue for the Microsoft\PowerShellForGitHub project. + Update an existing comment in an issue for the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -485,17 +485,17 @@ filter Remove-GitHubComment .EXAMPLE Remove-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 - Deletes a GitHub comment from the Microsoft\PowerShellForGitHub project. + Deletes a GitHub comment from the microsoft\PowerShellForGitHub project. .EXAMPLE Remove-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Confirm:$false - Deletes a Github comment from the Microsoft\PowerShellForGitHub project without prompting confirmation. + Deletes a Github comment from the microsoft\PowerShellForGitHub project without prompting confirmation. .EXAMPLE Remove-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Force - Deletes a GitHub comment from the Microsoft\PowerShellForGitHub project without prompting confirmation. + Deletes a GitHub comment from the microsoft\PowerShellForGitHub project without prompting confirmation. #> [CmdletBinding( SupportsShouldProcess, diff --git a/GitHubEvents.ps1 b/GitHubEvents.ps1 index 214646bd..16e7ddc0 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -50,7 +50,7 @@ filter Get-GitHubEvent .EXAMPLE Get-GitHubEvent -OwnerName microsoft -RepositoryName PowerShellForGitHub - Get the events for the Microsoft\PowerShellForGitHub project. + Get the events for the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index 110b583c..03a09720 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -117,12 +117,12 @@ filter Get-GitHubIssue .EXAMPLE Get-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -State Open - Gets all the currently open issues in the Microsoft\PowerShellForGitHub repository. + Gets all the currently open issues in the microsoft\PowerShellForGitHub repository. .EXAMPLE Get-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -State All -Assignee Octocat - Gets every issue in the Microsoft\PowerShellForGitHub repository that is assigned to Octocat. + Gets every issue in the microsoft\PowerShellForGitHub repository that is assigned to Octocat. #> [CmdletBinding( SupportsShouldProcess, diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index ccc3d168..c3104768 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -57,12 +57,12 @@ filter Get-GitHubLabel .EXAMPLE Get-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub - Gets the information for every label from the Microsoft\PowerShellForGitHub project. + Gets the information for every label from the microsoft\PowerShellForGitHub project. .EXAMPLE Get-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel - Gets the information for the label named "TestLabel" from the Microsoft\PowerShellForGitHub + Gets the information for the label named "TestLabel" from the microsoft\PowerShellForGitHub project. .NOTES diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index f043227e..77d66098 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -60,11 +60,11 @@ filter Get-GitHubMilestone .EXAMPLE Get-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub - Get the milestones for the Microsoft\PowerShellForGitHub project. + Get the milestones for the microsoft\PowerShellForGitHub project. .EXAMPLE Get-GitHubMilestone -Uri 'https://github.com/PowerShell/PowerShellForGitHub' -Milestone 1 - Get milestone number 1 for the Microsoft\PowerShellForGitHub project. + Get milestone number 1 for the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -240,7 +240,7 @@ filter New-GitHubMilestone .EXAMPLE New-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Title "Testing this API" - Creates a new GitHub milestone for the Microsoft\PowerShellForGitHub project. + Creates a new GitHub milestone for the microsoft\PowerShellForGitHub project. .NOTES For more information on how GitHub handles the dates specified in DueOn, please refer to @@ -402,7 +402,7 @@ filter Set-GitHubMilestone .EXAMPLE Set-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Title "Testing this API" - Update an existing milestone for the Microsoft\PowerShellForGitHub project. + Update an existing milestone for the microsoft\PowerShellForGitHub project. .NOTES For more information on how GitHub handles the dates specified in DueOn, please refer to @@ -556,18 +556,18 @@ filter Remove-GitHubMilestone .EXAMPLE Remove-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1 - Deletes a GitHub milestone from the Microsoft\PowerShellForGitHub project. + Deletes a GitHub milestone from the microsoft\PowerShellForGitHub project. .EXAMPLE Remove-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Confirm:$false - Deletes a Github milestone from the Microsoft\PowerShellForGitHub project. Will not prompt + Deletes a Github milestone from the microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified. .EXAMPLE Remove-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Force - Deletes a Github milestone from the Microsoft\PowerShellForGitHub project. Will not prompt + Deletes a Github milestone from the microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Force was specified. #> [CmdletBinding( diff --git a/GitHubMiscellaneous.ps1 b/GitHubMiscellaneous.ps1 index 0229f203..5dee23fc 100644 --- a/GitHubMiscellaneous.ps1 +++ b/GitHubMiscellaneous.ps1 @@ -245,7 +245,7 @@ filter Get-GitHubLicense .EXAMPLE Get-GitHubLicense -OwnerName microsoft -RepositoryName PowerShellForGitHub - Gets the content of the license file for the Microsoft\PowerShellForGitHub repository. + Gets the content of the license file for the microsoft\PowerShellForGitHub repository. It may be necessary to convert the content of the file. Check the 'encoding' property of the result to know how 'content' is encoded. As an example, to convert from Base64, do the following: @@ -435,7 +435,7 @@ filter Get-GitHubCodeOfConduct .EXAMPLE Get-GitHubCodeOfConduct -OwnerName microsoft -RepositoryName PowerShellForGitHub - Gets the content of the Code of Conduct file for the Microsoft\PowerShellForGitHub repository + Gets the content of the Code of Conduct file for the microsoft\PowerShellForGitHub repository if one is detected. It may be necessary to convert the content of the file. Check the 'encoding' property of diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index acb76f47..7fd284e5 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -56,7 +56,7 @@ filter Get-GitHubProject .EXAMPLE Get-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub - Get the projects for the Microsoft\PowerShellForGitHub repository. + Get the projects for the microsoft\PowerShellForGitHub repository. .EXAMPLE Get-GitHubProject -OrganizationName Microsoft @@ -66,7 +66,7 @@ filter Get-GitHubProject .EXAMPLE Get-GitHubProject -Uri https://github.com/Microsoft/PowerShellForGitHub - Get the projects for the Microsoft\PowerShellForGitHub repository using the Uri. + Get the projects for the microsoft\PowerShellForGitHub repository using the Uri. .EXAMPLE Get-GitHubProject -UserName GitHubUser @@ -76,7 +76,7 @@ filter Get-GitHubProject .EXAMPLE Get-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub -State Closed - Get closed projects from the Microsoft\PowerShellForGitHub repo. + Get closed projects from the microsoft\PowerShellForGitHub repo. .EXAMPLE Get-GitHubProject -Project 4378613 @@ -245,7 +245,7 @@ filter New-GitHubProject .EXAMPLE New-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub -Name TestProject - Creates a project called 'TestProject' for the Microsoft\PowerShellForGitHub repository. + Creates a project called 'TestProject' for the microsoft\PowerShellForGitHub repository. .EXAMPLE New-GitHubProject -OrganizationName Microsoft -Name TestProject -Description 'This is just a test project' @@ -255,7 +255,7 @@ filter New-GitHubProject .EXAMPLE New-GitHubProject -Uri https://github.com/Microsoft/PowerShellForGitHub -Name TestProject - Create a project for the Microsoft\PowerShellForGitHub repository using the Uri called 'TestProject'. + Create a project for the microsoft\PowerShellForGitHub repository using the Uri called 'TestProject'. .EXAMPLE New-GitHubProject -UserProject -Name 'TestProject' @@ -406,7 +406,7 @@ filter Set-GitHubProject $project = Get-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub | Where-Object Name -eq 'TestProject' Set-GitHubProject -Project $project.id -State Closed - Get the ID for the 'TestProject' project for the Microsoft\PowerShellForGitHub + Get the ID for the 'TestProject' project for the microsoft\PowerShellForGitHub repository and set state to closed. #> [CmdletBinding(SupportsShouldProcess)] @@ -526,7 +526,7 @@ filter Remove-GitHubProject $project = Get-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub | Where-Object Name -eq 'TestProject' Remove-GitHubProject -Project $project.id - Get the ID for the 'TestProject' project for the Microsoft\PowerShellForGitHub + Get the ID for the 'TestProject' project for the microsoft\PowerShellForGitHub repository and then remove the project. #> [CmdletBinding( diff --git a/GitHubRepositoryForks.ps1 b/GitHubRepositoryForks.ps1 index 2829e1c6..b2718074 100644 --- a/GitHubRepositoryForks.ps1 +++ b/GitHubRepositoryForks.ps1 @@ -44,7 +44,7 @@ filter Get-GitHubRepositoryFork .EXAMPLE Get-GitHubRepositoryFork -OwnerName microsoft -RepositoryName PowerShellForGitHub - Gets all of the forks for the Microsoft\PowerShellForGitHub repository. + Gets all of the forks for the microsoft\PowerShellForGitHub repository. #> [CmdletBinding( SupportsShouldProcess, diff --git a/GitHubRepositoryTraffic.ps1 b/GitHubRepositoryTraffic.ps1 index 833f0717..7e703514 100644 --- a/GitHubRepositoryTraffic.ps1 +++ b/GitHubRepositoryTraffic.ps1 @@ -50,7 +50,7 @@ filter Get-GitHubReferrerTraffic .EXAMPLE Get-GitHubReferrerTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub - Get the top 10 referrers over the last 14 days from the Microsoft\PowerShellForGitHub project. + Get the top 10 referrers over the last 14 days from the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -143,7 +143,7 @@ filter Get-GitHubPathTraffic .EXAMPLE Get-GitHubPathTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub - Get the top 10 popular contents over the last 14 days from the Microsoft\PowerShellForGitHub project. + Get the top 10 popular contents over the last 14 days from the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -240,7 +240,7 @@ filter Get-GitHubViewTraffic .EXAMPLE Get-GitHubViewTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub - Get the total number of views and breakdown per day or week for the last 14 days from the Microsoft\PowerShellForGitHub project. + Get the total number of views and breakdown per day or week for the last 14 days from the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -341,7 +341,7 @@ filter Get-GitHubCloneTraffic .EXAMPLE Get-GitHubCloneTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub - Get the total number of clones and breakdown per day or week for the last 14 days from the Microsoft\PowerShellForGitHub project. + Get the total number of clones and breakdown per day or week for the last 14 days from the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, diff --git a/USAGE.md b/USAGE.md index a123a91f..e17c5edb 100644 --- a/USAGE.md +++ b/USAGE.md @@ -204,7 +204,7 @@ $issueCounts | Sort-Object -Property Count -Descending #### Querying Pull Requests ```powershell -# Getting all of the pull requests from the Microsoft\PowerShellForGitHub repository +# Getting all of the pull requests from the microsoft\PowerShellForGitHub repository $issues = Get-GitHubIssue -OwnerName microsoft -RepositoryName 'PowerShellForGitHub' ``` From ccd1b7ac9457f10f77c097f020ce379d8668d684 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 15 Jun 2020 13:59:58 -0700 Subject: [PATCH 62/80] Remove unnecessary TypeName parameter passing --- GitHubPullRequests.ps1 | 6 ++---- GitHubReleases.ps1 | 3 +-- GitHubRepositories.ps1 | 12 ++++-------- GitHubRepositoryForks.ps1 | 6 ++---- Tests/GitHubRepositories.tests.ps1 | 2 +- 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index c0fb5415..bdd097d5 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -173,8 +173,7 @@ filter Get-GitHubPullRequest 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethodMultipleResult @params | - Add-GitHubPullRequestAdditionalProperties -TypeName $script:GitHubPullRequestTypeName) + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubPullRequestAdditionalProperties) } filter New-GitHubPullRequest @@ -406,8 +405,7 @@ filter New-GitHubPullRequest $restParams['AcceptHeader'] = $acceptHeader } - return (Invoke-GHRestMethod @restParams | - Add-GitHubPullRequestAdditionalProperties -TypeName $script:GitHubPullRequestTypeName) + return (Invoke-GHRestMethod @restParams | Add-GitHubPullRequestAdditionalProperties) } filter Add-GitHubPullRequestAdditionalProperties diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index 04b52641..1c3b722c 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -214,8 +214,7 @@ filter Get-GitHubRelease 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethodMultipleResult @params | - Add-GitHubReleaseAdditionalProperties -TypeName $script:GitHubReleaseTypeName) + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubReleaseAdditionalProperties) } diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 061b0d62..4a79ba08 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -209,8 +209,7 @@ filter New-GitHubRepository 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethod @params | - Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) + return (Invoke-GHRestMethod @params | Add-GitHubRepositoryAdditionalProperties) } filter Remove-GitHubRepository @@ -651,8 +650,7 @@ filter Get-GitHubRepository 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethodMultipleResult @params | - Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubRepositoryAdditionalProperties) } filter Rename-GitHubRepository @@ -990,8 +988,7 @@ filter Update-GitHubRepository 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethod @params | - Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) + return (Invoke-GHRestMethod @params | Add-GitHubRepositoryAdditionalProperties) } filter Get-GitHubRepositoryTopic @@ -1783,8 +1780,7 @@ filter Move-GitHubRepositoryOwnership 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethod @params | - Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) + return (Invoke-GHRestMethod @params | Add-GitHubRepositoryAdditionalProperties) } filter Add-GitHubRepositoryAdditionalProperties diff --git a/GitHubRepositoryForks.ps1 b/GitHubRepositoryForks.ps1 index b2718074..d0327904 100644 --- a/GitHubRepositoryForks.ps1 +++ b/GitHubRepositoryForks.ps1 @@ -99,8 +99,7 @@ filter Get-GitHubRepositoryFork 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethodMultipleResult @params | - Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubRepositoryAdditionalProperties) } filter New-GitHubRepositoryFork @@ -209,8 +208,7 @@ filter New-GitHubRepositoryFork 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - $result = (Invoke-GHRestMethod @params | - Add-GitHubRepositoryAdditionalProperties -TypeName $script:GitHubRepositoryTypeName) + $result = (Invoke-GHRestMethod @params | Add-GitHubRepositoryAdditionalProperties) Write-Log -Message 'Forking a repository happens asynchronously. You may have to wait a short period of time (up to 5 minutes) before you can access the git objects.' -Level Warning return $result diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 5d31cd5f..4717aa49 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -762,7 +762,7 @@ try It 'Should return expected number of contributors' { $contributors.Count | Should -Be 1 - $contributors[0].PSObject.TypeName = 'GitHub.User' + $contributors[0].PSObject.TypeNames[0] = 'GitHub.User' } } From c09a318c982dbf5ac27aa08a07926c14d4561284 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 15 Jun 2020 14:43:09 -0700 Subject: [PATCH 63/80] Renaming GitHubComments.* -> GitHubIssueComments.* --- GitHubCore.ps1 | 2 +- GitHubComments.ps1 => GitHubIssueComments.ps1 | 47 +++++++++++++++---- ...ests.ps1 => GitHubIssueComments.tests.ps1} | 0 3 files changed, 38 insertions(+), 11 deletions(-) rename GitHubComments.ps1 => GitHubIssueComments.ps1 (93%) rename Tests/{GitHubComments.tests.ps1 => GitHubIssueComments.tests.ps1} (100%) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 18c35893..28292f75 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -13,7 +13,7 @@ nebulaAcceptHeader = 'application/vnd.github.nebula-preview+json' sailerVAcceptHeader = 'application/vnd.github.sailer-v-preview+json' scarletWitchAcceptHeader = 'application/vnd.github.scarlet-witch-preview+json' - squirrelAcceptHeader = 'application/vnd.github.squirrel-girl-preview' + squirrelGirlAcceptHeader = 'application/vnd.github.squirrel-girl-preview' starfoxAcceptHeader = 'application/vnd.github.starfox-preview+json' symmetraAcceptHeader = 'application/vnd.github.symmetra-preview+json' }.GetEnumerator() | ForEach-Object { diff --git a/GitHubComments.ps1 b/GitHubIssueComments.ps1 similarity index 93% rename from GitHubComments.ps1 rename to GitHubIssueComments.ps1 index 37068a53..b94b338a 100644 --- a/GitHubComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -65,9 +65,36 @@ filter Get-GitHubComment GitHub.Comment .EXAMPLE - Get-GitHubComment-OwnerName microsoft -RepositoryName PowerShellForGitHub + Get-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub - Get the comments for the microsoft\PowerShellForGitHub project. + Get all of the Issue comments for the microsoft\PowerShellForGitHub project. + + .EXAMPLE + $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub + $repo | Get-GitHubComment -Since ([DateTime]::Now).AddDays(-1) + + Get all of the Issue comments for the microsoft\PowerShellForGitHub project since yesterday. + + .EXAMPLE + $issue = $repo | Get-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 + + Get the comments Issue #1 in the microsoft\PowerShellForGitHub project. + + .EXAMPLE + $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub + $issue = $repo | Get-GitHubIssue -Issue 1 + $issue | Get-GitHubComment + + Get the comments Issue #1 in the microsoft\PowerShellForGitHub project. + + .EXAMPLE + $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub + $issue = $repo | Get-GitHubIssue -Issue 1 + $comments = $issue | Get-GitHubComment + $comment[0] | Get-GitHubComment + + Get the most recent comment on Issue #1 in the microsoft\PowerShellForGitHub project by + passing it in via the pipeline. #> [CmdletBinding( SupportsShouldProcess, @@ -91,29 +118,29 @@ filter Get-GitHubComment [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='CommentUri')] [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='CommentElements')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='CommentUri')] [Alias('CommentId')] [string] $Comment, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueElements')] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] [Alias('IssueNumber')] [int64] $Issue, - [Parameter(ParameterSetName='RepositoryUri')] [Parameter(ParameterSetName='RepositoryElements')] + [Parameter(ParameterSetName='RepositoryUri')] [Parameter(ParameterSetName='IssueElements')] [Parameter(ParameterSetName='IssueUri')] [DateTime] $Since, - [Parameter(ParameterSetName='RepositoryUri')] [Parameter(ParameterSetName='RepositoryElements')] + [Parameter(ParameterSetName='RepositoryUri')] [ValidateSet('Created', 'Updated')] [string] $Sort, - [Parameter(ParameterSetName='RepositoryUri')] [Parameter(ParameterSetName='RepositoryElements')] + [Parameter(ParameterSetName='RepositoryUri')] [ValidateSet('Ascending', 'Descending')] [string] $Direction, @@ -194,7 +221,7 @@ filter Get-GitHubComment 'UriFragment' = $uriFragment 'Description' = $description 'AccessToken' = $AccessToken - 'AcceptHeader' = (Get-MediaAcceptHeader -MediaType $MediaType -AsJson -AcceptHeader $squirrelAcceptHeader) + 'AcceptHeader' = (Get-MediaAcceptHeader -MediaType $MediaType -AsJson -AcceptHeader $squirrelGirlAcceptHeader) 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) @@ -315,7 +342,7 @@ filter New-GitHubComment 'Method' = 'Post' 'Description' = "Creating comment under issue $Issue for $RepositoryName" 'AccessToken' = $AccessToken - 'AcceptHeader' = (Get-MediaAcceptHeader -MediaType $MediaType -AsJson -AcceptHeader $squirrelAcceptHeader) + 'AcceptHeader' = (Get-MediaAcceptHeader -MediaType $MediaType -AsJson -AcceptHeader $squirrelGirlAcceptHeader) 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) @@ -436,7 +463,7 @@ filter Set-GitHubComment 'Method' = 'Patch' 'Description' = "Update comment $Comment for $RepositoryName" 'AccessToken' = $AccessToken - 'AcceptHeader' = (Get-MediaAcceptHeader -MediaType $MediaType -AsJson -AcceptHeader $squirrelAcceptHeader) + 'AcceptHeader' = (Get-MediaAcceptHeader -MediaType $MediaType -AsJson -AcceptHeader $squirrelGirlAcceptHeader) 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) diff --git a/Tests/GitHubComments.tests.ps1 b/Tests/GitHubIssueComments.tests.ps1 similarity index 100% rename from Tests/GitHubComments.tests.ps1 rename to Tests/GitHubIssueComments.tests.ps1 From 9305a554ad6b7da44ebecef09042de77bd1b9513 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 15 Jun 2020 15:17:45 -0700 Subject: [PATCH 64/80] Got Issue comment tests working --- GitHubIssueComments.ps1 | 81 ++++++----- PowerShellForGitHub.psd1 | 15 +- Tests/GitHubIssueComments.tests.ps1 | 218 +++++++++++++++++++++++----- USAGE.md | 41 +++--- 4 files changed, 259 insertions(+), 96 deletions(-) diff --git a/GitHubIssueComments.ps1 b/GitHubIssueComments.ps1 index b94b338a..4ab9eff5 100644 --- a/GitHubIssueComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -3,15 +3,16 @@ @{ GitHubCommentTypeName = 'GitHub.Comment' + GitHubIssueCommentTypeName = 'GitHub.IssueComment' }.GetEnumerator() | ForEach-Object { Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value } -filter Get-GitHubComment +filter Get-GitHubIssueComment { <# .DESCRIPTION - Get the comments for a given GitHub repository. + Get the Issue comments for a given GitHub repository. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -62,36 +63,36 @@ filter Get-GitHubComment If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - GitHub.Comment + GitHub.IssueComment .EXAMPLE - Get-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub + Get-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub Get all of the Issue comments for the microsoft\PowerShellForGitHub project. .EXAMPLE $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub - $repo | Get-GitHubComment -Since ([DateTime]::Now).AddDays(-1) + $repo | Get-GitHubIssueComment -Since ([DateTime]::Now).AddDays(-1) Get all of the Issue comments for the microsoft\PowerShellForGitHub project since yesterday. .EXAMPLE - $issue = $repo | Get-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 + $issue = $repo | Get-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 Get the comments Issue #1 in the microsoft\PowerShellForGitHub project. .EXAMPLE $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub $issue = $repo | Get-GitHubIssue -Issue 1 - $issue | Get-GitHubComment + $issue | Get-GitHubIssueComment Get the comments Issue #1 in the microsoft\PowerShellForGitHub project. .EXAMPLE $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub $issue = $repo | Get-GitHubIssue -Issue 1 - $comments = $issue | Get-GitHubComment - $comment[0] | Get-GitHubComment + $comments = $issue | Get-GitHubIssueComment + $comment[0] | Get-GitHubIssueComment Get the most recent comment on Issue #1 in the microsoft\PowerShellForGitHub project by passing it in via the pipeline. @@ -99,7 +100,8 @@ filter Get-GitHubComment [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='RepositoryElements')] - [OutputType({$script:GitHubCommentTypeName})] + [Alias('Get-GitHubComment')] # Aliased to avoid a breaking change after v0.14.0 + [OutputType({$script:GitHubIssueCommentTypeName})] [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='RepositoryElements')] @@ -227,14 +229,14 @@ filter Get-GitHubComment 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubCommentAdditionalProperties) + return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubIssueCommentAdditionalProperties) } -filter New-GitHubComment +filter New-GitHubIssueComment { <# .DESCRIPTION - Creates a new GitHub comment in an issue for the given repository + Creates a new GitHub comment for an issue for the given repository The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -276,17 +278,18 @@ filter New-GitHubComment If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - GitHub.Comment + GitHub.IssueComment .EXAMPLE - New-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Body "Testing this API" + New-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Body "Testing this API" - Creates a new GitHub comment in an issue for the microsoft\PowerShellForGitHub project. + Creates a new GitHub comment for an issue for the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [OutputType({$script:GitHubCommentTypeName})] + [Alias('New-GitHubComment')] # Aliased to avoid a breaking change after v0.14.0 + [OutputType({$script:GitHubIssueCommentTypeName})] [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( @@ -348,14 +351,14 @@ filter New-GitHubComment 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethod @params | Add-GitHubCommentAdditionalProperties) + return (Invoke-GHRestMethod @params | Add-GitHubIssueCommentAdditionalProperties) } -filter Set-GitHubComment +filter Set-GitHubIssueComment { <# .DESCRIPTION - Set an existing comment in an issue for the given repository + Modifies an existing comment in an issue for the given repository The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -397,17 +400,18 @@ filter Set-GitHubComment If not supplied here, the DefaultNoStatus configuration property value will be used. .OUTPUTS - GitHub.Comment + GitHub.IssueComment .EXAMPLE - Set-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Body "Testing this API" + Set-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Body "Testing this API" - Update an existing comment in an issue for the microsoft\PowerShellForGitHub project. + Updates an existing comment in an issue for the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [OutputType({$script:GitHubCommentTypeName})] + [Alias('Set-GitHubComment')] # Aliased to avoid a breaking change after v0.14.0 + [OutputType({$script:GitHubIssueCommentTypeName})] [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( @@ -469,14 +473,14 @@ filter Set-GitHubComment 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethod @params | Add-GitHubCommentAdditionalProperties) + return (Invoke-GHRestMethod @params | Add-GitHubIssueCommentAdditionalProperties) } -filter Remove-GitHubComment +filter Remove-GitHubIssueComment { <# .DESCRIPTION - Deletes a GitHub comment for the given repository + Deletes a GitHub comment from an Issue in the given repository The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -510,25 +514,27 @@ filter Remove-GitHubComment If not supplied here, the DefaultNoStatus configuration property value will be used. .EXAMPLE - Remove-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 + Remove-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 - Deletes a GitHub comment from the microsoft\PowerShellForGitHub project. + Deletes a GitHub comment from an Issue in the microsoft\PowerShellForGitHub project. .EXAMPLE - Remove-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Confirm:$false + Remove-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Confirm:$false - Deletes a Github comment from the microsoft\PowerShellForGitHub project without prompting confirmation. + Deletes a Github comment from an Issue in the microsoft\PowerShellForGitHub project without prompting confirmation. .EXAMPLE - Remove-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Force + Remove-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Force - Deletes a GitHub comment from the microsoft\PowerShellForGitHub project without prompting confirmation. + Deletes a GitHub comment from an Issue in the microsoft\PowerShellForGitHub project without prompting confirmation. #> [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements', ConfirmImpact="High")] [Alias('Delete-GitHubComment')] + [Alias('Delete-GitHubIssueComment')] + [Alias('Remove-GitHubComment')] # Aliased to avoid a breaking change after v0.14.0 [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(ParameterSetName='Elements')] @@ -590,7 +596,7 @@ filter Remove-GitHubComment } } -filter Add-GitHubCommentAdditionalProperties +filter Add-GitHubIssueCommentAdditionalProperties { <# .SYNOPSIS @@ -613,12 +619,13 @@ filter Add-GitHubCommentAdditionalProperties [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] - [string] $TypeName = $script:GitHubCommentTypeName + [string] $TypeName = $script:GitHubIssueCommentTypeName ) foreach ($item in $InputObject) { - $item.PSObject.TypeNames.Insert(0, $TypeName) + $item.PSObject.TypeNames.Insert(0, $script:GitHubCommentTypeName) # Provide a generic comment type too + $item.PSObject.TypeNames.Insert(0, $TypeName) # We want the specific type on top if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { @@ -626,6 +633,8 @@ filter Add-GitHubCommentAdditionalProperties $repositoryUrl = Join-GitHubUri @elements Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'CommentId' -Value $item.id -MemberType NoteProperty -Force + if ($null -ne $item.user) { $null = Add-GitHubUserAdditionalProperties -InputObject $item.user diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index d100478c..c7f51c82 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -24,9 +24,9 @@ 'GitHubAssignees.ps1', 'GitHubBranches.ps1', 'GitHubCore.ps1', - 'GitHubComments.ps1', 'GitHubContents.ps1', 'GitHubEvents.ps1', + 'GitHubIssueComments.ps1', 'GitHubIssues.ps1', 'GitHubLabels.ps1', 'GitHubMilestones.ps1', @@ -57,13 +57,13 @@ 'Get-GitHubAssignee', 'Get-GitHubCloneTraffic', 'Get-GitHubCodeOfConduct', - 'Get-GitHubComment', 'Get-GitHubConfiguration', 'Get-GitHubContent', 'Get-GitHubEmoji', 'Get-GitHubEvent', 'Get-GitHubGitIgnore', 'Get-GitHubIssue', + 'Get-GitHubIssueComment', 'Get-GitHubIssueTimeline', 'Get-GitHubLabel', 'Get-GitHubLicense', @@ -101,8 +101,8 @@ 'Move-GitHubProjectColumn', 'Move-GitHubRepositoryOwnership', 'New-GitHubAssignee', - 'New-GitHubComment', 'New-GitHubIssue', + 'New-GitHubIssueComment', 'New-GitHubLabel', 'New-GitHubMilestone', 'New-GitHubProject', @@ -112,7 +112,7 @@ 'New-GitHubRepository', 'New-GitHubRepositoryFork', 'Remove-GitHubAssignee', - 'Remove-GitHubComment', + 'Remove-GitHubIssueComment', 'Remove-GitHubIssueLabel', 'Remove-GitHubLabel', 'Remove-GitHubMilestone', @@ -124,8 +124,8 @@ 'Reset-GitHubConfiguration', 'Restore-GitHubConfiguration', 'Set-GitHubAuthentication', - 'Set-GitHubComment', 'Set-GitHubConfiguration', + 'Set-GitHubIssueComment', 'Set-GitHubIssueLabel', 'Set-GitHubLabel', 'Set-GitHubMilestone', @@ -146,6 +146,7 @@ AliasesToExport = @( 'Delete-GitHubComment', + 'Delete-GitHubIssueComment', 'Delete-GitHubLabel', 'Delete-GitHubMilestone', 'Delete-GitHubProject', @@ -153,6 +154,10 @@ 'Delete-GitHubProjectColumn' 'Delete-GitHubRepository', 'Get-GitHubBranch', + 'Get-GitHubComment', + 'New-GitHubComment', + 'Remove-GitHubComment', + 'Set-GitHubComment', 'Transfer-GitHubRepositoryOwnership' ) diff --git a/Tests/GitHubIssueComments.tests.ps1 b/Tests/GitHubIssueComments.tests.ps1 index 1a9348e3..d5a82873 100644 --- a/Tests/GitHubIssueComments.tests.ps1 +++ b/Tests/GitHubIssueComments.tests.ps1 @@ -27,71 +27,217 @@ try } Describe 'Creating, modifying and deleting comments' { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + $issue = $repo | New-GitHubIssue -Title $defaultIssueTitle + } - $issue = New-GitHubIssue -Uri $repo.svn_url -Title $defaultIssueTitle + AfterAll { + $repo | Remove-GitHubRepository -Confirm:$false + } - Context 'For creating a new comment' { - $newComment = New-GitHubComment -Uri $repo.svn_url -Issue $issue.number -Body $defaultCommentBody - $existingComment = Get-GitHubComment -Uri $repo.svn_url -CommentID $newComment.id + Context 'With parameters' { + $comment = New-GitHubIssueComment -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number -Body $defaultCommentBody + It 'Should have the expected body text' { + $comment.body | Should -Be $defaultCommentBody + } - It "Should have the expected body text" { - $existingComment.body | Should -Be $defaultCommentBody + It 'Should have the expected type and additional properties' { + $comment.PSObject.TypeNames[0] | Should -Be 'GitHub.IssueComment' + $comment.PSObject.TypeNames[1] | Should -Be 'GitHub.Comment' + $comment.RepositoryUrl | Should -Be $repo.RepositoryUrl + $comment.CommentId | Should -Be $comment.id + $comment.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' } - } - Context 'For getting comments from an issue' { - $existingComments = @(Get-GitHubComment -Uri $repo.svn_url -Issue $issue.number) + $result = Get-GitHubIssueComment -OwnerName $script:ownerName -RepositoryName $repo.name -Comment $comment.id + It 'Should be the expected comment' { + $result.id | Should -Be $comment.id + } - It 'Should have the expected number of comments' { - $existingComments.Count | Should -Be 1 + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.IssueComment' + $result.PSObject.TypeNames[1] | Should -Be 'GitHub.Comment' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.CommentId | Should -Be $result.id + $result.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' } - It 'Should have the expected body text on the first comment' { - $existingComments[0].body | Should -Be $defaultCommentBody + $commentId = $result.id + $updated = Set-GitHubIssueComment -OwnerName $script:ownerName -RepositoryName $repo.name -Comment $commentId -Body $defaultEditedCommentBody + It 'Should have modified the expected comment' { + $updated.id | Should -Be $commentId } - } - Context 'For getting comments from an issue with a specific MediaType' { - $existingComments = @(Get-GitHubComment -Uri $repo.svn_url -Issue $issue.number -MediaType 'Html') + It 'Should have the expected body text' { + $updated.body | Should -Be $defaultEditedCommentBody + } + + It 'Should have the expected type and additional properties' { + $updated.PSObject.TypeNames[0] | Should -Be 'GitHub.IssueComment' + $updated.PSObject.TypeNames[1] | Should -Be 'GitHub.Comment' + $updated.RepositoryUrl | Should -Be $repo.RepositoryUrl + $updated.CommentId | Should -Be $updated.id + $updated.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } - It 'Should have the expected body_html on the first comment' { - $existingComments[0].body_html | Should -Not -Be $null + Remove-GitHubIssueComment -OwnerName $script:ownerName -RepositoryName $repo.name -Comment $commentId -Force + It 'Should have been removed' { + { Get-GitHubIssueComment -OwnerName $script:ownerName -RepositoryName $repo.name -Comment $commentId } | Should -Throw } } - Context 'For editing a comment' { - $newComment = New-GitHubComment -Uri $repo.svn_url -Issue $issue.number -Body $defaultCommentBody - $editedComment = Set-GitHubComment -Uri $repo.svn_url -CommentID $newComment.id -Body $defaultEditedCommentBody + Context 'With the repo on the pipeline' { + $comment = $repo | New-GitHubIssueComment -Issue $issue.number -Body $defaultCommentBody + It 'Should have the expected body text' { + $comment.body | Should -Be $defaultCommentBody + } + + It 'Should have the expected type and additional properties' { + $comment.PSObject.TypeNames[0] | Should -Be 'GitHub.IssueComment' + $comment.PSObject.TypeNames[1] | Should -Be 'GitHub.Comment' + $comment.RepositoryUrl | Should -Be $repo.RepositoryUrl + $comment.CommentId | Should -Be $comment.id + $comment.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + + $result = $repo | Get-GitHubIssueComment -Comment $comment.id + It 'Should be the expected comment' { + $result.id | Should -Be $comment.id + } - It 'Should have a body that is not equal to the original body' { - $editedComment.body | Should -Not -Be $newComment.Body + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.IssueComment' + $result.PSObject.TypeNames[1] | Should -Be 'GitHub.Comment' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.CommentId | Should -Be $result.id + $result.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' } - It 'Should have the edited content' { - $editedComment.body | Should -Be $defaultEditedCommentBody + $commentId = $result.id + $updated = $repo | Set-GitHubIssueComment -Comment $commentId -Body $defaultEditedCommentBody + It 'Should have modified the expected comment' { + $updated.id | Should -Be $commentId + } + + It 'Should have the expected body text' { + $updated.body | Should -Be $defaultEditedCommentBody + } + + It 'Should have the expected type and additional properties' { + $updated.PSObject.TypeNames[0] | Should -Be 'GitHub.IssueComment' + $updated.PSObject.TypeNames[1] | Should -Be 'GitHub.Comment' + $updated.RepositoryUrl | Should -Be $repo.RepositoryUrl + $updated.CommentId | Should -Be $updated.id + $updated.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + + $repo | Remove-GitHubIssueComment -Comment $commentId -Force + It 'Should have been removed' { + { $repo | Get-GitHubIssueComment -Comment $commentId } | Should -Throw } } - Context 'For getting comments from a repository and deleting them' { - $existingComments = @(Get-GitHubComment -Uri $repo.svn_url) + Context 'With the issue on the pipeline' { + $comment = $issue | New-GitHubIssueComment -Body $defaultCommentBody + It 'Should have the expected body text' { + $comment.body | Should -Be $defaultCommentBody + } + + It 'Should have the expected type and additional properties' { + $comment.PSObject.TypeNames[0] | Should -Be 'GitHub.IssueComment' + $comment.PSObject.TypeNames[1] | Should -Be 'GitHub.Comment' + $comment.RepositoryUrl | Should -Be $repo.RepositoryUrl + $comment.CommentId | Should -Be $comment.id + $comment.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + + $result = Get-GitHubIssueComment -OwnerName $script:ownerName -RepositoryName $repo.name -Comment $comment.id + It 'Should be the expected comment' { + $result.id | Should -Be $comment.id + } - It 'Should have the expected number of comments' { - $existingComments.Count | Should -Be 2 + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.IssueComment' + $result.PSObject.TypeNames[1] | Should -Be 'GitHub.Comment' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.CommentId | Should -Be $result.id + $result.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' } - foreach($comment in $existingComments) { - Remove-GitHubComment -Uri $repo.svn_url -CommentID $comment.id -Confirm:$false + $commentId = $result.id + $updated = Set-GitHubIssueComment -OwnerName $script:ownerName -RepositoryName $repo.name -Comment $commentId -Body $defaultEditedCommentBody + It 'Should have modified the expected comment' { + $updated.id | Should -Be $commentId } - $existingComments = @(Get-GitHubComment -Uri $repo.svn_url) + It 'Should have the expected body text' { + $updated.body | Should -Be $defaultEditedCommentBody + } + + It 'Should have the expected type and additional properties' { + $updated.PSObject.TypeNames[0] | Should -Be 'GitHub.IssueComment' + $updated.PSObject.TypeNames[1] | Should -Be 'GitHub.Comment' + $updated.RepositoryUrl | Should -Be $repo.RepositoryUrl + $updated.CommentId | Should -Be $updated.id + $updated.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } - It 'Should have no comments' { - $existingComments.Count | Should -Be 0 + Remove-GitHubIssueComment -OwnerName $script:ownerName -RepositoryName $repo.name -Comment $commentId -Force + It 'Should have been removed' { + { Get-GitHubIssueComment -OwnerName $script:ownerName -RepositoryName $repo.name -Comment $commentId } | Should -Throw } } - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + Context 'With the comment object on the pipeline' { + $comment = New-GitHubIssueComment -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number -Body $defaultCommentBody + It 'Should have the expected body text' { + $comment.body | Should -Be $defaultCommentBody + } + + It 'Should have the expected type and additional properties' { + $comment.PSObject.TypeNames[0] | Should -Be 'GitHub.IssueComment' + $comment.PSObject.TypeNames[1] | Should -Be 'GitHub.Comment' + $comment.RepositoryUrl | Should -Be $repo.RepositoryUrl + $comment.CommentId | Should -Be $comment.id + $comment.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + + $result = $comment | Get-GitHubIssueComment + It 'Should be the expected comment' { + $result.id | Should -Be $comment.id + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.IssueComment' + $result.PSObject.TypeNames[1] | Should -Be 'GitHub.Comment' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.CommentId | Should -Be $result.id + $result.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + + $updated = $comment | Set-GitHubIssueComment -Body $defaultEditedCommentBody + It 'Should have modified the expected comment' { + $updated.id | Should -Be $comment.id + } + + It 'Should have the expected body text' { + $updated.body | Should -Be $defaultEditedCommentBody + } + + It 'Should have the expected type and additional properties' { + $updated.PSObject.TypeNames[0] | Should -Be 'GitHub.IssueComment' + $updated.PSObject.TypeNames[1] | Should -Be 'GitHub.Comment' + $updated.RepositoryUrl | Should -Be $repo.RepositoryUrl + $updated.CommentId | Should -Be $updated.id + $updated.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + + $comment | Remove-GitHubIssueComment -Force + It 'Should have been removed' { + { $comment | Get-GitHubIssueComment } | Should -Throw + } + } } } finally diff --git a/USAGE.md b/USAGE.md index e17c5edb..a02ee3c2 100644 --- a/USAGE.md +++ b/USAGE.md @@ -40,12 +40,12 @@ * [Add assignee to an issue](#add-assignee-to-an-issue) * [Remove assignee from an issue](#remove-assignee-from-an-issue) * [Comments](#comments) - * [Get comments from an issue](#get-comments-from-an-issue) - * [Get comments from a repository](#get-comments-from-a-repository) - * [Get a single comment](#get-a-single-comment) - * [Adding a new comment to an issue](#adding-a-new-comment-to-an-issue) - * [Editing an existing comment](#editing-an-existing-comment) - * [Removing a comment](#removing-a-comment) + * [Get comments from an Issue](#get-comments-from-an-issue) + * [Get Issue comments from a repository](#get-issue-comments-from-a-repository) + * [Get a single Issue comment](#get-a-single-issue-comment) + * [Adding a new comment to an Issue](#adding-a-new-comment-to-an-issue) + * [Editing an existing Issue comment](#editing-an-existing-issue-comment) + * [Removing an Issue comment](#removing-an-issue-comment) * [Milestones](#milestones) * [Get milestones from a repository](#get-milestones-from-a-repository) * [Get a single milestone](#get-a-single-milestone) @@ -429,34 +429,34 @@ Remove-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub - ### Comments -#### Get comments from an issue +#### Get comments from an Issue ```powershell Get-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 ``` -#### Get comments from a repository +#### Get Issue comments from a repository ```powershell Get-GitHubRepositoryComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Sort Created -Direction Ascending -Since '2011-04-14T16:00:49Z' ``` -#### Get a single comment +#### Get a single Issue comment ```powershell -Get-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -CommentID 1 +Get-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -CommentID 1 ``` -#### Adding a new comment to an issue +#### Adding a new comment to an Issue ```powershell -New-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Body "Testing this API" +New-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Body "Testing this API" ``` -#### Editing an existing comment +#### Editing an existing Issue comment ```powershell -Set-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -CommentID 1 -Body "Testing this API" +Set-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -CommentID 1 -Body "Testing this API" ``` -#### Removing a comment +#### Removing an Issue comment ```powershell -Remove-GitHubComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -CommentID 1 +Remove-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -CommentID 1 ``` ---------- @@ -560,12 +560,15 @@ Move-GitHubProjectCard -Card 4 -ColumnId 6 -Bottom @LazyWinAdmin used this module to migrate his blog comments from Disqus to GitHub Issues. [See blog post](https://lazywinadmin.com/2019/04/moving_blog_comments.html) for full details. ```powershell +# Get your repo +$repo = Get-GitHubRepository -OwnerName -RepositoryName RepoName + # Create an issue -$IssueObject = New-GitHubIssue @githubsplat -Title $IssueTitle -Body $body -Label 'blog comments' +$issue = $repo | New-GitHubIssue -Title $IssueTitle -Body $body -Label 'blog comments' # Create Comment -New-GitHubComment @githubsplat -Issue $IssueObject.number -Body $CommentBody +$issue | New-GitHubIssueComment -Body $CommentBody # Close issue -Update-GitHubIssue @githubsplat -Issue $IssueObject.number -State Closed +$issue | Update-GitHubIssue -State Closed ``` From 02672877d89fd9617214866996d549d44a5d8f6b Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 15 Jun 2020 15:18:45 -0700 Subject: [PATCH 65/80] Missing comment update --- GitHubIssueComments.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GitHubIssueComments.ps1 b/GitHubIssueComments.ps1 index 4ab9eff5..156c2e16 100644 --- a/GitHubIssueComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -600,7 +600,7 @@ filter Add-GitHubIssueCommentAdditionalProperties { <# .SYNOPSIS - Adds type name and additional properties to ease pipelining to GitHub Comment objects. + Adds type name and additional properties to ease pipelining to GitHub Issue Comment objects. .PARAMETER InputObject The GitHub object to add additional properties to. From d89bdb4e26361ca7025550d9da0c9aa2d27ce9d6 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 15 Jun 2020 23:05:39 -0700 Subject: [PATCH 66/80] Fixing capitalization --- GitHubEvents.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GitHubEvents.ps1 b/GitHubEvents.ps1 index 16e7ddc0..9bfab784 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -98,7 +98,7 @@ filter Get-GitHubEvent 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) 'ProvidedIssue' = $PSBoundParameters.ContainsKey('Issue') - 'ProvidedEvent' = $PSBoundParameters.ContainsKey('EventID') + 'ProvidedEvent' = $PSBoundParameters.ContainsKey('EventId') } $uriFragment = "repos/$OwnerName/$RepositoryName/issues/events" From c753877a49c48098a498fdf7a07e37e438427051 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 15 Jun 2020 23:10:50 -0700 Subject: [PATCH 67/80] Get Issue tests passing (and fix a bug in Lock-GitHubIssue) --- GitHubIssues.ps1 | 6 +- Tests/GitHubIssues.tests.ps1 | 549 ++++++++++++++++++++++++++++++++--- 2 files changed, 517 insertions(+), 38 deletions(-) diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index 03a09720..7e57418c 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -35,7 +35,7 @@ filter Get-GitHubIssue The organization whose issues should be retrieved. .PARAMETER RepositoryType - all: Retrieve issues across owned, member and org repositories + all: Retrieve issues across owned, member and org repositories ownedAndMember: Retrieve issues across owned and member repositories .PARAMETER Issue @@ -91,7 +91,7 @@ filter Get-GitHubIssue Only issues created by this specified user will be returned. .PARAMETER Mentioned - Only issues that mention this specified user will be returned. + Only issues that mention this specified user will be returned. .PARAMETER MediaType The format in which the API will return the body of the issue. @@ -850,7 +850,7 @@ filter Lock-GitHubIssue } $telemetryProperties['Reason'] = $Reason - $hashBody['active_lock_reason'] = $reasonConverter[$Reason] + $hashBody['lock_reason'] = $reasonConverter[$Reason] } $params = @{ diff --git a/Tests/GitHubIssues.tests.ps1 b/Tests/GitHubIssues.tests.ps1 index 985aa82b..3c125764 100644 --- a/Tests/GitHubIssues.tests.ps1 +++ b/Tests/GitHubIssues.tests.ps1 @@ -17,10 +17,7 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { - # All of these tests will fail without authentication. Let's just avoid the failures. - if (-not $accessTokenConfigured) { return } - - Describe 'Obtaining issues for repository' { + Describe 'Getting issues for a repository' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit } @@ -29,44 +26,151 @@ try Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false } - Context 'When initially created, there are no issues' { - $issues = @(Get-GitHubIssue -Uri $repo.svn_url) + Context 'Getting all issues for a repository with parameters' { + $currentIssues = @(Get-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name) + + $numIssues = 2 + 1..$numIssues | + ForEach-Object { New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([Guid]::NewGuid().Guid) } | + Out-Null + $issues = @(Get-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name) It 'Should return expected number of issues' { - $issues.Count | Should -Be 0 + $issues.Count | Should -Be ($numIssues + $currentIssues.Count) + } + } + + Context 'Getting all issues for a repository with the repo on the pipeline' { + $currentIssues = @($repo | Get-GitHubIssue) + + $numIssues = 2 + 1..$numIssues | + ForEach-Object { $repo | New-GitHubIssue -Title ([Guid]::NewGuid().Guid) } | + Out-Null + + $issues = @($repo | Get-GitHubIssue) + It 'Should return expected number of issues' { + $issues.Count | Should -Be ($numIssues + $currentIssues.Count) + } + } + + Context 'Getting a specific issue with parameters' { + $issue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([Guid]::NewGuid().Guid) + + $result = Get-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number + It 'Should be the expected Issue' { + $result.id | Should -Be $issue.id + } + + It 'Should have the expected property values' { + $result.user.login | Should -Be $script:ownerName + $result.labels | Should -BeNullOrEmpty + $result.milestone | Should -BeNullOrEmpty + $result.assignee | Should -BeNullOrEmpty + $result.assignees | Should -BeNullOrEmpty + $result.closed_by | Should -BeNullOrEmpty + $result.repository | Should -BeNullOrEmpty + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.IssueId | Should -Be $result.id + $result.IssueNumber | Should -Be $result.number + $result.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Getting a specific issue with the repo on the pipeline' { + $issue = $repo | New-GitHubIssue -Title ([Guid]::NewGuid().Guid) + + $result = $repo | Get-GitHubIssue -Issue $issue.number + It 'Should be the expected Issue' { + $result.id | Should -Be $issue.id + } + + It 'Should have the expected property values' { + $result.user.login | Should -Be $script:ownerName + $result.labels | Should -BeNullOrEmpty + $result.milestone | Should -BeNullOrEmpty + $result.assignee | Should -BeNullOrEmpty + $result.assignees | Should -BeNullOrEmpty + $result.closed_by | Should -BeNullOrEmpty + $result.repository | Should -BeNullOrEmpty + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.IssueId | Should -Be $result.id + $result.IssueNumber | Should -Be $result.number + $result.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Getting a specific issue with the issue on the pipeline' { + $issue = $repo | New-GitHubIssue -Title ([Guid]::NewGuid().Guid) + + $result = $issue | Get-GitHubIssue -Issue $issue.number + It 'Should be the expected Issue' { + $result.id | Should -Be $issue.id + } + + It 'Should have the expected property values' { + $result.user.login | Should -Be $script:ownerName + $result.labels | Should -BeNullOrEmpty + $result.milestone | Should -BeNullOrEmpty + $result.assignee | Should -BeNullOrEmpty + $result.assignees | Should -BeNullOrEmpty + $result.closed_by | Should -BeNullOrEmpty + $result.repository | Should -BeNullOrEmpty + } + + It 'Should have the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + $result.RepositoryUrl | Should -Be $repo.RepositoryUrl + $result.IssueId | Should -Be $result.id + $result.IssueNumber | Should -Be $result.number + $result.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' } } - Context 'When there are issues present' { + Context 'Date specific scenarios' { + $existingIssues = @($repo | Get-GitHubIssue -State All) + $newIssues = @() for ($i = 0; $i -lt 4; $i++) { - $newIssues += New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid().Guid) + $newIssues += New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([Guid]::NewGuid().Guid) } $newIssues[0] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[0].number -State Closed $newIssues[-1] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[-1].number -State Closed - $issues = @(Get-GitHubIssue -Uri $repo.svn_url) + $existingOpenIssues = @($existingIssues | Where-Object { $_.state -eq 'open' }) + $newOpenIssues = @($newIssues | Where-Object { $_.state -eq 'open' }) + $issues = @($repo | Get-GitHubIssue) It 'Should return only open issues' { - $issues.Count | Should -Be 2 + $issues.Count | Should -Be ($newOpenIssues.Count + $existingOpenIssues.Count) } - $issues = @(Get-GitHubIssue -Uri $repo.svn_url -State All) + $issues = @($repo | Get-GitHubIssue -State All) It 'Should return all issues' { - $issues.Count | Should -Be 4 + $issues.Count | Should -Be ($newIssues.Count + $existingIssues.Count) } $createdOnOrAfterDate = Get-Date -Date $newIssues[0].created_at $createdOnOrBeforeDate = Get-Date -Date $newIssues[2].created_at - $issues = @((Get-GitHubIssue -Uri $repo.svn_url) | Where-Object { ($_.created_at -ge $createdOnOrAfterDate) -and ($_.created_at -le $createdOnOrBeforeDate) }) + $issues = @(($repo | Get-GitHubIssue) | + Where-Object { ($_.created_at -ge $createdOnOrAfterDate) -and ($_.created_at -le $createdOnOrBeforeDate) }) It 'Smart object date conversion works for comparing dates' { $issues.Count | Should -Be 2 } $createdDate = Get-Date -Date $newIssues[1].created_at - $issues = @(Get-GitHubIssue -Uri $repo.svn_url -State All | Where-Object { ($_.created_at -ge $createdDate) -and ($_.state -eq 'closed') }) + $issues = @(Get-GitHubIssue -Uri $repo.svn_url -State All | + Where-Object { ($_.created_at -ge $createdDate) -and ($_.state -eq 'closed') }) It 'Able to filter based on date and state' { $issues.Count | Should -Be 1 @@ -74,7 +178,7 @@ try } Context 'When issues are retrieved with a specific MediaTypes' { - $newIssue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid()) -Body ([guid]::NewGuid()) + $newIssue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid()) -Body ([Guid]::NewGuid()) $issues = @(Get-GitHubIssue -Uri $repo.svn_url -Issue $newIssue.number -MediaType 'Html') It 'Should return an issue with body_html' { @@ -83,36 +187,411 @@ try } } - Describe 'Obtaining repository with biggest number of issues' { + Describe 'Creating issues' { BeforeAll { - $repo1 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - $repo2 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + $milestone = $repo | New-GitHubMilestone -Title ([Guid]::NewGuid().Guid) } AfterAll { - Remove-GitHubRepository -Uri $repo1.RepositoryUrl -Confirm:$false - Remove-GitHubRepository -Uri $repo2.RepositoryUrl -Confirm:$false + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false } - Context 'When no additional conditions specified' { - for ($i = 0; $i -lt 3; $i++) - { - $null = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo1.name -Title ([guid]::NewGuid().Guid) + Context 'Creating an Issue with parameters' { + $params = @{ + 'OwnerName' = $script:ownerName + 'RepositoryName' = $repo.name + 'Title' = '-issue title-' + 'Body' = '-issue body-' + 'Assignee' = $script:ownerName + 'Milestone' = $milestone.number + 'Label' = 'bug' + 'MediaType' = 'Raw' + } + + $issue = New-GitHubIssue @params + + It 'Should have the expected property values' { + $issue.title | Should -Be $params.Title + $issue.body | Should -Be $params.Body + $issue.assignee.login | Should -Be $params.Assignee + $issue.assignees.Count | Should -Be 1 + $issue.assignees[0].login | Should -Be $params.Assignee + $issue.milestone.number | Should -Be $params.Milestone + $issue.labels.Count | Should -Be 1 + $issue.labels[0].name | Should -Contain $params.Label + } + + It 'Should have the expected type and additional properties' { + $issue.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + $issue.RepositoryUrl | Should -Be $repo.RepositoryUrl + $issue.IssueId | Should -Be $issue.id + $issue.IssueNumber | Should -Be $issue.number + $issue.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $issue.assignee.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $issue.assignees[0].PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $issue.milestone.PSObject.TypeNames[0] | Should -Be 'GitHub.Milestone' + $issue.labels[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + } + } + + Context 'Creating an Issue with the repo on the pipeline' { + $params = @{ + 'Title' = '-issue title-' + 'Body' = '-issue body-' + 'Assignee' = $script:ownerName + 'Milestone' = $milestone.number + 'Label' = 'bug' + 'MediaType' = 'Raw' + } + + $issue = $repo | New-GitHubIssue @params + + It 'Should have the expected property values' { + $issue.title | Should -Be $params.Title + $issue.body | Should -Be $params.Body + $issue.assignee.login | Should -Be $params.Assignee + $issue.assignees.Count | Should -Be 1 + $issue.assignees[0].login | Should -Be $params.Assignee + $issue.milestone.number | Should -Be $params.Milestone + $issue.labels.Count | Should -Be 1 + $issue.labels[0].name | Should -Contain $params.Label + } + + It 'Should have the expected type and additional properties' { + $issue.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + $issue.RepositoryUrl | Should -Be $repo.RepositoryUrl + $issue.IssueId | Should -Be $issue.id + $issue.IssueNumber | Should -Be $issue.number + $issue.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $issue.assignee.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $issue.assignees[0].PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $issue.milestone.PSObject.TypeNames[0] | Should -Be 'GitHub.Milestone' + $issue.labels[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + } + } + } + + Describe 'Updating issues' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + $milestone = $repo | New-GitHubMilestone -Title ([Guid]::NewGuid().Guid) + $title = 'issue title' + } + + AfterAll { + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } + + Context 'Updating an Issue with parameters' { + $issue = New-GitHubIssue -OwnerName $script:OwnerName -RepositoryName $repo.name -Title $title + It 'Should have the expected property values' { + $issue.title | Should -Be $title + $issue.body | Should -BeNullOrEmpty + $issue.assignee.login | Should -BeNullOrEmpty + $issue.assignees | Should -BeNullOrEmpty + $issue.milestone | Should -BeNullOrEmpty + $issue.labels | Should -BeNullOrEmpty + } + + $params = @{ + 'OwnerName' = $script:ownerName + 'RepositoryName' = $repo.name + 'Issue' = $issue.number + 'Title' = '-new title-' + 'Body' = '-new body-' + 'Assignee' = $script:ownerName + 'Milestone' = $milestone.number + 'Label' = 'bug' + 'MediaType' = 'Raw' + } + + $updated = Update-GitHubIssue @params + It 'Should have the expected property values' { + $updated.id | Should -Be $issue.id + $updated.number | Should -Be $issue.number + $updated.title | Should -Be $params.Title + $updated.body | Should -Be $params.Body + $updated.assignee.login | Should -Be $params.Assignee + $updated.assignees.Count | Should -Be 1 + $updated.assignees[0].login | Should -Be $params.Assignee + $updated.milestone.number | Should -Be $params.Milestone + $updated.labels.Count | Should -Be 1 + $updated.labels[0].name | Should -Contain $params.Label + } + + It 'Should have the expected type and additional properties' { + $updated.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + $updated.RepositoryUrl | Should -Be $repo.RepositoryUrl + $updated.IssueId | Should -Be $updated.id + $updated.IssueNumber | Should -Be $updated.number + $updated.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $updated.assignee.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $updated.assignees[0].PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $updated.milestone.PSObject.TypeNames[0] | Should -Be 'GitHub.Milestone' + $updated.labels[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + } + } + + Context 'Updating an Issue with the repo on the pipeline' { + $issue = New-GitHubIssue -OwnerName $script:OwnerName -RepositoryName $repo.name -Title $title + It 'Should have the expected property values' { + $issue.title | Should -Be $title + $issue.body | Should -BeNullOrEmpty + $issue.assignee.login | Should -BeNullOrEmpty + $issue.assignees | Should -BeNullOrEmpty + $issue.milestone | Should -BeNullOrEmpty + $issue.labels | Should -BeNullOrEmpty } - $repos = @(($repo1.svn_url), ($repo2.svn_url)) - $issueCounts = @() - $repos | ForEach-Object { $issueCounts = $issueCounts + ([PSCustomObject]@{ 'Uri' = $_; 'Count' = (Get-GitHubIssue -Uri $_).Count }) } - $issueCounts = $issueCounts | Sort-Object -Property Count -Descending + $params = @{ + 'Issue' = $issue.number + 'Title' = '-new title-' + 'Body' = '-new body-' + 'Assignee' = $script:ownerName + 'Milestone' = $milestone.number + 'Label' = 'bug' + 'MediaType' = 'Raw' + } + + $updated = $repo | Update-GitHubIssue @params + It 'Should have the expected property values' { + $updated.id | Should -Be $issue.id + $updated.number | Should -Be $issue.number + $updated.title | Should -Be $params.Title + $updated.body | Should -Be $params.Body + $updated.assignee.login | Should -Be $params.Assignee + $updated.assignees.Count | Should -Be 1 + $updated.assignees[0].login | Should -Be $params.Assignee + $updated.milestone.number | Should -Be $params.Milestone + $updated.labels.Count | Should -Be 1 + $updated.labels[0].name | Should -Contain $params.Label + } + + It 'Should have the expected type and additional properties' { + $updated.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + $updated.RepositoryUrl | Should -Be $repo.RepositoryUrl + $updated.IssueId | Should -Be $updated.id + $updated.IssueNumber | Should -Be $updated.number + $updated.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $updated.assignee.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $updated.assignees[0].PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $updated.milestone.PSObject.TypeNames[0] | Should -Be 'GitHub.Milestone' + $updated.labels[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + } + } + + Context 'Updating an Issue with the issue on the pipeline' { + $issue = New-GitHubIssue -OwnerName $script:OwnerName -RepositoryName $repo.name -Title $title + It 'Should have the expected property values' { + $issue.title | Should -Be $title + $issue.body | Should -BeNullOrEmpty + $issue.assignee.login | Should -BeNullOrEmpty + $issue.assignees | Should -BeNullOrEmpty + $issue.milestone | Should -BeNullOrEmpty + $issue.labels | Should -BeNullOrEmpty + } + + $params = @{ + 'Title' = '-new title-' + 'Body' = '-new body-' + 'Assignee' = $script:ownerName + 'Milestone' = $milestone.number + 'Label' = 'bug' + 'MediaType' = 'Raw' + } + + $updated = $issue | Update-GitHubIssue @params + It 'Should have the expected property values' { + $updated.id | Should -Be $issue.id + $updated.number | Should -Be $issue.number + $updated.title | Should -Be $params.Title + $updated.body | Should -Be $params.Body + $updated.assignee.login | Should -Be $params.Assignee + $updated.assignees.Count | Should -Be 1 + $updated.assignees[0].login | Should -Be $params.Assignee + $updated.milestone.number | Should -Be $params.Milestone + $updated.labels.Count | Should -Be 1 + $updated.labels[0].name | Should -Contain $params.Label + } + + It 'Should have the expected type and additional properties' { + $updated.PSObject.TypeNames[0] | Should -Be 'GitHub.Issue' + $updated.RepositoryUrl | Should -Be $repo.RepositoryUrl + $updated.IssueId | Should -Be $updated.id + $updated.IssueNumber | Should -Be $updated.number + $updated.user.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $updated.assignee.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $updated.assignees[0].PSObject.TypeNames[0] | Should -Be 'GitHub.User' + $updated.milestone.PSObject.TypeNames[0] | Should -Be 'GitHub.Milestone' + $updated.labels[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Label' + } + } + } + + Describe 'Locking and unlocking issues' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + } + + AfterAll { + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } + + Context 'Locking and unlocking an Issue with parameters' { + $issue = New-GitHubIssue -OwnerName $script:OwnerName -RepositoryName $repo.name -Title ([Guid]::NewGuid().Guid) + It 'Should be unlocked' { + $issue.locked | Should -BeFalse + $issue.active_lock_reason | Should -BeNullOrEmpty + } + + $reason = 'Resolved' + Lock-GitHubIssue -OwnerName $script:OwnerName -RepositoryName $repo.name -Issue $issue.number -Reason $reason + $updated = Get-GitHubIssue -OwnerName $script:OwnerName -RepositoryName $repo.name -Issue $issue.number + It 'Should be locked' { + $updated.id | Should -Be $issue.id + $updated.number | Should -Be $issue.number + $updated.locked | Should -BeTrue + $updated.active_lock_reason | Should -Be $reason + } + + Unlock-GitHubIssue -OwnerName $script:OwnerName -RepositoryName $repo.name -Issue $issue.number + $updated = Get-GitHubIssue -OwnerName $script:OwnerName -RepositoryName $repo.name -Issue $issue.number + It 'Should be unlocked again' { + $updated.id | Should -Be $issue.id + $updated.number | Should -Be $issue.number + $updated.locked | Should -BeFalse + $updated.active_lock_reason | Should -BeNullOrEmpty + } + } + + Context 'Locking and unlocking an Issue with the repo on the pipeline' { + $issue = $repo | New-GitHubIssue -Title ([Guid]::NewGuid().Guid) + It 'Should be unlocked' { + $issue.locked | Should -BeFalse + $issue.active_lock_reason | Should -BeNullOrEmpty + } + + $reason = 'Resolved' + $repo | Lock-GitHubIssue -Issue $issue.number -Reason $reason + $updated = $repo | Get-GitHubIssue -Issue $issue.number + It 'Should be locked' { + $updated.id | Should -Be $issue.id + $updated.number | Should -Be $issue.number + $updated.locked | Should -BeTrue + $updated.active_lock_reason | Should -Be $reason + } + + $repo | Unlock-GitHubIssue -Issue $issue.number + $updated = $repo | Get-GitHubIssue -Issue $issue.number + It 'Should be unlocked again' { + $updated.id | Should -Be $issue.id + $updated.number | Should -Be $issue.number + $updated.locked | Should -BeFalse + $updated.active_lock_reason | Should -BeNullOrEmpty + } + } + + Context 'Locking and unlocking an Issue with the issue on the pipeline' { + $issue = New-GitHubIssue -OwnerName $script:OwnerName -RepositoryName $repo.name -Title ([Guid]::NewGuid().Guid) + It 'Should be unlocked' { + $issue.locked | Should -BeFalse + $issue.active_lock_reason | Should -BeNullOrEmpty + } + + $reason = 'Resolved' + $issue | Lock-GitHubIssue -Reason $reason + $updated = $issue | Get-GitHubIssue + It 'Should be locked' { + $updated.id | Should -Be $issue.id + $updated.number | Should -Be $issue.number + $updated.locked | Should -BeTrue + $updated.active_lock_reason | Should -Be $reason + } + + $issue | Unlock-GitHubIssue + $updated = $issue | Get-GitHubIssue + It 'Should be unlocked again' { + $updated.id | Should -Be $issue.id + $updated.number | Should -Be $issue.number + $updated.locked | Should -BeFalse + $updated.active_lock_reason | Should -BeNullOrEmpty + } + } + } + + Describe 'Issue Timeline' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + } + + AfterAll { + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } + + Context 'Getting the Issue timeline with parameters' { + $issue = New-GitHubIssue -OwnerName $script:OwnerName -RepositoryName $repo.name -Title ([Guid]::NewGuid().Guid) + $timeline = @(Get-GitHubIssueTimeline -OwnerName $script:OwnerName -RepositoryName $repo.name -Issue $issue.number) + It 'Should have no events so far' { + $timeline.Count | Should -Be 0 + } + + Lock-GitHubIssue -OwnerName $script:OwnerName -RepositoryName $repo.name -Issue $issue.number + $timeline = @(Get-GitHubIssueTimeline -OwnerName $script:OwnerName -RepositoryName $repo.name -Issue $issue.number) + It 'Should have an event now' { + $timeline.Count | Should -Be 1 + $timeline[0].event | Should -Be 'locked' + } + + It 'Should have the expected type and additional properties' { + $timeline[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Event' + $timeline[0].RepositoryUrl | Should -Be $repo.RepositoryUrl + $timeline[0].EventId | Should -Be $timeline[0].id + $timeline[0].actor.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Getting the Issue timeline with the repo on the pipeline' { + $issue = $repo | New-GitHubIssue -Title ([Guid]::NewGuid().Guid) + $timeline = @($repo | Get-GitHubIssueTimeline -Issue $issue.number) + It 'Should have no events so far' { + $timeline.Count | Should -Be 0 + } + + $repo | Lock-GitHubIssue -Issue $issue.number + $timeline = @($repo | Get-GitHubIssueTimeline -Issue $issue.number) + It 'Should have an event now' { + $timeline.Count | Should -Be 1 + $timeline[0].event | Should -Be 'locked' + } + + It 'Should have the expected type and additional properties' { + $timeline[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Event' + $timeline[0].RepositoryUrl | Should -Be $repo.RepositoryUrl + $timeline[0].EventId | Should -Be $timeline[0].id + $timeline[0].actor.PSObject.TypeNames[0] | Should -Be 'GitHub.User' + } + } + + Context 'Getting the Issue timeline with the issue on the pipeline' { + $issue = $repo | New-GitHubIssue -Title ([Guid]::NewGuid().Guid) + $timeline = @($issue | Get-GitHubIssueTimeline) + It 'Should have no events so far' { + $timeline.Count | Should -Be 0 + } - It 'Should return expected number of issues for each repository' { - $issueCounts[0].Count | Should -Be 3 - $issueCounts[1].Count | Should -Be 0 + $issue | Lock-GitHubIssue + $timeline = @($issue | Get-GitHubIssueTimeline) + It 'Should have an event now' { + $timeline.Count | Should -Be 1 + $timeline[0].event | Should -Be 'locked' } - It 'Should return expected repository names' { - $issueCounts[0].Uri | Should -Be $repo1.svn_url - $issueCounts[1].Uri | Should -Be $repo2.svn_url + It 'Should have the expected type and additional properties' { + $timeline[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Event' + $timeline[0].RepositoryUrl | Should -Be $repo.RepositoryUrl + $timeline[0].EventId | Should -Be $timeline[0].id + $timeline[0].actor.PSObject.TypeNames[0] | Should -Be 'GitHub.User' } } } From 48c96d9b9537e959a18a230bfa424ac8c104aead Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 16 Jun 2020 00:23:00 -0700 Subject: [PATCH 68/80] Some minor test fixes. All passing clean --- Tests/GitHubIssues.tests.ps1 | 29 ++++++---- Tests/GitHubLabels.tests.ps1 | 76 +++++++++++++-------------- Tests/GitHubProjects.tests.ps1 | 20 ++----- Tests/GitHubRepositoryForks.tests.ps1 | 1 + 4 files changed, 62 insertions(+), 64 deletions(-) diff --git a/Tests/GitHubIssues.tests.ps1 b/Tests/GitHubIssues.tests.ps1 index 3c125764..2f8f8624 100644 --- a/Tests/GitHubIssues.tests.ps1 +++ b/Tests/GitHubIssues.tests.ps1 @@ -135,6 +135,25 @@ try } } + Context 'When issues are retrieved with a specific MediaTypes' { + $newIssue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid()) -Body ([Guid]::NewGuid()) + + $issues = @(Get-GitHubIssue -Uri $repo.svn_url -Issue $newIssue.number -MediaType 'Html') + It 'Should return an issue with body_html' { + $issues[0].body_html | Should -Not -Be $null + } + } + } + + Describe 'Date-specific Issue tests' { + BeforeAll { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + } + + AfterAll { + Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false + } + Context 'Date specific scenarios' { $existingIssues = @($repo | Get-GitHubIssue -State All) @@ -176,17 +195,7 @@ try $issues.Count | Should -Be 1 } } - - Context 'When issues are retrieved with a specific MediaTypes' { - $newIssue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid()) -Body ([Guid]::NewGuid()) - - $issues = @(Get-GitHubIssue -Uri $repo.svn_url -Issue $newIssue.number -MediaType 'Html') - It 'Should return an issue with body_html' { - $issues[0].body_html | Should -Not -Be $null - } - } } - Describe 'Creating issues' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index 85d4556a..e2807442 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -79,9 +79,9 @@ try Describe 'Getting labels from a repository' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName repositoryName + $repo = New-GitHubRepository -RepositoryName $repositoryName - Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $defaultLabels + Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $defaultLabels } AfterAll { @@ -89,7 +89,7 @@ try } Context 'When querying for all labels' { - $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) + $labels = @(Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName) It 'Should return expected number of labels' { $labels.Count | Should -Be $defaultLabels.Count @@ -151,7 +151,7 @@ try Context 'When querying for a specific label' { $labelName = 'bug' - $label = Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $labelName + $label = Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $labelName It 'Should return expected label' { $label.name | Should -Be $labelName @@ -186,7 +186,7 @@ try # # Context 'When querying for a specific label (via Label on pipeline)' { # $labelName = 'bug' - # $label = $labelName | Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName + # $label = $labelName | Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName # It 'Should return expected label' { # $label.name | Should -Be $labelName @@ -204,7 +204,7 @@ try Describe 'Creating a new label' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName repositoryName + $repo = New-GitHubRepository -RepositoryName $repositoryName } AfterAll { @@ -214,7 +214,7 @@ try Context 'On a repo with parameters' { $labelName = [Guid]::NewGuid().Guid $color = 'AAAAAA' - $label = New-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $labelName -Color $color + $label = New-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $labelName -Color $color It 'New label should be created' { $label.name | Should -Be $labelName @@ -232,7 +232,7 @@ try Context 'On a repo with and color starts with a #' { $labelName = [Guid]::NewGuid().Guid $color = '#AAAAAA' - $label = New-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $labelName -Color $color + $label = New-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $labelName -Color $color It 'New label should be created' { $label.name | Should -Be $labelName @@ -271,7 +271,7 @@ try Context 'On a repo with the name on the pipeline' { $labelName = [Guid]::NewGuid().Guid $color = 'CCCCCC' - $label = $labelName | New-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Color $color + $label = $labelName | New-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Color $color It 'New label should be created' { $label.name | Should -Be $labelName @@ -289,7 +289,7 @@ try Context 'On a repo with three names on the pipeline' { $labelNames = @(([Guid]::NewGuid().Guid), ([Guid]::NewGuid().Guid), ([Guid]::NewGuid().Guid)) $color = 'CCCCCC' - $labels = @($labelNames | New-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Color $color) + $labels = @($labelNames | New-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Color $color) It 'Has the right count of labels' { $labels.Count | Should -Be $labelNames.Count @@ -318,7 +318,7 @@ try Describe 'Removing a label' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName repositoryName + $repo = New-GitHubRepository -RepositoryName $repositoryName } AfterAll { @@ -327,7 +327,7 @@ try Context 'Removing a label with parameters' { $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' - Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $label.name -Force + Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -Force It 'Should be gone after being removed by parameter' { { $label | Get-GitHubLabel } | Should -Throw @@ -345,7 +345,7 @@ try Context 'Removing a label with the name on the pipeline' { $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' - $label.name | Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Force + $label.name | Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Force It 'Should be gone after being removed by parameter' { { $label | Get-GitHubLabel } | Should -Throw @@ -365,7 +365,7 @@ try Describe 'Updating a label' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName repositoryName + $repo = New-GitHubRepository -RepositoryName $repositoryName } AfterAll { @@ -376,7 +376,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' $newColor = 'AAAAAA' - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $label.name -Color $newColor + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -Color $newColor It 'Label should have different color' { $result.name | Should -Be $label.name @@ -396,7 +396,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' $newColor = '#AAAAAA' - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $label.name -Color $newColor + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -Color $newColor It 'Label should have different color' { $result.name | Should -Be $label.name @@ -416,7 +416,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' $newName = [Guid]::NewGuid().Guid - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $label.name -NewName $newName + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -NewName $newName It 'Label should have different name' { $result.name | Should -Be $newName @@ -436,7 +436,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' -Description 'test description' $newDescription = [Guid]::NewGuid().Guid - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $label.name -Description $newDescription + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -Description $newDescription It 'Label should have different name' { $result.name | Should -Be $label.name @@ -458,7 +458,7 @@ try $newName = [Guid]::NewGuid().Guid $newColor = 'AAAAAA' $newDescription = [Guid]::NewGuid().Guid - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $label.name -NewName $newName -Color $newColor -Description $newDescription + $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -NewName $newName -Color $newColor -Description $newDescription It 'Label should have different everything' { $result.name | Should -Be $newName @@ -542,7 +542,7 @@ try Describe 'Initializing the labels on a repository' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName repositoryName + $repo = New-GitHubRepository -RepositoryName $repositoryName } AfterAll { @@ -550,7 +550,7 @@ try } Context 'Applying a default set of labels' { - Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $defaultLabels + Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $defaultLabels $labels = @($repo | Get-GitHubLabel) @@ -624,7 +624,7 @@ try Describe 'Adding labels to an issue' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName repositoryName + $repo = New-GitHubRepository -RepositoryName $repositoryName $repo | Set-GitHubLabel -Label $defaultLabels } @@ -635,7 +635,7 @@ try Context 'Adding labels to an issue' { $expectedLabels = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[3].name) $issue = $repo | New-GitHubIssue -Title 'test issue' - $result = @(Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Issue $issue.number -LabelName $expectedLabels) + $result = @(Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $expectedLabels) It 'Should return the number of labels that were just added' { $result.Count | Should -Be $expectedLabels.Count @@ -764,7 +764,7 @@ try Context 'Adding labels to an issue with the label names on the pipeline' { $expectedLabels = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[3].name) $issue = $repo | New-GitHubIssue -Title 'test issue' - $result = @($expectedLabels | Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Issue $issue.number) + $result = @($expectedLabels | Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Issue $issue.number) It 'Should return the number of labels that were just added' { $result.Count | Should -Be $expectedLabels.Count @@ -807,8 +807,8 @@ try Context 'Adding labels to an issue with the label object on the pipeline' { $expectedLabels = @($defaultLabels[0].name, $defaultLabels[1].name, $defaultLabels[3].name) $issue = $repo | New-GitHubIssue -Title 'test issue' - $labels = @($expectedLabels | ForEach-Object { Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $_ } ) - $result = @($labels | Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Issue $issue.number) + $labels = @($expectedLabels | ForEach-Object { Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $_ } ) + $result = @($labels | Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Issue $issue.number) It 'Should return the number of labels that were just added' { $result.Count | Should -Be $expectedLabels.Count @@ -852,7 +852,7 @@ try Describe 'Creating a new Issue with labels' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName repositoryName + $repo = New-GitHubRepository -RepositoryName $repositoryName $repo | Set-GitHubLabel -Label $defaultLabels } @@ -863,7 +863,7 @@ try Context 'When creating a new issue using parameters' { $issueName = [Guid]::NewGuid().Guid $issueLabels = @($defaultLabels[0].name, $defaultLabels[1].name) - $issue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName repositoryName -Title $issueName -Label $issueLabels + $issue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repositoryName -Title $issueName -Label $issueLabels It 'Should return the number of labels that were just added' { $issue.labels.Count | Should -Be $issueLabels.Count @@ -918,7 +918,7 @@ try Describe 'Removing labels on an issue' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName repositoryName + $repo = New-GitHubRepository -RepositoryName $repositoryName $repo | Set-GitHubLabel -Label $defaultLabels } @@ -939,9 +939,9 @@ try } # Doing this manually instead of in a loop to try out different combinations of -Confirm:$false and -Force - Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $labelsToAdd[0] -Issue $issue.number -Confirm:$false - Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $labelsToAdd[1] -Issue $issue.number -Force - Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Label $labelsToAdd[2] -Issue $issue.number -Confirm:$false -Force + Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $labelsToAdd[0] -Issue $issue.number -Confirm:$false + Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $labelsToAdd[1] -Issue $issue.number -Force + Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $labelsToAdd[2] -Issue $issue.number -Confirm:$false -Force $issueLabels = @($issue | Get-GitHubLabel) It 'Should have removed all labels from the issue' { @@ -1009,7 +1009,7 @@ try # } # $labelToRemove = $labelsToAdd[2] - # $labelToRemove | Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Issue $issue.number -Confirm:$false + # $labelToRemove | Remove-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Issue $issue.number -Confirm:$false # $issueLabels = @($issue | Get-GitHubLabel) # It 'Should have removed the expected label from the issue' { @@ -1085,7 +1085,7 @@ try Describe 'Replacing labels on an issue' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName repositoryName + $repo = New-GitHubRepository -RepositoryName $repositoryName $repo | Set-GitHubLabel -Label $defaultLabels } @@ -1106,7 +1106,7 @@ try } $newIssueLabels = @($defaultLabels[0].name, $defaultLabels[5].name) - $result = @(Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Issue $issue.number -Label $newIssueLabels) + $result = @(Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Issue $issue.number -Label $newIssueLabels) It 'Should have the expected labels' { $result.labels.Count | Should -Be $newIssueLabels.Count @@ -1209,7 +1209,7 @@ try $newIssueLabelNames = @($defaultLabels[0].name, $defaultLabels[5].name) $issueLabels = @($newIssueLabelNames | ForEach-Object { $repo | Get-GitHubLabel -Label $_ }) - $result = @($issueLabels | Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Issue $issue.number) + $result = @($issueLabels | Set-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Issue $issue.number) It 'Should have the expected labels' { $result.labels.Count | Should -Be $newIssueLabelNames.Count @@ -1234,7 +1234,7 @@ try Describe 'Labels and Milestones' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid - $repo = New-GitHubRepository -RepositoryName repositoryName + $repo = New-GitHubRepository -RepositoryName $repositoryName $repo | Set-GitHubLabel -Label $defaultLabels $milestone = $repo | New-GitHubMilestone -Title 'test milestone' @@ -1256,7 +1256,7 @@ try $issue2.labels.Count | Should -Be $issueLabels2.Count } - $milestoneLabels = Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName repositoryName -Milestone $milestone.number + $milestoneLabels = Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Milestone $milestone.number It 'Should return the same number of labels in the issue that were assigned to the milestone' { $milestoneLabels.Count | Should -Be ($issue.labels.Count + $issue2.labels.Count) diff --git a/Tests/GitHubProjects.tests.ps1 b/Tests/GitHubProjects.tests.ps1 index 3cc2d694..3e93b1c2 100644 --- a/Tests/GitHubProjects.tests.ps1 +++ b/Tests/GitHubProjects.tests.ps1 @@ -592,10 +592,7 @@ try Describe 'Remove Project' { Context 'Remove User projects' { - BeforeAll { - $project = New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc - } - + $project = New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc $null = Remove-GitHubProject -Project $project.id -Force It 'Project should be removed' { {Get-GitHubProject -Project $project.id} | Should -Throw @@ -603,10 +600,7 @@ try } Context 'Remove Organization projects' { - BeforeAll { - $project = New-GitHubProject -OrganizationName $script:organizationName -Name $defaultOrgProject -Description $defaultOrgProjectDesc - } - + $project = New-GitHubProject -OrganizationName $script:organizationName -Name $defaultOrgProject -Description $defaultOrgProjectDesc $null = Remove-GitHubProject -Project $project.id -Force It 'Project should be removed' { {Get-GitHubProject -Project $project.id} | Should -Throw @@ -614,10 +608,7 @@ try } Context 'Remove Repo projects' { - BeforeAll { - $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultRepoProject -Description $defaultRepoProjectDesc - } - + $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultRepoProject -Description $defaultRepoProjectDesc $null = Remove-GitHubProject -Project $project.id -Confirm:$false It 'Project should be removed' { {Get-GitHubProject -Project $project.id} | Should -Throw @@ -625,10 +616,7 @@ try } Context 'Remove Repo project via pipeline' { - BeforeAll { - $project = $repo | New-GitHubProject -Name $defaultRepoProject -Description $defaultRepoProjectDesc - } - + $project = $repo | New-GitHubProject -Name $defaultRepoProject -Description $defaultRepoProjectDesc $project | Remove-GitHubProject -Force It 'Project should be removed' { {$project | Get-GitHubProject} | Should -Throw diff --git a/Tests/GitHubRepositoryForks.tests.ps1 b/Tests/GitHubRepositoryForks.tests.ps1 index 45a3e47d..a7f6d37f 100644 --- a/Tests/GitHubRepositoryForks.tests.ps1 +++ b/Tests/GitHubRepositoryForks.tests.ps1 @@ -83,6 +83,7 @@ try } AfterAll { + Start-Sleep -Seconds 3 # Trying to avoid an issue with deleting the repo if it's still being created by GitHub $repo | Remove-GitHubRepository -Force } From 13303942d8d1d2d771f9c0a519c9b2ef5e93e5a8 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 16 Jun 2020 02:04:29 -0700 Subject: [PATCH 69/80] Add tests for GitHubMiscellaneous and fix up some other tests --- GitHubContents.ps1 | 15 +- GitHubMiscellaneous.ps1 | 28 ++- GitHubRepositoryTraffic.ps1 | 28 ++- Tests/GitHubContents.tests.ps1 | 49 ++++- Tests/GitHubIssues.tests.ps1 | 1 + Tests/GitHubMiscellaneous.tests.ps1 | 244 +++++++++++++++++++++++- Tests/GitHubRepositoryTraffic.tests.ps1 | 12 +- 7 files changed, 355 insertions(+), 22 deletions(-) diff --git a/GitHubContents.ps1 b/GitHubContents.ps1 index c222479b..d28f942b 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -1,4 +1,10 @@ -filter Get-GitHubContent +@{ + GitHubContentTypeName = 'GitHub.Content' + }.GetEnumerator() | ForEach-Object { + Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value + } + + filter Get-GitHubContent { <# .SYNOPSIS @@ -73,6 +79,8 @@ filter Get-GitHubContent [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName = 'Elements')] + [OutputType([String])] + [OutputType({$script:GitHubContentTypeName})] [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')] @@ -153,5 +161,10 @@ filter Get-GitHubContent } } + if ($MediaType -eq 'Object') + { + $result.PSObject.TypeNames.Insert(0, $script:GitHubContentTypeName) + } + return $result } diff --git a/GitHubMiscellaneous.ps1 b/GitHubMiscellaneous.ps1 index 5dee23fc..3ad499dc 100644 --- a/GitHubMiscellaneous.ps1 +++ b/GitHubMiscellaneous.ps1 @@ -252,8 +252,11 @@ filter Get-GitHubLicense [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($result.content)) #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding( + SupportsShouldProcess, + DefaultParameterSetName='All')] [OutputType({$script:GitHubLicenseTypeName})] + [OutputType({$script:GitHubContentTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -318,10 +321,27 @@ filter Get-GitHubLicense $result = Invoke-GHRestMethod @params foreach ($item in $result) { - $item.PSObject.TypeNames.Insert(0, $script:GitHubLicenseTypeName) - if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + if ($PSCmdlet.ParameterSetName -in ('Elements', 'Uri')) + { + # Convert from base64 + $decoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($item.content)) + Add-Member -InputObject $item -NotePropertyName "contentAsString" -NotePropertyValue $decoded + + $item.PSObject.TypeNames.Insert(0, $script:GitHubContentTypeName) + $item.license.PSObject.TypeNames.Insert(0, $script:GitHubLicenseTypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + Add-Member -InputObject $item -Name 'LicenseKey' -Value $item.license.key -MemberType NoteProperty -Force + } + } + else { - Add-Member -InputObject $item -Name 'LicenseKey' -Value $item.key -MemberType NoteProperty -Force + $item.PSObject.TypeNames.Insert(0, $script:GitHubLicenseTypeName) + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + Add-Member -InputObject $item -Name 'LicenseKey' -Value $item.key -MemberType NoteProperty -Force + } } } diff --git a/GitHubRepositoryTraffic.ps1 b/GitHubRepositoryTraffic.ps1 index 7e703514..5b461927 100644 --- a/GitHubRepositoryTraffic.ps1 +++ b/GitHubRepositoryTraffic.ps1 @@ -99,7 +99,12 @@ filter Get-GitHubReferrerTraffic } $result = Invoke-GHRestMethod @params - $result.PSObject.TypeNames.Insert(0, $script:GitHubReferrerTrafficTypeName) + + if ($null -ne $result) + { + $result.PSObject.TypeNames.Insert(0, $script:GitHubReferrerTrafficTypeName) + } + return $result } @@ -192,7 +197,12 @@ filter Get-GitHubPathTraffic } $result = Invoke-GHRestMethod @params - $result.PSObject.TypeNames.Insert(0, $script:GitHubPathTrafficTypeName) + + if ($null -ne $result) + { + $result.PSObject.TypeNames.Insert(0, $script:GitHubPathTrafficTypeName) + } + return $result } @@ -293,7 +303,12 @@ filter Get-GitHubViewTraffic } $result = Invoke-GHRestMethod @params - $result.PSObject.TypeNames.Insert(0, $script:GitHubViewTrafficTypeName) + + if ($null -ne $result) + { + $result.PSObject.TypeNames.Insert(0, $script:GitHubViewTrafficTypeName) + } + return $result } @@ -394,6 +409,11 @@ filter Get-GitHubCloneTraffic } $result = Invoke-GHRestMethod @params - $result.PSObject.TypeNames.Insert(0, $script:GitHubCloneTrafficTypeName) + + if ($null -ne $result) + { + $result.PSObject.TypeNames.Insert(0, $script:GitHubCloneTrafficTypeName) + } + return $result } diff --git a/Tests/GitHubContents.tests.ps1 b/Tests/GitHubContents.tests.ps1 index bd372626..eda60f03 100644 --- a/Tests/GitHubContents.tests.ps1 +++ b/Tests/GitHubContents.tests.ps1 @@ -66,6 +66,10 @@ try $folderOutput.entries[0].name | Should -Be $readmeFileName $folderOutput.entries[0].path | Should -Be $readmeFileName } + + It "Should have the expected type" { + $folderOutput.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + } } Context 'For getting folder contents via URL' { @@ -74,19 +78,27 @@ try It "Should have the expected name" { $folderOutput.name | Should -BeNullOrEmpty } + It "Should have the expected path" { $folderOutput.path | Should -BeNullOrEmpty } + It "Should have the expected type" { $folderOutput.type | Should -Be "dir" } + It "Should have the expected entries" { $folderOutput.entries.length | Should -Be 1 } + It "Should have the expected entry data" { $folderOutput.entries[0].name | Should -Be $readmeFileName $folderOutput.entries[0].path | Should -Be $readmeFileName } + + It "Should have the expected type" { + $folderOutput.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + } } Context 'For getting folder contents with the repo on the pipeline' { @@ -112,29 +124,38 @@ try $folderOutput.entries[0].name | Should -Be $readmeFileName $folderOutput.entries[0].path | Should -Be $readmeFileName } + + It "Should have the expected type" { + $folderOutput.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + } } Context 'For getting raw (byte) file contents' { - $readmeFileBytes = Get-GitHubContent -OwnerName $script:ownerName -RepositoryName $repo.name -Path $readmeFileName -MediaType Raw $readmeFileString = [System.Text.Encoding]::UTF8.GetString($readmeFileBytes) It "Should have the expected content" { $readmeFileString | Should -Be $rawOutput } + + It "Should have the expected type" { + $readmeFileString.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Content' + } } Context 'For getting raw (string) file contents' { - $readmeFileString = Get-GitHubContent -OwnerName $script:ownerName -RepositoryName $repo.name -Path $readmeFileName -MediaType Raw -ResultAsString It "Should have the expected content" { $readmeFileString | Should -Be $rawOutput } + + It "Should have the expected type" { + $readmeFileString.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Content' + } } Context 'For getting html (byte) file contents' { - $readmeFileBytes = Get-GitHubContent -OwnerName $script:ownerName -RepositoryName $repo.name -Path $readmeFileName -MediaType Html $readmeFileString = [System.Text.Encoding]::UTF8.GetString($readmeFileBytes) @@ -146,10 +167,13 @@ try $readmeNoBreaks.StartsWith($htmlOutputStart) | Should -BeTrue $readmeNoBreaks.IndexOf($repoGuid) | Should -BeGreaterOrEqual 0 } + + It "Should have the expected type" { + $readmeNoBreaks.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Content' + } } Context 'For getting html (string) file contents' { - $readmeFileString = Get-GitHubContent -OwnerName $script:ownerName -RepositoryName $repo.name -Path $readmeFileName -MediaType Html -ResultAsString # Replace newlines with empty for comparison purposes @@ -160,21 +184,27 @@ try $readmeNoBreaks.StartsWith($htmlOutputStart) | Should -BeTrue $readmeNoBreaks.IndexOf($repoGuid) | Should -BeGreaterOrEqual 0 } + + It "Should have the expected type" { + $readmeFileString.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Content' + } } Context 'For getting object (default) file result' { - $readmeFileObject = Get-GitHubContent -OwnerName $script:ownerName -RepositoryName $repo.name -Path $readmeFileName It "Should have the expected name" { $readmeFileObject.name | Should -Be $readmeFileName } + It "Should have the expected path" { $readmeFileObject.path | Should -Be $readmeFileName } + It "Should have the expected type" { $readmeFileObject.type | Should -Be "file" } + It "Should have the expected encoding" { $readmeFileObject.encoding | Should -Be "base64" } @@ -184,10 +214,13 @@ try $readmeFileString = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($readmeFileObject.content)) $readmeFileString | Should -Be $rawOutput } + + It "Should have the expected type" { + $readmeFileObject.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + } } Context 'For getting object file result as string' { - $readmeFileObject = Get-GitHubContent -OwnerName $script:ownerName -RepositoryName $repo.name -Path $readmeFileName -MediaType Object -ResultAsString It "Should have the expected name" { @@ -206,6 +239,10 @@ try It "Should have the expected content" { $readmeFileObject.contentAsString | Should -Be $rawOutput } + + It "Should have the expected type" { + $readmeFileObject.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + } } } } diff --git a/Tests/GitHubIssues.tests.ps1 b/Tests/GitHubIssues.tests.ps1 index 2f8f8624..21b4dd30 100644 --- a/Tests/GitHubIssues.tests.ps1 +++ b/Tests/GitHubIssues.tests.ps1 @@ -161,6 +161,7 @@ try for ($i = 0; $i -lt 4; $i++) { $newIssues += New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([Guid]::NewGuid().Guid) + Start-Sleep -Seconds 1 # Needed to ensure that there is a unique creation timestamp between issues } $newIssues[0] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[0].number -State Closed diff --git a/Tests/GitHubMiscellaneous.tests.ps1 b/Tests/GitHubMiscellaneous.tests.ps1 index 877e4de1..26654c11 100644 --- a/Tests/GitHubMiscellaneous.tests.ps1 +++ b/Tests/GitHubMiscellaneous.tests.ps1 @@ -17,7 +17,249 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { - # TODO + Describe 'Get-GitHubRateLimit' { + Context 'Is working' { + $result = Get-GitHubRateLimit + + It 'Has the expected type' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.RateLimit' + } + } + } + + Describe 'ConvertFrom-GitHubMarkdown' { + BeforeAll { + $markdown = '**PowerShellForGitHub**' + $expectedHtml = '

PowerShellForGitHub

' + } + + Context 'Works with the parameter' { + $result = ConvertFrom-GitHubMarkdown -Content $markdown + + It 'Has the expected result' { + # Replace newlines with empty for comparison purposes + $result.Replace("`n", "").Replace("`r", "") | Should -Be $expectedHtml + } + } + + Context 'Works with the pipeline' { + $result = $markdown | ConvertFrom-GitHubMarkdown + + It 'Has the expected result' { + # Replace newlines with empty for comparison purposes + $result.Replace("`n", "").Replace("`r", "") | Should -Be $expectedHtml + } + } + } + + Describe 'Get-GitHubLicense' { + Context 'Can get the license for a repo with parameters' { + $result = Get-GitHubLicense -OwnerName 'PowerShell' -RepositoryName 'PowerShell' + + It 'Has the expected result' { + $result.license.key | Should -Be 'mit' + } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + $result.LicenseKey | Should -Be $result.license.key + $result.license.PSObject.TypeNames[0] | Should -Be 'GitHub.License' + } + } + + Context 'Can get the license for a repo with the repo on the pipeline' { + $result = Get-GitHubRepository -OwnerName 'PowerShell' -RepositoryName 'PowerShell' | + Get-GitHubLicense + + It 'Has the expected result' { + $result.license.key | Should -Be 'mit' + } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + $result.LicenseKey | Should -Be $result.license.key + $result.license.PSObject.TypeNames[0] | Should -Be 'GitHub.License' + } + } + + Context 'Can get all of the licenses' { + $results = @(Get-GitHubLicense) + + It 'Has the expected result' { + # The number of licenses on GitHub is unlikely to remain static. + # Let's just make sure that we have a few results + $results.Count | Should -BeGreaterThan 3 + } + + It 'Has the expected type and additional properties' { + foreach ($license in $results) + { + $license.PSObject.TypeNames[0] | Should -Be 'GitHub.License' + $license.LicenseKey | Should -Be $license.key + } + } + } + + Context 'Can get a specific license' { + $result = Get-GitHubLicense -Key 'mit' + + It 'Has the expected result' { + $result.key | Should -Be 'mit' + } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.License' + $result.LicenseKey | Should -Be $result.key + } + + $again = $result | Get-GitHubLicense + It 'Has the expected result' { + $again.key | Should -Be 'mit' + } + + It 'Has the expected type and additional properties' { + $again.PSObject.TypeNames[0] | Should -Be 'GitHub.License' + $again.LicenseKey | Should -Be $again.key + } + } + } + + Describe 'Get-GitHubEmoji' { + Context 'Is working' { + $result = Get-GitHubEmoji + + It 'Has the expected type' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Emoji' + } + } + } + + Describe 'Get-GitHubCodeOfConduct' { + Context 'Can get the code of conduct for a repo with parameters' { + $result = Get-GitHubCodeOfConduct -OwnerName 'PowerShell' -RepositoryName 'PowerShell' + + It 'Has the expected result' { + $result.key | Should -Be 'other' + } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' + $result.CodeOfConductKey | Should -Be $result.key + } + } + + Context 'Can get the code of conduct for a repo with the repo on the pipeline' { + $result = Get-GitHubRepository -OwnerName 'PowerShell' -RepositoryName 'PowerShell' | + Get-GitHubCodeOfConduct + + It 'Has the expected result' { + $result.key | Should -Be 'other' + } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' + $result.CodeOfConductKey | Should -Be $result.key + } + } + + Context 'Can get all of the codes of conduct' { + $results = @(Get-GitHubCodeOfConduct) + + It 'Has the expected results' { + # The number of codes of conduct on GitHub is unlikely to remain static. + # Let's just make sure that we have a couple results + $results.Count | Should -BeGreaterOrEqual 2 + } + + It 'Has the expected type and additional properties' { + foreach ($item in $results) + { + $item.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' + $item.CodeOfConductKey | Should -Be $item.key + } + } + } + + Context 'Can get a specific code of conduct' { + $key = 'contributor_covenant' + $result = Get-GitHubCodeOfConduct -Key $key + + It 'Has the expected result' { + $result.key | Should -Be $key + } + + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' + $result.CodeOfConductKey | Should -Be $result.key + } + + $again = $result | Get-GitHubCodeOfConduct + It 'Has the expected result' { + $again.key | Should -Be $key + } + + It 'Has the expected type and additional properties' { + $again.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' + $again.CodeOfConductKey | Should -Be $again.key + } + } + } + + Describe 'Get-GitHubGitIgnore' { + Context 'Gets all the known .gitignore files' { + $result = Get-GitHubGitIgnore + + It 'Has the expected values' { + # The number of .gitignore files on GitHub is unlikely to remain static. + # Let's just make sure that we have a bunch of results + $result.Count | Should -BeGreaterOrEqual 5 + } + It 'Has the expected type' { + $result.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Gitignore' + } + } + + Context 'Gets a specific one via parameter' { + $name = 'C' + $result = Get-GitHubGitIgnore -Name $name + + It 'Has the expected value' { + $result.name | Should -Be $name + $result.source | Should -Not -BeNullOrEmpty + } + + It 'Has the expected type' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Gitignore' + } + } + + Context 'Gets a specific one via the pipeline' { + $name = 'C' + $result = $name | Get-GitHubGitIgnore + + It 'Has the expected value' { + $result.name | Should -Be $name + $result.source | Should -Not -BeNullOrEmpty + } + + It 'Has the expected type' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Gitignore' + } + } + + Context 'Gets a specific one as raw content via the pipeline' { + $name = 'C' + $result = $name | Get-GitHubGitIgnore -RawContent + + It 'Has the expected value' { + $result | Should -Not -BeNullOrEmpty + } + + It 'Has the expected type' { + $result.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Gitignore' + } + } + } } finally { diff --git a/Tests/GitHubRepositoryTraffic.tests.ps1 b/Tests/GitHubRepositoryTraffic.tests.ps1 index 39d8aa32..7136ee0a 100644 --- a/Tests/GitHubRepositoryTraffic.tests.ps1 +++ b/Tests/GitHubRepositoryTraffic.tests.ps1 @@ -29,12 +29,12 @@ try Context 'When initially created, there are no referrers' { It 'Should return expected number of referrers' { $traffic = Get-GitHubReferrerTraffic -Uri $repo.svn_url - $traffic.Count | Should -Be 0 + $traffic | Should -BeNullOrEmpty } It 'Should have the expected type (via pipeline)' { $traffic = $repo | Get-GitHubReferrerTraffic - $traffic.PSObject.TypeNames[0] | Should -Be 'GitHub.ReferrerTraffic' + $traffic | Should -BeNullOrEmpty } } } @@ -51,12 +51,12 @@ try Context 'Getting the popular content over the last 14 days' { It 'Should have no traffic since it was just created' { $traffic = Get-GitHubPathTraffic -Uri $repo.svn_url - $traffic.Count | Should -Be 0 + $traffic | Should -BeNullOrEmpty } It 'Should have the expected type (via pipeline)' { $traffic = $repo | Get-GitHubPathTraffic - $traffic.PSObject.TypeNames[0] | Should -Be 'GitHub.PathTraffic' + $traffic | Should -BeNullOrEmpty } } } @@ -83,7 +83,7 @@ try } } - Describe 'Testing the view traffic on a repository' { + Describe 'Testing the clone traffic on a repository' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit } @@ -98,7 +98,7 @@ try $traffic.Count | Should -Be 0 } - It 'Should have the expected type (via pipeline)' { + It 'Should have no clones since it was just created (via pipeline)' { $traffic = $repo | Get-GitHubCloneTraffic $traffic.PSObject.TypeNames[0] | Should -Be 'GitHub.CloneTraffic' } From 6b15d1d67dcffba5714254d069a16b613206956d Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 16 Jun 2020 02:50:03 -0700 Subject: [PATCH 70/80] Update GitHubMiscellaneous tests to be compatible with Pester 5 --- Tests/GitHubMiscellaneous.tests.ps1 | 410 +++++++++++++++++----------- 1 file changed, 245 insertions(+), 165 deletions(-) diff --git a/Tests/GitHubMiscellaneous.tests.ps1 b/Tests/GitHubMiscellaneous.tests.ps1 index 26654c11..7be6eb96 100644 --- a/Tests/GitHubMiscellaneous.tests.ps1 +++ b/Tests/GitHubMiscellaneous.tests.ps1 @@ -11,262 +11,342 @@ 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') - -try -{ - Describe 'Get-GitHubRateLimit' { - Context 'Is working' { +Describe 'Get-GitHubRateLimit' { + BeforeAll { + # 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') + } + + AfterAll { + # Restore the user's configuration to its pre-test state + Restore-GitHubConfiguration -Path $script:originalConfigFile + $script:originalConfigFile = $null + } + + Context 'Is working' { + BeforeAll { $result = Get-GitHubRateLimit + } - It 'Has the expected type' { - $result.PSObject.TypeNames[0] | Should -Be 'GitHub.RateLimit' - } + It 'Has the expected type' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.RateLimit' } } +} + +Describe 'ConvertFrom-GitHubMarkdown' { + BeforeAll { + # 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') + } + + AfterAll { + # Restore the user's configuration to its pre-test state + Restore-GitHubConfiguration -Path $script:originalConfigFile + $script:originalConfigFile = $null + } - Describe 'ConvertFrom-GitHubMarkdown' { + Context 'Works with the parameter' { BeforeAll { $markdown = '**PowerShellForGitHub**' $expectedHtml = '

PowerShellForGitHub

' } - Context 'Works with the parameter' { + It 'Has the expected result as a parameter' { $result = ConvertFrom-GitHubMarkdown -Content $markdown - It 'Has the expected result' { - # Replace newlines with empty for comparison purposes - $result.Replace("`n", "").Replace("`r", "") | Should -Be $expectedHtml - } + # Replace newlines with empty for comparison purposes + $result.Replace("`n", "").Replace("`r", "") | Should -Be $expectedHtml } - Context 'Works with the pipeline' { + It 'Has the expected result with the pipeline' { $result = $markdown | ConvertFrom-GitHubMarkdown - It 'Has the expected result' { - # Replace newlines with empty for comparison purposes - $result.Replace("`n", "").Replace("`r", "") | Should -Be $expectedHtml - } + # Replace newlines with empty for comparison purposes + $result.Replace("`n", "").Replace("`r", "") | Should -Be $expectedHtml } } +} + +Describe 'Get-GitHubLicense' { + BeforeAll { + # 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') + } - Describe 'Get-GitHubLicense' { - Context 'Can get the license for a repo with parameters' { + AfterAll { + # Restore the user's configuration to its pre-test state + Restore-GitHubConfiguration -Path $script:originalConfigFile + $script:originalConfigFile = $null + } + + Context 'Can get the license for a repo with parameters' { + BeforeAll { $result = Get-GitHubLicense -OwnerName 'PowerShell' -RepositoryName 'PowerShell' + } - It 'Has the expected result' { - $result.license.key | Should -Be 'mit' - } + It 'Has the expected result' { + $result.license.key | Should -Be 'mit' + } - It 'Has the expected type and additional properties' { - $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' - $result.LicenseKey | Should -Be $result.license.key - $result.license.PSObject.TypeNames[0] | Should -Be 'GitHub.License' - } + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + $result.LicenseKey | Should -Be $result.license.key + $result.license.PSObject.TypeNames[0] | Should -Be 'GitHub.License' } + } - Context 'Can get the license for a repo with the repo on the pipeline' { - $result = Get-GitHubRepository -OwnerName 'PowerShell' -RepositoryName 'PowerShell' | - Get-GitHubLicense + Context 'Can get the license for a repo with the repo on the pipeline' { + BeforeAll { + $result = Get-GitHubRepository -OwnerName 'PowerShell' -RepositoryName 'PowerShell' | Get-GitHubLicense + } - It 'Has the expected result' { - $result.license.key | Should -Be 'mit' - } + It 'Has the expected result' { + $result.license.key | Should -Be 'mit' + } - It 'Has the expected type and additional properties' { - $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' - $result.LicenseKey | Should -Be $result.license.key - $result.license.PSObject.TypeNames[0] | Should -Be 'GitHub.License' - } + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + $result.LicenseKey | Should -Be $result.license.key + $result.license.PSObject.TypeNames[0] | Should -Be 'GitHub.License' } + } - Context 'Can get all of the licenses' { + Context 'Can get all of the licenses' { + BeforeAll { $results = @(Get-GitHubLicense) + } - It 'Has the expected result' { - # The number of licenses on GitHub is unlikely to remain static. - # Let's just make sure that we have a few results - $results.Count | Should -BeGreaterThan 3 - } + It 'Has the expected result' { + # The number of licenses on GitHub is unlikely to remain static. + # Let's just make sure that we have a few results + $results.Count | Should -BeGreaterThan 3 + } - It 'Has the expected type and additional properties' { - foreach ($license in $results) - { - $license.PSObject.TypeNames[0] | Should -Be 'GitHub.License' - $license.LicenseKey | Should -Be $license.key - } + It 'Has the expected type and additional properties' { + foreach ($license in $results) + { + $license.PSObject.TypeNames[0] | Should -Be 'GitHub.License' + $license.LicenseKey | Should -Be $license.key } } + } - Context 'Can get a specific license' { + Context 'Can get a specific license' { + BeforeAll { $result = Get-GitHubLicense -Key 'mit' + $again = $result | Get-GitHubLicense + } - It 'Has the expected result' { - $result.key | Should -Be 'mit' - } + It 'Has the expected result' { + $result.key | Should -Be 'mit' + } - It 'Has the expected type and additional properties' { - $result.PSObject.TypeNames[0] | Should -Be 'GitHub.License' - $result.LicenseKey | Should -Be $result.key - } + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.License' + $result.LicenseKey | Should -Be $result.key + } - $again = $result | Get-GitHubLicense - It 'Has the expected result' { - $again.key | Should -Be 'mit' - } + It 'Has the expected result' { + $again.key | Should -Be 'mit' + } - It 'Has the expected type and additional properties' { - $again.PSObject.TypeNames[0] | Should -Be 'GitHub.License' - $again.LicenseKey | Should -Be $again.key - } + It 'Has the expected type and additional properties' { + $again.PSObject.TypeNames[0] | Should -Be 'GitHub.License' + $again.LicenseKey | Should -Be $again.key } } +} - Describe 'Get-GitHubEmoji' { - Context 'Is working' { +Describe 'Get-GitHubEmoji' { + BeforeAll { + # 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') + } + + AfterAll { + # Restore the user's configuration to its pre-test state + Restore-GitHubConfiguration -Path $script:originalConfigFile + $script:originalConfigFile = $null + } + + Context 'Is working' { + BeforeAll { $result = Get-GitHubEmoji + } - It 'Has the expected type' { - $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Emoji' - } + It 'Has the expected type' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Emoji' } } +} + +Describe 'Get-GitHubCodeOfConduct' { + BeforeAll { + # 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') + } - Describe 'Get-GitHubCodeOfConduct' { - Context 'Can get the code of conduct for a repo with parameters' { + AfterAll { + # Restore the user's configuration to its pre-test state + Restore-GitHubConfiguration -Path $script:originalConfigFile + $script:originalConfigFile = $null + } + + Context 'Can get the code of conduct for a repo with parameters' { + BeforeAll { $result = Get-GitHubCodeOfConduct -OwnerName 'PowerShell' -RepositoryName 'PowerShell' + } - It 'Has the expected result' { - $result.key | Should -Be 'other' - } + It 'Has the expected result' { + $result.key | Should -Be 'other' + } - It 'Has the expected type and additional properties' { - $result.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' - $result.CodeOfConductKey | Should -Be $result.key - } + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' + $result.CodeOfConductKey | Should -Be $result.key } + } - Context 'Can get the code of conduct for a repo with the repo on the pipeline' { - $result = Get-GitHubRepository -OwnerName 'PowerShell' -RepositoryName 'PowerShell' | - Get-GitHubCodeOfConduct + Context 'Can get the code of conduct for a repo with the repo on the pipeline' { + BeforeAll { + $result = Get-GitHubRepository -OwnerName 'PowerShell' -RepositoryName 'PowerShell' | Get-GitHubCodeOfConduct + } - It 'Has the expected result' { - $result.key | Should -Be 'other' - } + It 'Has the expected result' { + $result.key | Should -Be 'other' + } - It 'Has the expected type and additional properties' { - $result.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' - $result.CodeOfConductKey | Should -Be $result.key - } + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' + $result.CodeOfConductKey | Should -Be $result.key } + } - Context 'Can get all of the codes of conduct' { + Context 'Can get all of the codes of conduct' { + BeforeAll { $results = @(Get-GitHubCodeOfConduct) + } - It 'Has the expected results' { - # The number of codes of conduct on GitHub is unlikely to remain static. - # Let's just make sure that we have a couple results - $results.Count | Should -BeGreaterOrEqual 2 - } + It 'Has the expected results' { + # The number of codes of conduct on GitHub is unlikely to remain static. + # Let's just make sure that we have a couple results + $results.Count | Should -BeGreaterOrEqual 2 + } - It 'Has the expected type and additional properties' { - foreach ($item in $results) - { - $item.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' - $item.CodeOfConductKey | Should -Be $item.key - } + It 'Has the expected type and additional properties' { + foreach ($item in $results) + { + $item.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' + $item.CodeOfConductKey | Should -Be $item.key } } + } - Context 'Can get a specific code of conduct' { + Context 'Can get a specific code of conduct' { + BeforeAll { $key = 'contributor_covenant' $result = Get-GitHubCodeOfConduct -Key $key + $again = $result | Get-GitHubCodeOfConduct + } - It 'Has the expected result' { - $result.key | Should -Be $key - } + It 'Has the expected result' { + $result.key | Should -Be $key + } - It 'Has the expected type and additional properties' { - $result.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' - $result.CodeOfConductKey | Should -Be $result.key - } + It 'Has the expected type and additional properties' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' + $result.CodeOfConductKey | Should -Be $result.key + } - $again = $result | Get-GitHubCodeOfConduct - It 'Has the expected result' { - $again.key | Should -Be $key - } + It 'Has the expected result' { + $again.key | Should -Be $key + } - It 'Has the expected type and additional properties' { - $again.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' - $again.CodeOfConductKey | Should -Be $again.key - } + It 'Has the expected type and additional properties' { + $again.PSObject.TypeNames[0] | Should -Be 'GitHub.CodeOfConduct' + $again.CodeOfConductKey | Should -Be $again.key } } +} - Describe 'Get-GitHubGitIgnore' { - Context 'Gets all the known .gitignore files' { +Describe 'Get-GitHubGitIgnore' { + BeforeAll { + # 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') + } + + AfterAll { + # Restore the user's configuration to its pre-test state + Restore-GitHubConfiguration -Path $script:originalConfigFile + $script:originalConfigFile = $null + } + + Context 'Gets all the known .gitignore files' { + BeforeAll { $result = Get-GitHubGitIgnore + } - It 'Has the expected values' { - # The number of .gitignore files on GitHub is unlikely to remain static. - # Let's just make sure that we have a bunch of results - $result.Count | Should -BeGreaterOrEqual 5 - } - It 'Has the expected type' { - $result.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Gitignore' - } + It 'Has the expected values' { + # The number of .gitignore files on GitHub is unlikely to remain static. + # Let's just make sure that we have a bunch of results + $result.Count | Should -BeGreaterOrEqual 5 + } + It 'Has the expected type' { + $result.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Gitignore' } + } - Context 'Gets a specific one via parameter' { + Context 'Gets a specific one via parameter' { + BeforeAll { $name = 'C' $result = Get-GitHubGitIgnore -Name $name + } - It 'Has the expected value' { - $result.name | Should -Be $name - $result.source | Should -Not -BeNullOrEmpty - } + It 'Has the expected value' { + $result.name | Should -Be $name + $result.source | Should -Not -BeNullOrEmpty + } - It 'Has the expected type' { - $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Gitignore' - } + It 'Has the expected type' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Gitignore' } + } - Context 'Gets a specific one via the pipeline' { + Context 'Gets a specific one via the pipeline' { + BeforeAll { $name = 'C' $result = $name | Get-GitHubGitIgnore + } - It 'Has the expected value' { - $result.name | Should -Be $name - $result.source | Should -Not -BeNullOrEmpty - } + It 'Has the expected value' { + $result.name | Should -Be $name + $result.source | Should -Not -BeNullOrEmpty + } - It 'Has the expected type' { - $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Gitignore' - } + It 'Has the expected type' { + $result.PSObject.TypeNames[0] | Should -Be 'GitHub.Gitignore' } + } - Context 'Gets a specific one as raw content via the pipeline' { + Context 'Gets a specific one as raw content via the pipeline' { + BeforeAll { $name = 'C' $result = $name | Get-GitHubGitIgnore -RawContent + } - It 'Has the expected value' { - $result | Should -Not -BeNullOrEmpty - } + It 'Has the expected value' { + $result | Should -Not -BeNullOrEmpty + } - It 'Has the expected type' { - $result.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Gitignore' - } + It 'Has the expected type' { + $result.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Gitignore' } } } -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 e62d395c2af258a04251d04ba9e3aecad5be744b Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 16 Jun 2020 10:52:50 -0700 Subject: [PATCH 71/80] Moving Contents type setting to its own function --- GitHubContents.ps1 | 36 +++++++++++++++++++++++++++++++++++- GitHubMiscellaneous.ps1 | 5 +++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/GitHubContents.ps1 b/GitHubContents.ps1 index d28f942b..19e4034e 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -163,8 +163,42 @@ if ($MediaType -eq 'Object') { - $result.PSObject.TypeNames.Insert(0, $script:GitHubContentTypeName) + $null = $result | Add-GitHubContentAdditionalProperties } return $result } + +filter Add-GitHubContentAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Content objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. +#> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubContentTypeName + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + Write-Output $item + } +} \ No newline at end of file diff --git a/GitHubMiscellaneous.ps1 b/GitHubMiscellaneous.ps1 index 3ad499dc..ff7575fc 100644 --- a/GitHubMiscellaneous.ps1 +++ b/GitHubMiscellaneous.ps1 @@ -323,11 +323,12 @@ filter Get-GitHubLicense { if ($PSCmdlet.ParameterSetName -in ('Elements', 'Uri')) { - # Convert from base64 + $null = $item | Add-GitHubContentAdditionalProperties + + # Add the decoded Base64 content directly to the object as an additional String property $decoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($item.content)) Add-Member -InputObject $item -NotePropertyName "contentAsString" -NotePropertyValue $decoded - $item.PSObject.TypeNames.Insert(0, $script:GitHubContentTypeName) $item.license.PSObject.TypeNames.Insert(0, $script:GitHubLicenseTypeName) if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) From 6d5f83db0ba243ff933b0ca79bd2ad0529d013d7 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 16 Jun 2020 14:15:24 -0700 Subject: [PATCH 72/80] Updating documentation --- .github/PULL_REQUEST_TEMPLATE.md | 6 +-- CONTRIBUTING.md | 64 ++++++++++++++++++++++++++++++-- README.md | 60 ++++++++++++++++++++++-------- USAGE.md | 61 +++++++++++++++++++++++++++--- 4 files changed, 164 insertions(+), 27 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index b5ecc397..d4ac695e 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -32,10 +32,10 @@ --> - [ ] You actually ran the code that you just wrote, especially if you did just "one last quick change". - [ ] Comment-based help added/updated, including examples. -- [ ] [Static analysis](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#static-analysis) -is reporting back clean. +- [ ] [Static analysis](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#static-analysis) is reporting back clean. - [ ] New/changed code adheres to our [coding guidelines](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#coding-guidelines). +- [ ] New/changed code continues to [support the pipeline](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#pipeline-support). - [ ] Changes to the manifest file follow the [manifest guidance](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#module-manifest). -- [ ] Unit tests were added/updated and are all passing. See [testing guidelines](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#testing). +- [ ] Unit tests were added/updated and are all passing. See [testing guidelines](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#testing). This includes making sure that all pipeline input variations have been covered. - [ ] Relevant usage examples have been added/updated in [USAGE.md](https://github.com/microsoft/PowerShellForGitHub/blob/master/USAGE.md). - [ ] If desired, ensure your name is added to our [Contributors list](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#contributors) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3bb7e8d8..eab33dce 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,6 +23,7 @@ Looking for information on how to use this module? Head on over to [README.md]( * [Adding New Configuration Properties](#adding-new-configuration-properties) * [Code Comments](#code-comments) * [Debugging Tips](#debugging-tips) +* [Pipeline Support](#pipeline-support) * [Testing](#testing) * [Installing Pester](#installing-pester) * [Configuring Your Environment](#configuring-your-environment) @@ -286,8 +287,63 @@ Set-GitHubConfiguration -LogRequestBody ---------- +### Pipeline Support + +This module has comprehensive support for the PowerShell pipeline. It is imperative that all +new functionality added to the module embraces this design. + + * Most functions are declared as a `filter`. This is the equivalent of a `function` with a + where the body of the function is the `process` block, and the `begin/end` blocks are empty. + + * In limited cases where one of the inputs is an array of something, and you specifically want that + to be processed as a single command (like adding a bunch of labels to a single issue at once), + you can implement it as a `function` where you use `begin/process` to gather all of the values + into a single internal array, and then do the actual command execution in the `end` block. A + good example of that which you can follow can be seen with `Add-GitHubIssueLabel`. + + * Any function that requires the repo's `Uri` to be provided should be additionally aliased with + `[Alias('RepositoryUrl')]` and its `[Parameter()]` definition should include `ValueFromPipelineByPropertyName`. + + * Do not use any generic term like `Name` in your parameters. That will end up causing unintended + pipeline issues down the line. For instance, if it's a label, call it `Label`, even though `Name` + would make sense, other objects in the pipeline (like a `GitHub.Respository` object) also have + a `name` property that would conflict. + + * You should plan on adding additional properties to all objects being returned from an API call. + Any object that is specific to a repository should have a `RepositoryUrl` `NoteProperty` added + to it, enabling it to be piped-in to any other command that requires knowing which repository + you're talking about. Additionally, any other property that might be necessary to uniquely + identify that object in a different command should get added properties. For example, with Issues, + we add both an `IssueNumber` property and an `IssueId` property to it, as the Issue commands + need to interact with the `IssueNumber` while the Event commands interact with the `IssueId`. + We prefer to _only_ add additional properties that are believed to be needed as input to other + commands (as opposed to creating alias properties for all of the object's properties). + + * For every major file, you will find an `Add-GitHub*AdditionalProperties` filter method at the end. + If you're writing a new file, you'll need to create this yourself (and model it after an existing + one). The goal of this is that you can simply pipe the output of your `Invoke-GHRestMethod` + directly into this method to update the result with the additional properties, and then return + that modified version to the user. The benefit of this approach is that you can then apply that + filter on child objects within the primary object. For instance, a `GitHub.Issue` has multiple + `GitHub.User` objects, `GitHub.Label` objects, a `GitHub.Milestone` object and more. Within + `Add-GitHubIssueAdditionalProperties`, it just needs to know to call the appropriate + `Add-GitHub*AdditionalProperties` method on the qualifying child properties, without needing to + know anything more about them. + + * That method will also "type" information to each object. This is forward-looking work to ease + support for providing formatting of various object types in the future. + + * To enable debugging issues involving pipeline support, there is an additional configuration + property that you might use: `Set-GitHubConfiguration -DisablePipelineSupport`. That will + prevent the module from adding _any_ additional properties to the objects. + +---------- + ### Testing [![Build status](https://dev.azure.com/ms/PowerShellForGitHub/_apis/build/status/PowerShellForGitHub-CI?branchName=master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master) +[![Azure DevOps tests](https://img.shields.io/azure-devops/tests/ms/PowerShellForGitHub/109/master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master) +[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/ms/PowerShellForGitHub/109/master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master) + #### Installing Pester This module supports testing using the [Pester UT framework](https://github.com/pester/Pester). @@ -350,6 +406,8 @@ There are many more nuances to code-coverage, see #### Automated Tests [![Build status](https://dev.azure.com/ms/PowerShellForGitHub/_apis/build/status/PowerShellForGitHub-CI?branchName=master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master) +[![Azure DevOps tests](https://img.shields.io/azure-devops/tests/ms/PowerShellForGitHub/109/master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master) +[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/ms/PowerShellForGitHub/109/master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master) These test are configured to automatically execute upon any update to the `master` branch of `microsoft/PowerShellForGitHub`. @@ -362,9 +420,9 @@ as well...it is stored, encrypted, within Azure DevOps. It is not accessible fo the CI pipeline. To run the tests locally with your own account, see [configuring-your-environment](#configuring-your-environment). -> NOTE: We're currently encountering issues with the tests successfully running within the pipeline. -> They do complete successfully locally, so please test your changes locally before submitting a -> pull request. +> Your change must successfully pass all tests before they will be merged. While we will run a CI +> build on your behalf for any submitted pull request, it's to your benefit to verify your changes +> locally first. #### New Test Guidelines Your tests should have NO dependencies on an account being set up in a specific way. They should diff --git a/README.md b/README.md index 0332ee91..0488dc54 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/3990/badge)](https://bestpractices.coreinfrastructure.org/projects/3990) [![tweet](https://img.shields.io/twitter/url?url=https%3A%2F%2Ftwitter.com%2FQuackFu)](https://twitter.com/intent/tweet?text=%23PowerShellForGitHub%20%40QuackFu%20&original_referer=https://github.com/microsoft/PowerShellForGitHub)
-[![Build status](https://dev.azure.com/ms/PowerShellForGitHub/_apis/build/status/PowerShellForGitHub-CI?branchName=master)](https://dev.azure.com/ms/PowerShellForGitHub/_build?definitionId=109&_a=summary&repositoryFilter=63&branchFilter=2197) -[![Azure DevOps tests](https://img.shields.io/azure-devops/tests/ms/PowerShellForGitHub/109/master)](https://dev.azure.com/ms/PowerShellForGitHub/_build?definitionId=109&_a=summary&repositoryFilter=63&branchFilter=2197) -[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/ms/PowerShellForGitHub/109/master)](https://dev.azure.com/ms/PowerShellForGitHub/_build?definitionId=109&_a=summary&repositoryFilter=63&branchFilter=2197) +[![Build status](https://dev.azure.com/ms/PowerShellForGitHub/_apis/build/status/PowerShellForGitHub-CI?branchName=master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master) +[![Azure DevOps tests](https://img.shields.io/azure-devops/tests/ms/PowerShellForGitHub/109/master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master) +[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/ms/PowerShellForGitHub/109/master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master)
[![Help Wanted Issues](https://img.shields.io/github/issues/microsoft/PowerShellForGitHub/help%20wanted)](https://github.com/microsoft/PowerShellForGitHub/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) [![GitHub last commit](https://img.shields.io/github/last-commit/microsoft/PowerShellForGitHub)](https://github.com/HowardWolosky/PowerShellForGitHub/commits/master) @@ -35,28 +35,58 @@ ## Overview This is a [PowerShell](https://microsoft.com/powershell) [module](https://technet.microsoft.com/en-us/library/dd901839.aspx) -that provides command-line interaction and automation for the [GitHub v3 API](https://developer.github.com/v3/). +that provides stateless command-line interaction and automation for the +[GitHub v3 API](https://developer.github.com/v3/). + +**Embracing the benefits of PowerShell, it has +[full support for pipelining](./USAGE.md#embracing-the-pipeline), allowing you pipe the output of +virtually any command into any other command within the module.** ---------- ## Current API Support At present, this module can: - * Query issues - * Query [pull requests](https://developer.github.com/v3/pulls/) + * Query, create, update and remove [Repositories](https://developer.github.com/v3/repos/) including + * Query [Branches](https://developer.github.com/v3/repos/branches/) + * Query and create new [Forks](https://developer.github.com/v3/repos/forks/) + * Query/retrieve [Content](https://developer.github.com/v3/repos/contents/) from a repo. + * Query the languages and tags in a repository, and and query/update its topics. + * Change repository ownership. + * Query various [traffic reports](https://developer.github.com/v3/repos/traffic/) including + referral sources and paths, page views and clones. + * Query, create, edit, lock/unlock [Issues](https://developer.github.com/v3/issues/) and + all of their related properties: + * Query, check, add and remove [Assignees](https://developer.github.com/v3/issues/assignees/) + * Query, create, edit and remove [Issue Comments](https://developer.github.com/v3/issues/comments/) + * Query, create, edit and remove [Labels](https://developer.github.com/v3/issues/labels/) + * Query [Events](https://developer.github.com/v3/issues/events/) and the + [timeline](https://developer.github.com/v3/issues/timeline/) + * Query, create, edit and remove [Milestones](https://developer.github.com/v3/issues/milestones/) + * Query and create [Pull Requests](https://developer.github.com/v3/pulls/) * Query [collaborators](https://developer.github.com/v3/repos/collaborators/) * Query [contributors](https://developer.github.com/v3/repos/statistics/) - * Query [organizations](https://developer.github.com/v3/orgs/) - * Query, create, update and remove [Issues](https://developer.github.com/v3/issues/) and - all of their related properties (assignees, comments, events, labels, milestones, timeline) - * Query, create, update and remove [Labels](https://developer.github.com/v3/issues/labels/) - * Query, check, add and remove [Assignees](https://developer.github.com/v3/issues/assignees/) - * Query, create, update and remove [Repositories](https://developer.github.com/v3/repos/) + * Query [organizations](https://developer.github.com/v3/orgs/) and their members. * Query and update [Users](https://developer.github.com/v3/users/) + * Query [Teams](https://developer.github.com/v3/teams/) and their members. + * Query, create, edit and remove [Projects](https://developer.github.com/v3/projects/), along with + [Project Columns](https://developer.github.com/v3/projects/columns/) and + [Project Cards](https://developer.github.com/v3/projects/cards/) + * Query [Releases](https://developer.github.com/v3/repos/releases/) + * Miscellaneous functionality: + * Get all [Codes of Conduct](https://developer.github.com/v3/codes_of_conduct/) as well as that + of a specific repo. + * Get all [GitHub emojis](https://developer.github.com/v3/emojis/) + * Get [gitignore templates](https://developer.github.com/v3/gitignore/) + * Get [commonly used licenses](https://developer.github.com/v3/licenses/) as well as that for + a specific repository. + * [Convert markdown](https://developer.github.com/v3/markdown/) to the equivalent HTML + * Get your current [rate limit](https://developer.github.com/v3/rate_limit/) for API usage. Development is ongoing, with the goal to add broad support for the entire API set. -For a comprehensive look at what work is remaining to be API Complete, refer to [Issue #70](https://github.com/PowerShell/PowerShellForGitHub/issues/70). +For a comprehensive look at what work is remaining to be API Complete, refer to +[Issue #70](https://github.com/microsoft/PowerShellForGitHub/issues/70). Review [examples](USAGE.md#examples) to see how the module can be used to accomplish some of these tasks. @@ -135,7 +165,7 @@ Set-GitHubConfiguration -ApiHostName "github.contoso.com" Example command: ```powershell -$issues = Get-GitHubIssue -Uri 'https://github.com/PowerShell/PowerShellForGitHub' +$issues = Get-GitHubIssue -Uri 'https://github.com/microsoft/PowerShellForGitHub' ``` For more example commands, please refer to [USAGE](USAGE.md#examples). @@ -147,7 +177,7 @@ For more example commands, please refer to [USAGE](USAGE.md#examples). Please see the [Contribution Guide](CONTRIBUTING.md) for information on how to develop and contribute. -If you have any problems, please consult [GitHub Issues](https://github.com/PowerShell/PowerShellForGitHub/issues) +If you have any problems, please consult [GitHub Issues](https://github.com/microsoft/PowerShellForGitHub/issues) to see if has already been discussed. If you do not see your problem captured, please file [feedback](CONTRIBUTING.md#feedback). diff --git a/USAGE.md b/USAGE.md index a02ee3c2..c29124b7 100644 --- a/USAGE.md +++ b/USAGE.md @@ -5,6 +5,9 @@ * [Logging](#logging) * [Telemetry](#telemetry) * [Examples](#examples) + * [Overview](#overview) + * [Embracing the pipeline](#embracing-the-pipeline) + * [Pipeline Example](#pipeline-example) * [Analytics](#analytics) * [Querying Issues](#querying-issues) * [Querying Pull Requests](#querying-pull-requests) @@ -104,12 +107,6 @@ In order to track usage, gauge performance and identify areas for improvement, t employed during execution of commands within this module (via Application Insights). For more information, refer to the [Privacy Policy](README.md#privacy-policy). -> You may notice some needed assemblies for communicating with Application Insights being -> downloaded on first run of a command within each PowerShell session. The -> [automatic dependency downloads](#automatic-dependency-downloads) section of the setup -> documentation describes how you can avoid having to always re-download the telemetry assemblies -> in the future. - We recommend that you always leave the telemetry feature enabled, but a situation may arise where it must be disabled for some reason. In this scenario, you can disable telemetry by calling: @@ -161,6 +158,58 @@ us for analysis. We expose it here for complete transparency. ## Examples +### Overview + +#### Embracing the Pipeline + +One of the major benefits of PowerShell is its pipeline -- allowing you to "pipe" a saved value or +the output of a previous command directly into the next command. There is absolutely no requirement +to make use of it in order to use the module, but you will find that the module becomes increasingly +easier to use and more powerful if you do. + +Some of the examples that you find below will show how you might be able to use it to your advantage. + +#### Pipeline Example + +Most commands require you to pass in either a `Uri` for the repository or its elements (the +`OwnerName` and `RepositoryName`). If you keep around the repo that you're interacting with in +a local var (like `$repo`), then you can pipe that into any command to avoid having to specify that +information. Further, piping in a more specific object (like an `Issue`) allows you to avoid even +specifying the relevant Issue number. + +Without the pipeline, an interaction log might look like this: + +```powershell +# Find all of the issues that have the label "repro steps needed" and add a new comment to those +# issues asking for an update. +$issues = @(Get-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label 'repro steps needed') +foreach ($issue in $issues) +{ + $params = @{ + 'OwnerName' = 'microsoft' + 'RepositoryName' = 'PowerShellForGitHub' + 'Issue' = $issue.number + 'Body' = 'Any update on those repro steps?' + } + + New-GitHubIssueComment @params +} + +``` + +With the pipeline, a similar interaction log might look like this: + +```powershell +# Find all of the issues that have the label "repro steps needed" and add a new comment to those +# issues asking for an update. +Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub | + Get-GitHubIssue -Label 'repro steps needed' | + New-GitHubIssueComment -Body 'Any update on those repro steps?' +``` + +We encourage you to explore how embracing the pipeline may simplify your code and interaction +with GitHub using this module! + ### Analytics #### Querying Issues From 3d3acfd4da9e39935586197de806a423c03db507 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 16 Jun 2020 14:17:59 -0700 Subject: [PATCH 73/80] Further doc update --- CONTRIBUTING.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eab33dce..ccad1c5d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -331,7 +331,10 @@ new functionality added to the module embraces this design. know anything more about them. * That method will also "type" information to each object. This is forward-looking work to ease - support for providing formatting of various object types in the future. + support for providing formatting of various object types in the future. That type should be + defined at the top of the current file at the script level (see other files for an example), + and you should be sure to both specify it in the `.OUTPUTS` section of the Comment Based Help (CBH) + for the command, as well as with `[OutputType({$script:GitHubUserTypeName})]` (for example). * To enable debugging issues involving pipeline support, there is an additional configuration property that you might use: `Set-GitHubConfiguration -DisablePipelineSupport`. That will From 1bc229c5927aa1547eae79849946687e59fcbdd1 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 16 Jun 2020 14:33:03 -0700 Subject: [PATCH 74/80] Migrating all accept header usage to come from constants. This also fixes a bug with the `sailor-v` accept header which had been spelled wrong. --- GitHubAssignees.ps1 | 4 ++-- GitHubCore.ps1 | 5 ++++- GitHubEvents.ps1 | 2 +- GitHubIssues.ps1 | 4 ++-- GitHubProjectCards.ps1 | 10 +++++----- GitHubProjectColumns.ps1 | 10 +++++----- GitHubProjects.ps1 | 8 ++++---- GitHubPullRequests.ps1 | 2 +- GitHubTeams.ps1 | 2 +- GitHubUsers.ps1 | 2 +- 10 files changed, 26 insertions(+), 23 deletions(-) diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index b5845d2d..76e5705d 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -356,7 +356,7 @@ function New-GitHubAssignee 'Method' = 'Post' 'Description' = "Add assignees to issue $Issue for $RepositoryName" 'AccessToken' = $AccessToken - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'AcceptHeader' = $script:symmetraAcceptHeader 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) @@ -527,7 +527,7 @@ function Remove-GitHubAssignee 'Method' = 'Delete' 'Description' = "Removing assignees from issue $Issue for $RepositoryName" 'AccessToken' = $AccessToken - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'AcceptHeader' = $script:symmetraAcceptHeader 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 28292f75..9c92c606 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -6,12 +6,15 @@ mediaTypeVersion = 'v3' baptisteAcceptHeader = 'application/vnd.github.baptiste-preview+json' dorianAcceptHeader = 'application/vnd.github.dorian-preview+json' + hagarAcceptHeader = 'application/vnd.github.hagar-preview+json' + hellcatAcceptHeader = 'application/vnd.github.hellcat-preview+json' + inertiaAcceptHeader = 'application/vnd.github.inertia-preview+json' londonAcceptHeader = 'application/vnd.github.london-preview+json' machineManAcceptHeader = 'application/vnd.github.machine-man-preview' mercyAcceptHeader = 'application/vnd.github.mercy-preview+json' mockingbirdAcceptHeader = 'application/vnd.github.mockingbird-preview' nebulaAcceptHeader = 'application/vnd.github.nebula-preview+json' - sailerVAcceptHeader = 'application/vnd.github.sailer-v-preview+json' + sailorVAcceptHeader = 'application/vnd.github.sailor-v-preview+json' scarletWitchAcceptHeader = 'application/vnd.github.scarlet-witch-preview+json' squirrelGirlAcceptHeader = 'application/vnd.github.squirrel-girl-preview' starfoxAcceptHeader = 'application/vnd.github.starfox-preview+json' diff --git a/GitHubEvents.ps1 b/GitHubEvents.ps1 index 9bfab784..0b618729 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -117,7 +117,7 @@ filter Get-GitHubEvent $acceptHeaders = @( $script:starfoxAcceptHeader, - $script:sailerVAcceptHeader, + $script:sailorVAcceptHeader, $script:symmetraAcceptHeader, $script:machineManAcceptHeader) diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index 7e57418c..8aaf3acc 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -858,7 +858,7 @@ filter Lock-GitHubIssue 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Put' 'Description' = "Locking Issue #$Issue on $RepositoryName" - 'AcceptHeader' = 'application/vnd.github.sailor-v-preview+json' + 'AcceptHeader' = $script:sailorVAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -953,7 +953,7 @@ filter Unlock-GitHubIssue 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/lock" 'Method' = 'Delete' 'Description' = "Unlocking Issue #$Issue on $RepositoryName" - 'AcceptHeader' = 'application/vnd.github.sailor-v-preview+json' + 'AcceptHeader' = $script:sailorVAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties diff --git a/GitHubProjectCards.ps1 b/GitHubProjectCards.ps1 index 935ed73b..814beda1 100644 --- a/GitHubProjectCards.ps1 +++ b/GitHubProjectCards.ps1 @@ -123,7 +123,7 @@ filter Get-GitHubProjectCard 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubProjectCardAdditionalProperties) @@ -258,7 +258,7 @@ filter New-GitHubProjectCard 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return (Invoke-GHRestMethod @params | Add-GitHubProjectCardAdditionalProperties) @@ -375,7 +375,7 @@ filter Set-GitHubProjectCard 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return (Invoke-GHRestMethod @params | Add-GitHubProjectCardAdditionalProperties) @@ -461,7 +461,7 @@ filter Remove-GitHubProjectCard 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return Invoke-GHRestMethod @params @@ -592,7 +592,7 @@ filter Move-GitHubProjectCard 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return Invoke-GHRestMethod @params diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index 8932bfff..7e3b43ed 100644 --- a/GitHubProjectColumns.ps1 +++ b/GitHubProjectColumns.ps1 @@ -100,7 +100,7 @@ filter Get-GitHubProjectColumn 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubProjectColumnAdditionalProperties) @@ -181,7 +181,7 @@ filter New-GitHubProjectColumn 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return (Invoke-GHRestMethod @params | Add-GitHubProjectColumnAdditionalProperties) @@ -258,7 +258,7 @@ filter Set-GitHubProjectColumn 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return (Invoke-GHRestMethod @params | Add-GitHubProjectColumnAdditionalProperties) @@ -344,7 +344,7 @@ filter Remove-GitHubProjectColumn 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return Invoke-GHRestMethod @params @@ -457,7 +457,7 @@ filter Move-GitHubProjectColumn 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return Invoke-GHRestMethod @params diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 7fd284e5..9446efae 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -189,7 +189,7 @@ filter Get-GitHubProject 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubProjectAdditionalProperties) @@ -351,7 +351,7 @@ filter New-GitHubProject 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return (Invoke-GHRestMethod @params | Add-GitHubProjectAdditionalProperties) @@ -477,7 +477,7 @@ filter Set-GitHubProject 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return (Invoke-GHRestMethod @params | Add-GitHubProjectAdditionalProperties) @@ -568,7 +568,7 @@ filter Remove-GitHubProject 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = 'application/vnd.github.inertia-preview+json' + 'AcceptHeader' = $script:inertiaAcceptHeader } return Invoke-GHRestMethod @params diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index bdd097d5..477d2b28 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -166,7 +166,7 @@ filter Get-GitHubPullRequest $params = @{ 'UriFragment' = $uriFragment + '?' + ($getParams -join '&') 'Description' = $description - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'AcceptHeader' = $script:symmetraAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties diff --git a/GitHubTeams.ps1 b/GitHubTeams.ps1 index 35691c9d..20abcbdc 100644 --- a/GitHubTeams.ps1 +++ b/GitHubTeams.ps1 @@ -128,7 +128,7 @@ filter Get-GitHubTeam $params = @{ 'UriFragment' = $uriFragment - 'AcceptHeader' = 'application/vnd.github.hellcat-preview+json' + 'AcceptHeader' = $script:hellcatAcceptHeader 'Description' = $description 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 9698b478..78e93cdf 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -265,7 +265,7 @@ filter Get-GitHubUserContextualInformation 'UriFragment' = "users/$UserName/hovercard`?" + ($getParams -join '&') 'Method' = 'Get' 'Description' = "Getting hovercard information for $UserName" - 'AcceptHeader' = 'application/vnd.github.hagar-preview+json' + 'AcceptHeader' = $script:hagarAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) From 6f004955b32286a200830714cf4cd858acb128e3 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 16 Jun 2020 15:37:02 -0700 Subject: [PATCH 75/80] Fix milestone support in issues --- GitHubIssues.ps1 | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index 8aaf3acc..51f1b45a 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -75,7 +75,7 @@ filter Get-GitHubIssue all: All milestones will be returned. none: Only issues without milestones will be returned. - .PARAMETER Milestone + .PARAMETER MilestoneNumber Only issues with this milestone will be returned. .PARAMETER AssigneeType @@ -143,6 +143,7 @@ filter Get-GitHubIssue [Alias('RepositoryUrl')] [string] $Uri, + [Parameter(ValueFromPipelineByPropertyName)] [string] $OrganizationName, [ValidateSet('All', 'OwnedAndMember')] @@ -173,13 +174,16 @@ filter Get-GitHubIssue [ValidateSet('Specific', 'All', 'None')] [string] $MilestoneType, - [string] $Milestone, + [Parameter(ValueFromPipelineByPropertyName)] + [int64] $MilestoneNumber, [ValidateSet('Specific', 'All', 'None')] [string] $AssigneeType, [string] $Assignee, + [Parameter(ValueFromPipelineByPropertyName)] + [Alias('UserName')] [string] $Creator, [string] $Mentioned, @@ -280,17 +284,17 @@ filter Get-GitHubIssue { $getParams += 'mentioned=none' } - elseif ([String]::IsNullOrEmpty($Milestone)) + elseif ($PSBoundParameters.ContainsKey('$MilestoneNumber')) { - $message = "MilestoneType was set to [$MilestoneType], but no value for Milestone was provided." + $message = "MilestoneType was set to [$MilestoneType], but no value for MilestoneNumber was provided." Write-Log -Message $message -Level Error throw $message } } - if ($PSBoundParameters.ContainsKey('Milestone')) + if ($PSBoundParameters.ContainsKey('MilestoneNumber')) { - $getParams += "milestone=$Milestone" + $getParams += "milestone=$MilestoneNumber" } if ($PSBoundParameters.ContainsKey('AssigneeType')) @@ -627,7 +631,7 @@ filter Update-GitHubIssue Login(s) for Users to assign to the issue. Provide an empty array to clear all existing assignees. - .PARAMETER Milestone + .PARAMETER MilestoneNumber The number of the milestone to associate this issue with. Set to 0/$null to remove current. @@ -693,7 +697,7 @@ filter Update-GitHubIssue [string[]] $Assignee, - [int64] $Milestone, + [int64] $MilestoneNumber, [string[]] $Label, @@ -726,10 +730,10 @@ filter Update-GitHubIssue if ($PSBoundParameters.ContainsKey('Assignee')) { $hashBody['assignees'] = @($Assignee) } if ($PSBoundParameters.ContainsKey('Label')) { $hashBody['labels'] = @($Label) } if ($PSBoundParameters.ContainsKey('State')) { $hashBody['state'] = $State.ToLower() } - if ($PSBoundParameters.ContainsKey('Milestone')) + if ($PSBoundParameters.ContainsKey('MilestoneNumber')) { - $hashBody['milestone'] = $Milestone - if ($Milestone -in (0, $null)) + $hashBody['milestone'] = $MilestoneNumber + if ($MilestoneNumber -in (0, $null)) { $hashBody['milestone'] = $null } From b6f3a1258ac9b074ea835ab86edf8ca5e87c3fc2 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 16 Jun 2020 17:02:44 -0700 Subject: [PATCH 76/80] Some various cleanup around removing generic 'Name' parameters, etc... --- GitHubOrganizations.ps1 | 37 +++---------------------- GitHubProjectColumns.ps1 | 16 ++++++----- GitHubProjects.ps1 | 15 ++++++----- GitHubPullRequests.ps1 | 2 +- GitHubRepositories.ps1 | 18 +++++-------- GitHubTeams.ps1 | 37 +++---------------------- Tests/GitHubProjectCards.tests.ps1 | 6 ++--- Tests/GitHubProjectColumns.tests.ps1 | 18 ++++++------- Tests/GitHubProjects.tests.ps1 | 40 ++++++++++++++-------------- Tests/GitHubRepositories.tests.ps1 | 2 +- USAGE.md | 4 +-- 11 files changed, 65 insertions(+), 130 deletions(-) diff --git a/GitHubOrganizations.ps1 b/GitHubOrganizations.ps1 index 26a31150..62c8ee2e 100644 --- a/GitHubOrganizations.ps1 +++ b/GitHubOrganizations.ps1 @@ -169,14 +169,6 @@ filter Add-GitHubOrganizationAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. - - .PARAMETER Name - The name of the organization. This information might be obtainable from InputObject, so this - is optional based on what InputObject contains. - - .PARAMETER Id - The ID of the organization. This information might be obtainable from InputObject, so this - is optional based on what InputObject contains. #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] @@ -189,11 +181,7 @@ filter Add-GitHubOrganizationAdditionalProperties [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] - [string] $TypeName = $script:GitHubOrganizationTypeName, - - [string] $Name, - - [int64] $Id + [string] $TypeName = $script:GitHubOrganizationTypeName ) foreach ($item in $InputObject) @@ -202,27 +190,8 @@ filter Add-GitHubOrganizationAdditionalProperties if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { - $organizationName = $item.login - if ([String]::IsNullOrEmpty($organizationName) -and $PSBoundParameters.ContainsKey('Name')) - { - $organizationName = $Name - } - - if (-not [String]::IsNullOrEmpty($organizationName)) - { - Add-Member -InputObject $item -Name 'OrganizationName' -Value $organizationName -MemberType NoteProperty -Force - } - - $organizationId = $item.id - if (($organizationId -eq 0) -and $PSBoundParameters.ContainsKey('Id')) - { - $organizationId = $Id - } - - if ($organizationId -ne 0) - { - Add-Member -InputObject $item -Name 'OrganizationId' -Value $organizationId -MemberType NoteProperty -Force - } + Add-Member -InputObject $item -Name 'OrganizationName' -Value $item.login -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'OrganizationId' -Value $item.id -MemberType NoteProperty -Force } Write-Output $item diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index 7e3b43ed..86235287 100644 --- a/GitHubProjectColumns.ps1 +++ b/GitHubProjectColumns.ps1 @@ -134,7 +134,7 @@ filter New-GitHubProjectColumn GitHub.ProjectColumn .EXAMPLE - New-GitHubProjectColumn -Project 999999 -Name 'Done' + New-GitHubProjectColumn -Project 999999 -ColumnName 'Done' Creates a column called 'Done' for the project with ID 999999. #> @@ -153,7 +153,8 @@ filter New-GitHubProjectColumn [Parameter( Mandatory, ValueFromPipeline)] - [string] $Name, + [Alias('Name')] + [string] $ColumnName, [string] $AccessToken, @@ -166,10 +167,10 @@ filter New-GitHubProjectColumn $telemetryProperties['Project'] = Get-PiiSafeString -PlainText $Project $uriFragment = "/projects/$Project/columns" - $apiDescription = "Creating project column $Name" + $apiDescription = "Creating project column $ColumnName" $hashBody = @{ - 'name' = $Name + 'name' = $ColumnName } $params = @{ @@ -215,7 +216,7 @@ filter Set-GitHubProjectColumn GitHub.ProjectColumn .EXAMPLE - Set-GitHubProjectColumn -Column 999999 -Name NewColumnName + Set-GitHubProjectColumn -Column 999999 -ColumnName NewColumnName Set the project column name to 'NewColumnName' with column with ID 999999. #> @@ -231,7 +232,8 @@ filter Set-GitHubProjectColumn [int64] $Column, [Parameter(Mandatory)] - [string] $Name, + [Alias('Name')] + [string] $ColumnName, [string] $AccessToken, @@ -246,7 +248,7 @@ filter Set-GitHubProjectColumn $apiDescription = "Updating column $Column" $hashBody = @{ - 'name' = $Name + 'name' = $ColumnName } $params = @{ diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 9446efae..e9071228 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -243,22 +243,22 @@ filter New-GitHubProject GitHub.Project .EXAMPLE - New-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub -Name TestProject + New-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub -ProjectName TestProject Creates a project called 'TestProject' for the microsoft\PowerShellForGitHub repository. .EXAMPLE - New-GitHubProject -OrganizationName Microsoft -Name TestProject -Description 'This is just a test project' + New-GitHubProject -OrganizationName Microsoft -ProjectName TestProject -Description 'This is just a test project' Create a project for the Microsoft organization called 'TestProject' with a description. .EXAMPLE - New-GitHubProject -Uri https://github.com/Microsoft/PowerShellForGitHub -Name TestProject + New-GitHubProject -Uri https://github.com/Microsoft/PowerShellForGitHub -ProjectName TestProject Create a project for the microsoft\PowerShellForGitHub repository using the Uri called 'TestProject'. .EXAMPLE - New-GitHubProject -UserProject -Name 'TestProject' + New-GitHubProject -UserProject -ProjectName 'TestProject' Creates a project for the signed in user called 'TestProject'. #> @@ -290,7 +290,8 @@ filter New-GitHubProject [Parameter( Mandatory, ValueFromPipeline)] - [string] $Name, + [Alias('Name')] + [string] $ProjectName, [string] $Description, @@ -302,7 +303,7 @@ filter New-GitHubProject Write-InvocationLog $telemetryProperties = @{} - $telemetryProperties['Name'] = Get-PiiSafeString -PlainText $Name + $telemetryProperties['ProjectName'] = Get-PiiSafeString -PlainText $ProjectName $uriFragment = [String]::Empty $apiDescription = [String]::Empty @@ -334,7 +335,7 @@ filter New-GitHubProject } $hashBody = @{ - 'name' = $Name + 'name' = $ProjectName } if ($PSBoundParameters.ContainsKey('Description')) diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index 477d2b28..7e3de9ed 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -308,7 +308,7 @@ filter New-GitHubPullRequest Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='Uri_Issue')] - [Alias('IssueId')] + [Alias('IssueNumber')] [int] $Issue, [Parameter(Mandatory)] diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 4a79ba08..fd06d787 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -761,12 +761,6 @@ filter Rename-GitHubRepository # This method was created by mistake and is now retained to avoid a breaking change. # Update-GitHubRepository is able to handle this scenario just fine. - if ($PSBoundParameters.ContainsKey('NewName')) - { - $null = $PSBoundParameters.Add('Name', $NewName) - $null = $PSBoundParameters.Remove('NewName') - } - return Update-GitHubRepository @PSBoundParameters } @@ -794,7 +788,7 @@ filter Update-GitHubRepository The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually. - .PARAMETER Name + .PARAMETER NewName Rename the repository to this new name. .PARAMETER Description @@ -872,7 +866,7 @@ filter Update-GitHubRepository .EXAMPLE Get-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub | - Update-GitHubRepository -Name 'PoShForGitHub' -Force + Update-GitHubRepository -NewName 'PoShForGitHub' -Force Renames the repository without any user confirmation prompting. This is identical to using Rename-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub -NewName 'PoShForGitHub' -Confirm:$false @@ -898,7 +892,7 @@ filter Update-GitHubRepository [string] $Uri, [ValidateNotNullOrEmpty()] - [string] $Name, + [string] $NewName, [string] $Description, @@ -951,15 +945,15 @@ filter Update-GitHubRepository $hashBody = @{} - if ($PSBoundParameters.ContainsKey('Name')) + if ($PSBoundParameters.ContainsKey('NewName')) { $existingName = if ($PSCmdlet.ParameterSetName -eq 'Uri') { $Uri } else { $OwnerName, $RepositoryName -join '/' } - if (-not $PSCmdlet.ShouldProcess($existingName, "Rename repository to '$Name'")) + if (-not $PSCmdlet.ShouldProcess($existingName, "Rename repository to '$NewName'")) { return } - $hashBody['name'] = $Name + $hashBody['name'] = $NewName } if ($PSBoundParameters.ContainsKey('Description')) { $hashBody['description'] = $Description } diff --git a/GitHubTeams.ps1 b/GitHubTeams.ps1 index 20abcbdc..538b52c7 100644 --- a/GitHubTeams.ps1 +++ b/GitHubTeams.ps1 @@ -254,14 +254,6 @@ filter Add-GitHubTeamAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. - - .PARAMETER Name - The name of the team. This information might be obtainable from InputObject, so this - is optional based on what InputObject contains. - - .PARAMETER Id - The ID of the team. This information might be obtainable from InputObject, so this - is optional based on what InputObject contains. #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] @@ -274,11 +266,7 @@ filter Add-GitHubTeamAdditionalProperties [PSCustomObject[]] $InputObject, [ValidateNotNullOrEmpty()] - [string] $TypeName = $script:GitHubTeamTypeName, - - [string] $Name, - - [int64] $Id + [string] $TypeName = $script:GitHubTeamTypeName ) foreach ($item in $InputObject) @@ -287,27 +275,8 @@ filter Add-GitHubTeamAdditionalProperties if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { - $teamName = $item.name - if ([String]::IsNullOrEmpty($teamName) -and $PSBoundParameters.ContainsKey('Name')) - { - $teamName = $Name - } - - if (-not [String]::IsNullOrEmpty($teamName)) - { - Add-Member -InputObject $item -Name 'TeamName' -Value $teamName -MemberType NoteProperty -Force - } - - $teamId = $item.id - if (($teamId -eq 0) -and $PSBoundParameters.ContainsKey('Id')) - { - $teamId = $Id - } - - if ($teamId -ne 0) - { - Add-Member -InputObject $item -Name 'TeamId' -Value $teamId -MemberType NoteProperty -Force - } + Add-Member -InputObject $item -Name 'TeamName' -Value $item.name -MemberType NoteProperty -Force + Add-Member -InputObject $item -Name 'TeamId' -Value $item.id -MemberType NoteProperty -Force # Apply these properties to any embedded parent teams as well. if ($null -ne $item.parent) diff --git a/Tests/GitHubProjectCards.tests.ps1 b/Tests/GitHubProjectCards.tests.ps1 index 4308783b..54d80ec3 100644 --- a/Tests/GitHubProjectCards.tests.ps1 +++ b/Tests/GitHubProjectCards.tests.ps1 @@ -34,10 +34,10 @@ try } $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultProject + $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -ProjectName $defaultProject - $column = New-GitHubProjectColumn -Project $project.id -Name $defaultColumn - $columntwo = New-GitHubProjectColumn -Project $project.id -Name $defaultColumnTwo + $column = New-GitHubProjectColumn -Project $project.id -ColumnName $defaultColumn + $columntwo = New-GitHubProjectColumn -Project $project.id -ColumnName $defaultColumnTwo $issue = New-GitHubIssue -Owner $script:ownerName -RepositoryName $repo.name -Title $defaultIssue diff --git a/Tests/GitHubProjectColumns.tests.ps1 b/Tests/GitHubProjectColumns.tests.ps1 index b9233134..a2fcbb09 100644 --- a/Tests/GitHubProjectColumns.tests.ps1 +++ b/Tests/GitHubProjectColumns.tests.ps1 @@ -27,11 +27,11 @@ try Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value } - $project = New-GitHubProject -UserProject -Name $defaultProject + $project = New-GitHubProject -UserProject -ProjectName $defaultProject Describe 'Getting Project Columns' { BeforeAll { - $column = New-GitHubProjectColumn -Project $project.id -Name $defaultColumn + $column = New-GitHubProjectColumn -Project $project.id -ColumnName $defaultColumn } AfterAll { @@ -115,8 +115,8 @@ try Describe 'Modify Project Column' { BeforeAll { - $column = New-GitHubProjectColumn -Project $project.id -Name $defaultColumn - $columntwo = New-GitHubProjectColumn -Project $project.id -Name $defaultColumnTwo + $column = New-GitHubProjectColumn -Project $project.id -ColumnName $defaultColumn + $columntwo = New-GitHubProjectColumn -Project $project.id -ColumnName $defaultColumnTwo } AfterAll { @@ -125,7 +125,7 @@ try } Context 'Modify column name' { - $null = Set-GitHubProjectColumn -Column $column.id -Name $defaultColumnUpdate + $null = Set-GitHubProjectColumn -Column $column.id -ColumnName $defaultColumnUpdate $result = Get-GitHubProjectColumn -Column $column.id It 'Should get column' { @@ -198,7 +198,7 @@ try Remove-Variable -Name column } - $column.id = (New-GitHubProjectColumn -Project $project.id -Name $defaultColumn).id + $column.id = (New-GitHubProjectColumn -Project $project.id -ColumnName $defaultColumn).id $result = Get-GitHubProjectColumn -Column $column.id It 'Column exists' { @@ -227,7 +227,7 @@ try Remove-Variable -Name column } - $column.id = ($project | New-GitHubProjectColumn -Name $defaultColumn).id + $column.id = ($project | New-GitHubProjectColumn -ColumnName $defaultColumn).id $result = Get-GitHubProjectColumn -Column $column.id It 'Column exists' { @@ -279,7 +279,7 @@ try Describe 'Remove project column' { Context 'Remove project column' { BeforeAll { - $column = New-GitHubProjectColumn -Project $project.id -Name $defaultColumn + $column = New-GitHubProjectColumn -Project $project.id -ColumnName $defaultColumn } $null = Remove-GitHubProjectColumn -Column $column.id -Confirm:$false @@ -290,7 +290,7 @@ try Context 'Remove project column (via pipeline)' { BeforeAll { - $column = New-GitHubProjectColumn -Project $project.id -Name $defaultColumn + $column = New-GitHubProjectColumn -Project $project.id -ColumnName $defaultColumn } $column | Remove-GitHubProjectColumn -Force diff --git a/Tests/GitHubProjects.tests.ps1 b/Tests/GitHubProjects.tests.ps1 index 3e93b1c2..ccde85d6 100644 --- a/Tests/GitHubProjects.tests.ps1 +++ b/Tests/GitHubProjects.tests.ps1 @@ -42,7 +42,7 @@ try Describe 'Getting Project' { Context 'Get User projects' { BeforeAll { - $project = New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc + $project = New-GitHubProject -UserProject -ProjectName $defaultUserProject -Description $defaultUserProjectDesc } AfterAll { @@ -75,7 +75,7 @@ try Context 'Get Organization projects' { BeforeAll { - $project = New-GitHubProject -OrganizationName $script:organizationName -Name $defaultOrgProject -Description $defaultOrgProjectDesc + $project = New-GitHubProject -OrganizationName $script:organizationName -ProjectName $defaultOrgProject -Description $defaultOrgProjectDesc } AfterAll { @@ -111,7 +111,7 @@ try Context 'Get Repo projects' { BeforeAll { - $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultRepoProject -Description $defaultRepoProjectDesc + $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -ProjectName $defaultRepoProject -Description $defaultRepoProjectDesc } AfterAll { @@ -145,7 +145,7 @@ try Context 'Get a closed Repo project (via pipeline)' { BeforeAll { - $project = $repo | New-GitHubProject -Name $defaultProjectClosed -Description $defaultProjectClosedDesc + $project = $repo | New-GitHubProject -ProjectName $defaultProjectClosed -Description $defaultProjectClosedDesc $null = Set-GitHubProject -Project $project.id -State Closed } @@ -184,7 +184,7 @@ try Context 'Get a specific project (by parameter)' { BeforeAll { - $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultRepoProject -Description $defaultRepoProjectDesc + $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -ProjectName $defaultRepoProject -Description $defaultRepoProjectDesc } AfterAll { @@ -214,7 +214,7 @@ try Context 'Get a specific project (by pipeline object)' { BeforeAll { - $project = $repo | New-GitHubProject -Name $defaultRepoProject -Description $defaultRepoProjectDesc + $project = $repo | New-GitHubProject -ProjectName $defaultRepoProject -Description $defaultRepoProjectDesc } AfterAll { @@ -236,7 +236,7 @@ try Context 'Get a specific project (with ID via pipeline)' { BeforeAll { - $project = $repo | New-GitHubProject -Name $defaultRepoProject -Description $defaultRepoProjectDesc + $project = $repo | New-GitHubProject -ProjectName $defaultRepoProject -Description $defaultRepoProjectDesc } AfterAll { @@ -260,7 +260,7 @@ try Describe 'Modify Project' { Context 'Modify User projects' { BeforeAll { - $project = New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc + $project = New-GitHubProject -UserProject -ProjectName $defaultUserProject -Description $defaultUserProjectDesc } AfterAll { @@ -291,7 +291,7 @@ try Context 'Modify User projects (via ID in pipeline)' { BeforeAll { - $project = New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc + $project = New-GitHubProject -UserProject -ProjectName $defaultUserProject -Description $defaultUserProjectDesc } AfterAll { @@ -322,7 +322,7 @@ try Context 'Modify User projects (via object in pipeline)' { BeforeAll { - $project = New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc + $project = New-GitHubProject -UserProject -ProjectName $defaultUserProject -Description $defaultUserProjectDesc } AfterAll { @@ -353,7 +353,7 @@ try Context 'Modify Organization projects' { BeforeAll { - $project = New-GitHubProject -OrganizationName $script:organizationName -Name $defaultOrgProject -Description $defaultOrgProjectDesc + $project = New-GitHubProject -OrganizationName $script:organizationName -ProjectName $defaultOrgProject -Description $defaultOrgProjectDesc } AfterAll { @@ -395,7 +395,7 @@ try Context 'Modify Repo projects' { BeforeAll { - $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultRepoProject -Description $defaultRepoProjectDesc + $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -ProjectName $defaultRepoProject -Description $defaultRepoProjectDesc } AfterAll { @@ -436,7 +436,7 @@ try Remove-Variable project } - $project.id = (New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc).id + $project.id = (New-GitHubProject -UserProject -ProjectName $defaultUserProject -Description $defaultUserProjectDesc).id $result = Get-GitHubProject -Project $project.id It 'Project exists' { $result | Should -Not -BeNullOrEmpty @@ -500,7 +500,7 @@ try Remove-Variable project } - $project.id = (New-GitHubProject -OrganizationName $script:organizationName -Name $defaultOrgProject -Description $defaultOrgProjectDesc).id + $project.id = (New-GitHubProject -OrganizationName $script:organizationName -ProjectName $defaultOrgProject -Description $defaultOrgProjectDesc).id $result = Get-GitHubProject -Project $project.id It 'Project exists' { $result | Should -Not -BeNullOrEmpty @@ -535,7 +535,7 @@ try Remove-Variable project } - $project.id = (New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultRepoProject -Description $defaultRepoProjectDesc).id + $project.id = (New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -ProjectName $defaultRepoProject -Description $defaultRepoProjectDesc).id $result = Get-GitHubProject -Project $project.id It 'Project Exists' { $result | Should -Not -BeNullOrEmpty @@ -567,7 +567,7 @@ try Remove-Variable project } - $project.id = ($repo | New-GitHubProject -Name $defaultRepoProject -Description $defaultRepoProjectDesc).id + $project.id = ($repo | New-GitHubProject -ProjectName $defaultRepoProject -Description $defaultRepoProjectDesc).id $result = Get-GitHubProject -Project $project.id It 'Project Exists' { $result | Should -Not -BeNullOrEmpty @@ -592,7 +592,7 @@ try Describe 'Remove Project' { Context 'Remove User projects' { - $project = New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc + $project = New-GitHubProject -UserProject -ProjectName $defaultUserProject -Description $defaultUserProjectDesc $null = Remove-GitHubProject -Project $project.id -Force It 'Project should be removed' { {Get-GitHubProject -Project $project.id} | Should -Throw @@ -600,7 +600,7 @@ try } Context 'Remove Organization projects' { - $project = New-GitHubProject -OrganizationName $script:organizationName -Name $defaultOrgProject -Description $defaultOrgProjectDesc + $project = New-GitHubProject -OrganizationName $script:organizationName -ProjectName $defaultOrgProject -Description $defaultOrgProjectDesc $null = Remove-GitHubProject -Project $project.id -Force It 'Project should be removed' { {Get-GitHubProject -Project $project.id} | Should -Throw @@ -608,7 +608,7 @@ try } Context 'Remove Repo projects' { - $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultRepoProject -Description $defaultRepoProjectDesc + $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -ProjectName $defaultRepoProject -Description $defaultRepoProjectDesc $null = Remove-GitHubProject -Project $project.id -Confirm:$false It 'Project should be removed' { {Get-GitHubProject -Project $project.id} | Should -Throw @@ -616,7 +616,7 @@ try } Context 'Remove Repo project via pipeline' { - $project = $repo | New-GitHubProject -Name $defaultRepoProject -Description $defaultRepoProjectDesc + $project = $repo | New-GitHubProject -ProjectName $defaultRepoProject -Description $defaultRepoProjectDesc $project | Remove-GitHubProject -Force It 'Project should be removed' { {$project | Get-GitHubProject} | Should -Throw diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 4717aa49..3dc1bf81 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -425,7 +425,7 @@ try } It "Should be possible to rename with Update-GitHubRepository too" { - $renamedRepo = $repo | Update-GitHubRepository -Name $newRepoName -Confirm:$false + $renamedRepo = $repo | Update-GitHubRepository -NewName $newRepoName -Confirm:$false $renamedRepo.name | Should -Be $newRepoName $renamedRepo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' } diff --git a/USAGE.md b/USAGE.md index c29124b7..59cc3954 100644 --- a/USAGE.md +++ b/USAGE.md @@ -573,12 +573,12 @@ Get-GitHubProject -UserName octocat #### Create a project ```powershell -New-GitHubProject -OwnerName octocat -RepositoryName PowerShellForGitHub -Name TestProject +New-GitHubProject -OwnerName octocat -RepositoryName PowerShellForGitHub -ProjectName TestProject ``` #### Add a column to a project ```powershell -New-GitHubProjectColumn -Project 1 -Name 'To Do' +New-GitHubProjectColumn -Project 1 -ColumnName 'To Do' ``` #### Add a card to a column From 9fe5a7b86f4bb00f0c76c169c85d53b7e90db3ce Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Wed, 17 Jun 2020 13:50:06 -0700 Subject: [PATCH 77/80] Applying some CR feedback including limiting the lines exceeding 100 chars --- CONTRIBUTING.md | 4 +-- GitHubAnalytics.ps1 | 19 ++++++++---- GitHubAssignees.ps1 | 41 ++++++++++++++++++-------- GitHubConfiguration.ps1 | 59 ++++++++++++++++++++++++------------- GitHubContents.ps1 | 17 +++++++---- GitHubCore.ps1 | 46 +++++++++++++++++++++-------- GitHubEvents.ps1 | 6 ++-- GitHubIssueComments.ps1 | 39 ++++++++++++++++-------- GitHubIssues.ps1 | 39 ++++++++++++++++-------- GitHubLabels.ps1 | 41 ++++++++++++++++++-------- GitHubMiscellaneous.ps1 | 7 +++-- GitHubProjects.ps1 | 3 +- GitHubPullRequests.ps1 | 7 +++-- GitHubReleases.ps1 | 2 +- GitHubRepositories.ps1 | 46 +++++++++++++++++------------ GitHubRepositoryTraffic.ps1 | 21 ++++++++----- GitHubUsers.ps1 | 3 +- 17 files changed, 269 insertions(+), 131 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ccad1c5d..498d5130 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -292,8 +292,8 @@ Set-GitHubConfiguration -LogRequestBody This module has comprehensive support for the PowerShell pipeline. It is imperative that all new functionality added to the module embraces this design. - * Most functions are declared as a `filter`. This is the equivalent of a `function` with a - where the body of the function is the `process` block, and the `begin/end` blocks are empty. + * Most functions are declared as a `filter`. This is the equivalent of a `function` where the + body of the function is the `process` block, and the `begin/end` blocks are empty. * In limited cases where one of the inputs is an array of something, and you specifically want that to be processed as a single command (like adding a bunch of labels to a single issue at once), diff --git a/GitHubAnalytics.ps1 b/GitHubAnalytics.ps1 index e4bba220..623b723f 100644 --- a/GitHubAnalytics.ps1 +++ b/GitHubAnalytics.ps1 @@ -25,7 +25,8 @@ function Group-GitHubIssue if part of. .OUTPUTS - [PSCustomObject[]] Collection of issues and counts, by week, along with the total count of issues. + [PSCustomObject[]] + Collection of issues and counts, by week, along with the total count of issues. .EXAMPLE $issues = @() @@ -90,8 +91,12 @@ function Group-GitHubIssue foreach ($week in $weekDates) { $filteredIssues = @($Issue | Where-Object { - (($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or - (($DateType -eq 'Closed') -and ($_.closed_at -ge $week) -and ($_.closed_at -le $endOfWeek)) + (($DateType -eq 'Created') -and + ($_.created_at -ge $week) -and + ($_.created_at -le $endOfWeek)) -or + (($DateType -eq 'Closed') -and + ($_.closed_at -ge $week) -and + ($_.closed_at -le $endOfWeek)) }) $endOfWeek = $week @@ -211,8 +216,12 @@ function Group-GitHubPullRequest foreach ($week in $weekDates) { $filteredPullRequests = @($PullRequest | Where-Object { - (($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or - (($DateType -eq 'Merged') -and ($_.merged_at -ge $week) -and ($_.merged_at -le $endOfWeek)) + (($DateType -eq 'Created') -and + ($_.created_at -ge $week) -and + ($_.created_at -le $endOfWeek)) -or + (($DateType -eq 'Merged') -and + ($_.merged_at -ge $week) -and + ($_.merged_at -le $endOfWeek)) }) $endOfWeek = $week diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index 76e5705d..421a5b47 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -98,7 +98,7 @@ filter Test-GitHubAssignee { <# .DESCRIPTION - Checks if a user has permission to be assigned to an issue in this repository. Returns a boolean. + Checks if a user has permission to be assigned to an issue in this repository. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -135,19 +135,22 @@ filter Test-GitHubAssignee .EXAMPLE Test-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee "LoginID123" - Checks if a user has permission to be assigned to an issue from the microsoft\PowerShellForGitHub project. + Checks if a user has permission to be assigned to an issue + from the microsoft\PowerShellForGitHub project. .EXAMPLE $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub $repo | Test-GitHubAssignee -Assignee 'octocat' - Checks if a user has permission to be assigned to an issue from the microsoft\PowerShellForGitHub project. + Checks if a user has permission to be assigned to an issue + from the microsoft\PowerShellForGitHub project. .EXAMPLE $octocat = Get-GitHubUser -UserName 'octocat' $repo = $octocat | Test-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub - Checks if a user has permission to be assigned to an issue from the microsoft\PowerShellForGitHub project. + Checks if a user has permission to be assigned to an issue + from the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -237,7 +240,9 @@ function New-GitHubAssignee Issue number to add the assignees to. .PARAMETER Assignee - Usernames of users to assign this issue to. NOTE: Only users with push access can add assignees to an issue. + Usernames of users to assign this issue to. + + NOTE: Only users with push access can add assignees to an issue. Assignees are silently ignored otherwise. .PARAMETER AccessToken @@ -257,14 +262,16 @@ function New-GitHubAssignee $assignees = @('octocat') New-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Assignee $assignee - Additionally assigns the usernames in $assignee to Issue #1 from the microsoft\PowerShellForGitHub project. + Additionally assigns the usernames in $assignee to Issue #1 + from the microsoft\PowerShellForGitHub project. .EXAMPLE $assignees = @('octocat') $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub $repo | New-GitHubAssignee -Issue 1 -Assignee $assignee - Additionally assigns the usernames in $assignee to Issue #1 from the microsoft\PowerShellForGitHub project. + Additionally assigns the usernames in $assignee to Issue #1 + from the microsoft\PowerShellForGitHub project. .EXAMPLE $assignees = @('octocat') @@ -272,13 +279,15 @@ function New-GitHubAssignee Get-GitHubIssue -Issue 1 | New-GitHubAssignee -Assignee $assignee - Additionally assigns the usernames in $assignee to Issue #1 from the microsoft\PowerShellForGitHub project. + Additionally assigns the usernames in $assignee to Issue #1 + from the microsoft\PowerShellForGitHub project. .EXAMPLE $octocat = Get-GitHubUser -UserName 'octocat' $octocat | New-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 - Additionally assigns the user 'octocat' to Issue #1 from the microsoft\PowerShellForGitHub project. + Additionally assigns the user 'octocat' to Issue #1 + from the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -413,14 +422,17 @@ function Remove-GitHubAssignee $assignees = @('octocat') Remove-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Assignee $assignee - Removes the specified usernames from the assignee list for Issue #1 in the microsoft\PowerShellForGitHub project. + Removes the specified usernames from the assignee list for Issue #1 + in the microsoft\PowerShellForGitHub project. .EXAMPLE $assignees = @('octocat') $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub $repo | Remove-GitHubAssignee -Issue 1 -Assignee $assignee - Removes the specified usernames from the assignee list for Issue #1 in the microsoft\PowerShellForGitHub project. + Removes the specified usernames from the assignee list for Issue #1 + in the microsoft\PowerShellForGitHub project. + Will not prompt for confirmation because -Confirm:$false was specified .EXAMPLE @@ -429,14 +441,17 @@ function Remove-GitHubAssignee Get-GitHubIssue -Issue 1 | Remove-GitHubAssignee -Assignee $assignee - Removes the specified usernames from the assignee list for Issue #1 in the microsoft\PowerShellForGitHub project. + Removes the specified usernames from the assignee list for Issue #1 + in the microsoft\PowerShellForGitHub project. + Will not prompt for confirmation because -Force was specified .EXAMPLE $octocat = Get-GitHubUser -UserName 'octocat' $octocat | Remove-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 - Removes the specified usernames from the assignee list for Issue #1 in the microsoft\PowerShellForGitHub project. + Removes the specified usernames from the assignee list for Issue #1 + in the microsoft\PowerShellForGitHub project. .NOTES Only users with push access can remove assignees from an issue. diff --git a/GitHubConfiguration.ps1 b/GitHubConfiguration.ps1 index 308ebe8e..0320f399 100644 --- a/GitHubConfiguration.ps1 +++ b/GitHubConfiguration.ps1 @@ -348,7 +348,8 @@ function Save-GitHubConfiguration if (($null -ne $ev) -and ($ev.Count -gt 0)) { - Write-Log -Message "Failed to persist these updated settings to disk. They will remain for this PowerShell session only." -Level Warning -Exception $ev[0] + $message = "Failed to persist these updated settings to disk. They will remain for this PowerShell session only." + Write-Log -Message $message -Level Warning -Exception $ev[0] } } @@ -459,7 +460,8 @@ function Resolve-PropertyValue } else { - Write-Log "The locally cached $Name configuration was not of type $Type. Reverting to default value." -Level Warning + $message = "The locally cached $Name configuration was not of type $Type. Reverting to default value." + Write-Log -Message $message -Level Warning return $DefaultValue } } @@ -495,7 +497,8 @@ function Reset-GitHubConfiguration Deletes the local configuration file and loads in all default configuration values. .NOTES - This command will not clear your authentication token. Please use Clear-GitHubAuthentication to accomplish that. + This command will not clear your authentication token. + Please use Clear-GitHubAuthentication to accomplish that. #> [CmdletBinding(SupportsShouldProcess)] param( @@ -513,13 +516,15 @@ function Reset-GitHubConfiguration if (($null -ne $ev) -and ($ev.Count -gt 0) -and ($ev[0].FullyQualifiedErrorId -notlike 'PathNotFound*')) { - Write-Log -Message "Reset was unsuccessful. Experienced a problem trying to remove the file [$script:configurationFilePath]." -Level Warning -Exception $ev[0] + $message = "Reset was unsuccessful. Experienced a problem trying to remove the file [$script:configurationFilePath]." + Write-Log -Message $message -Level Warning -Exception $ev[0] } } Initialize-GitHubConfiguration - Write-Log -Message "This has not cleared your authentication token. Call Clear-GitHubAuthentication to accomplish that." -Level Verbose + $message = "This has not cleared your authentication token. Call Clear-GitHubAuthentication to accomplish that." + Write-Log -Message $message -Level Verbose } function Read-GitHubConfiguration @@ -565,7 +570,8 @@ function Read-GitHubConfiguration } catch { - Write-Log -Message 'The configuration file for this module is in an invalid state. Use Reset-GitHubConfiguration to recover.' -Level Warning + $message = 'The configuration file for this module is in an invalid state. Use Reset-GitHubConfiguration to recover.' + Write-Log -Message $message -Level Warning } } @@ -639,11 +645,13 @@ function Import-GitHubConfiguration 'suppressTelemetryReminder' = $false 'webRequestTimeoutSec' = 0 - # This hash is generated by using Helper.ps1's Get-Sha512Hash in Tests/Config/Settings.ps1 like so: + # This hash is generated by using Helper.ps1's Get-Sha512Hash in Tests/Config/Settings.ps1 + # like so: # . ./Helpers.ps1; Get-Sha512Hash -PlainText (Get-Content -Path ./Tests/Config/Settings.ps1 -Raw -Encoding Utf8) - # The hash is used to identify if the user has made changes to the config file prior to running the UT's locally. - # It intentionally cannot be modified via Set-GitHubConfiguration and must be updated directly in the - # source code here should the default Settings.ps1 file ever be changed. + # The hash is used to identify if the user has made changes to the config file prior to + # running the UT's locally. It intentionally cannot be modified via Set-GitHubConfiguration + # and must be updated directly in the source code here should the default Settings.ps1 file + # ever be changed. 'testConfigSettingsHash' = '272EE14CED396100A7AFD23EA21CA262470B7F4D80E47B7ABD90508B86210775F020EEF79D322F4C22A53835F700E1DFD13D0509C1D08DD6F9771B3F0133EDAB' } @@ -675,7 +683,7 @@ function Backup-GitHubConfiguration The path to store the user's current configuration file. .PARAMETER Force - If specified, will overwrite the contents of any file with the same name at th + If specified, will overwrite the contents of any file with the same name at the location specified by Path. .EXAMPLE @@ -728,7 +736,9 @@ function Restore-GitHubConfiguration [CmdletBinding(SupportsShouldProcess)] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( - [ValidateScript({if (Test-Path -Path $_ -PathType Leaf) { $true } else { throw "$_ does not exist." }})] + [ValidateScript({ + if (Test-Path -Path $_ -PathType Leaf) { $true } + else { throw "$_ does not exist." }})] [string] $Path ) @@ -935,7 +945,8 @@ function Clear-GitHubAuthentication Clears out any GitHub API token from memory, as well as from local file storage. .NOTES - This command will not clear your configuration settings. Please use Reset-GitHubConfiguration to accomplish that. + This command will not clear your configuration settings. + Please use Reset-GitHubConfiguration to accomplish that. #> [CmdletBinding(SupportsShouldProcess)] param( @@ -957,14 +968,18 @@ function Clear-GitHubAuthentication { Remove-Item -Path $script:accessTokenFilePath -Force -ErrorAction SilentlyContinue -ErrorVariable ev - if (($null -ne $ev) -and ($ev.Count -gt 0) -and ($ev[0].FullyQualifiedErrorId -notlike 'PathNotFound*')) + if (($null -ne $ev) -and + ($ev.Count -gt 0) -and + ($ev[0].FullyQualifiedErrorId -notlike 'PathNotFound*')) { - Write-Log -Message "Experienced a problem trying to remove the file that persists the Access Token [$script:accessTokenFilePath]." -Level Warning -Exception $ev[0] + $message = "Experienced a problem trying to remove the file that persists the Access Token [$script:accessTokenFilePath]." + Write-Log -Message $message -Level Warning -Exception $ev[0] } } } - Write-Log -Message "This has not cleared your configuration settings. Call Reset-GitHubConfiguration to accomplish that." -Level Verbose + $message = "This has not cleared your configuration settings. Call Reset-GitHubConfiguration to accomplish that." + Write-Log -Message $message -Level Verbose } function Get-AccessToken @@ -1021,19 +1036,22 @@ function Get-AccessToken { $secureString = $content | ConvertTo-SecureString - Write-Log -Message "Restoring Access Token from file. This value can be cleared in the future by calling Clear-GitHubAuthentication." -Level Verbose + $message = "Restoring Access Token from file. This value can be cleared in the future by calling Clear-GitHubAuthentication." + Write-Log -Message $messsage -Level Verbose $script:accessTokenCredential = New-Object System.Management.Automation.PSCredential "", $secureString return $script:accessTokenCredential.GetNetworkCredential().Password } catch { - Write-Log -Message 'The Access Token file for this module contains an invalid SecureString (files can''t be shared by users or computers). Use Set-GitHubAuthentication to update it.' -Level Warning + $message = 'The Access Token file for this module contains an invalid SecureString (files can''t be shared by users or computers). Use Set-GitHubAuthentication to update it.' + Write-Log -Message $message -Level Warning } } if (-not [String]::IsNullOrEmpty($global:gitHubApiToken)) { - Write-Log -Message 'Storing the Access Token in `$global:gitHubApiToken` is insecure and is no longer recommended. To cache your Access Token for use across future PowerShell sessions, please use Set-GitHubAuthentication instead.' -Level Warning + $message = 'Storing the Access Token in `$global:gitHubApiToken` is insecure and is no longer recommended. To cache your Access Token for use across future PowerShell sessions, please use Set-GitHubAuthentication instead.' + Write-Log -Message $message -Level Warning return $global:gitHubApiToken } @@ -1041,7 +1059,8 @@ function Get-AccessToken (-not $script:seenTokenWarningThisSession)) { $script:seenTokenWarningThisSession = $true - Write-Log -Message 'This module has not yet been configured with a personal GitHub Access token. The module can still be used, but GitHub will limit your usage to 60 queries per hour. You can get a GitHub API token from https://github.com/settings/tokens/new (provide a description and check any appropriate scopes).' -Level Warning + $message = 'This module has not yet been configured with a personal GitHub Access token. The module can still be used, but GitHub will limit your usage to 60 queries per hour. You can get a GitHub API token from https://github.com/settings/tokens/new (provide a description and check any appropriate scopes).' + Write-Log -Message $message -Level Warning } return $null diff --git a/GitHubContents.ps1 b/GitHubContents.ps1 index 19e4034e..4e1cd084 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -32,14 +32,19 @@ .PARAMETER MediaType The format in which the API will return the body of the issue. - Object - Return a json object representation a file or folder. This is the default if you do not pass any specific media type. - Raw - Return the raw contents of a file. - Html - For markup files such as Markdown or AsciiDoc, you can retrieve the rendered HTML using the Html media type. + + Object - Return a json object representation a file or folder. + This is the default if you do not pass any specific media type. + Raw - Return the raw contents of a file. + Html - For markup files such as Markdown or AsciiDoc, + you can retrieve the rendered HTML using the Html media type. .PARAMETER ResultAsString - If this switch is specified and the MediaType is either Raw or Html then the resulting bytes will be decoded the result will be - returned as a string instead of bytes. If the MediaType is Object, then an additional property on the object is returned 'contentAsString' - which will be the decoded base64 result as a string. + If this switch is specified and the MediaType is either Raw or Html then the + resulting bytes will be decoded the result will be returned as a string instead of bytes. + If the MediaType is Object, then an additional property on the object named + 'contentAsString' will be included and its value will be the decoded base64 result + as a string. .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 9c92c606..860a3a62 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -103,8 +103,8 @@ function Invoke-GHRestMethod no additional status shown to the user until a response is returned from the REST request. .NOTES - This wraps Invoke-WebRequest as opposed to Invoke-RestMethod because we want access to the headers - that are returned in the response, and Invoke-RestMethod drops those headers. + This wraps Invoke-WebRequest as opposed to Invoke-RestMethod because we want access + to the headers that are returned in the response, and Invoke-RestMethod drops those headers. #> [CmdletBinding(SupportsShouldProcess)] param( @@ -245,7 +245,15 @@ function Invoke-GHRestMethod $jobName = "Invoke-GHRestMethod-" + (Get-Date).ToFileTime().ToString() [scriptblock]$scriptBlock = { - param($Url, $Method, $Headers, $Body, $ValidBodyContainingRequestMethods, $TimeoutSec, $LogRequestBody, $ScriptRootPath) + param( + $Url, + $Method, + $Headers, + $Body, + $ValidBodyContainingRequestMethods, + $TimeoutSec, + $LogRequestBody, + $ScriptRootPath) # We need to "dot invoke" Helpers.ps1 and GitHubConfiguration.ps1 within # the context of this script block since we're running in a different @@ -347,7 +355,8 @@ function Invoke-GHRestMethod } catch [ArgumentException] { - # The content must not be JSON (which is a legitimate situation). We'll return the raw content result instead. + # The content must not be JSON (which is a legitimate situation). + # We'll return the raw content result instead. # We do this unnecessary assignment to avoid PSScriptAnalyzer's PSAvoidUsingEmptyCatchBlock. $finalResult = $finalResult } @@ -359,7 +368,9 @@ function Invoke-GHRestMethod # a lot of time. Let's optimize here by not bothering to send in something that we # know is definitely not convertible ([int32] on PS5, [long] on PS7). if (($finalResult -isnot [Object[]]) -or - (($finalResult.Count -gt 0) -and ($finalResult[0] -isnot [int]) -and ($finalResult[0] -isnot [long]))) + (($finalResult.Count -gt 0) -and + ($finalResult[0] -isnot [int]) -and + ($finalResult[0] -isnot [long]))) { $finalResult = ConvertTo-SmarterObject -InputObject $finalResult } @@ -424,8 +435,9 @@ function Invoke-GHRestMethod } catch { - # We only know how to handle WebExceptions, which will either come in "pure" when running with -NoStatus, - # or will come in as a RemoteException when running normally (since it's coming from the asynchronous Job). + # We only know how to handle WebExceptions, which will either come in "pure" + # when running with -NoStatus, or will come in as a RemoteException when running + # normally (since it's coming from the asynchronous Job). $ex = $null $message = $null $statusCode = $null @@ -530,7 +542,9 @@ function Invoke-GHRestMethod if ($statusCode -eq 404) { - $output += "This typically happens when the current user isn't properly authenticated. You may need an Access Token with additional scopes checked." + $explanation = @('This typically happens when the current user isn''t properly authenticated.', + 'You may need an Access Token with additional scopes checked.') + $output += ($explanation -join ' ') } if (-not [String]::IsNullOrEmpty($requestId)) @@ -991,7 +1005,8 @@ filter ConvertTo-SmarterObject } catch { - Write-Log -Message "Unable to convert $($property.Name) value of $($property.Value) to a [DateTime] object. Leaving as-is." -Level Verbose + $message = "Unable to convert $($property.Name) value of $($property.Value) to a [DateTime] object. Leaving as-is." + Write-Log -Message $message -Level Verbose } } @@ -1024,10 +1039,15 @@ function Get-MediaAcceptHeader .PARAMETER MediaType The format in which the API will return the body of the comment or issue. - Raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. - Text - Return a text only representation of the markdown body. Response will include body_text. - Html - Return HTML rendered from the body's markdown. Response will include body_html. - Full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. + Raw - Return the raw markdown body. + Response will include body. + This is the default if you do not pass any specific media type. + Text - Return a text only representation of the markdown body. + Response will include body_text. + Html - Return HTML rendered from the body's markdown. + Response will include body_html. + Full - Return raw, text and HTML representations. + Response will include body, body_text, and body_html. Object - Return a json object representation a file or folder. .PARAMETER AsJson diff --git a/GitHubEvents.ps1 b/GitHubEvents.ps1 index 0b618729..c074740b 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -29,10 +29,12 @@ filter Get-GitHubEvent them individually. .PARAMETER EventId - The ID of a specific event to get. If not supplied, will return back all events for this repository. + The ID of a specific event to get. + If not supplied, will return back all events for this repository. .PARAMETER Issue - Issue number to get events for. If not supplied, will return back all events for this repository. + Issue number to get events for. + If not supplied, will return back all events for this repository. .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the diff --git a/GitHubIssueComments.ps1 b/GitHubIssueComments.ps1 index 156c2e16..f4ebdc9e 100644 --- a/GitHubIssueComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -47,10 +47,15 @@ filter Get-GitHubIssueComment .PARAMETER MediaType The format in which the API will return the body of the comment. - Raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. - Text - Return a text only representation of the markdown body. Response will include body_text. - Html - Return HTML rendered from the body's markdown. Response will include body_html. - Full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. + Raw - Return the raw markdown body. + Response will include body. + This is the default if you do not pass any specific media type. + Text - Return a text only representation of the markdown body. + Response will include body_text. + Html - Return HTML rendered from the body's markdown. + Response will include body_html. + Full - Return raw, text and HTML representations. + Response will include body, body_text, and body_html. .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the @@ -384,10 +389,15 @@ filter Set-GitHubIssueComment .PARAMETER MediaType The format in which the API will return the body of the comment. - Raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. - Text - Return a text only representation of the markdown body. Response will include body_text. - Html - Return HTML rendered from the body's markdown. Response will include body_html. - Full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. + Raw - Return the raw markdown body. + Response will include body. + This is the default if you do not pass any specific media type. + Text - Return a text only representation of the markdown body. + Response will include body_text. + Html - Return HTML rendered from the body's markdown. + Response will include body_html. + Full - Return raw, text and HTML representations. + Response will include body, body_text, and body_html. .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the @@ -521,12 +531,14 @@ filter Remove-GitHubIssueComment .EXAMPLE Remove-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Confirm:$false - Deletes a Github comment from an Issue in the microsoft\PowerShellForGitHub project without prompting confirmation. + Deletes a Github comment from an Issue in the microsoft\PowerShellForGitHub project + without prompting confirmation. .EXAMPLE Remove-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 -Force - Deletes a GitHub comment from an Issue in the microsoft\PowerShellForGitHub project without prompting confirmation. + Deletes a GitHub comment from an Issue in the microsoft\PowerShellForGitHub project + without prompting confirmation. #> [CmdletBinding( SupportsShouldProcess, @@ -624,8 +636,11 @@ filter Add-GitHubIssueCommentAdditionalProperties foreach ($item in $InputObject) { - $item.PSObject.TypeNames.Insert(0, $script:GitHubCommentTypeName) # Provide a generic comment type too - $item.PSObject.TypeNames.Insert(0, $TypeName) # We want the specific type on top + # Provide a generic comment type too + $item.PSObject.TypeNames.Insert(0, $script:GitHubCommentTypeName) + + # But we want the specific type on top + $item.PSObject.TypeNames.Insert(0, $TypeName) if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index 51f1b45a..77098945 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -96,10 +96,15 @@ filter Get-GitHubIssue .PARAMETER MediaType The format in which the API will return the body of the issue. - Raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. - Text - Return a text only representation of the markdown body. Response will include body_text. - Html - Return HTML rendered from the body's markdown. Response will include body_html. - Full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. + Raw - Return the raw markdown body. + Response will include body. + This is the default if you do not pass any specific media type. + Text - Return a text only representation of the markdown body. + Response will include body_text. + Html - Return HTML rendered from the body's markdown. + Response will include body_html. + Full - Return raw, text and HTML representations. + Response will include body, body_text, and body_html. .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the @@ -497,10 +502,15 @@ filter New-GitHubIssue .PARAMETER MediaType The format in which the API will return the body of the issue. - Raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. - Text - Return a text only representation of the markdown body. Response will include body_text. - Html - Return HTML rendered from the body's markdown. Response will include body_html. - Full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. + Raw - Return the raw markdown body. + Response will include body. + This is the default if you do not pass any specific media type. + Text - Return a text only representation of the markdown body. + Response will include body_text. + Html - Return HTML rendered from the body's markdown. + Response will include body_html. + Full - Return raw, text and HTML representations. + Response will include body, body_text, and body_html. .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the @@ -645,10 +655,15 @@ filter Update-GitHubIssue .PARAMETER MediaType The format in which the API will return the body of the issue. - Raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. - Text - Return a text only representation of the markdown body. Response will include body_text. - Html - Return HTML rendered from the body's markdown. Response will include body_html. - Full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. + Raw - Return the raw markdown body. + Response will include body. + This is the default if you do not pass any specific media type. + Text - Return a text only representation of the markdown body. + Response will include body_text. + Html - Return HTML rendered from the body's markdown. + Response will include body_html. + Full - Return raw, text and HTML representations. + Response will include body, body_text, and body_html. .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index c3104768..5bcfa80a 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -197,7 +197,8 @@ filter New-GitHubLabel .PARAMETER Label Name of the label to be created. - Emoji and codes are supported. For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ + Emoji and codes are supported. + For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ .PARAMETER Color Color (in HEX) for the new label. @@ -356,12 +357,14 @@ filter Remove-GitHubLabel .EXAMPLE Remove-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -Confirm:$false - Removes the label called "TestLabel" from the PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified. + Removes the label called "TestLabel" from the PowerShellForGitHub project. + Will not prompt for confirmation, as -Confirm:$false was specified. .EXAMPLE Remove-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -Force - Removes the label called "TestLabel" from the PowerShellForGitHub project. Will not prompt for confirmation, as -Force was specified. + Removes the label called "TestLabel" from the PowerShellForGitHub project. + Will not prompt for confirmation, as -Force was specified. #> [CmdletBinding( SupportsShouldProcess, @@ -457,11 +460,13 @@ filter Update-GitHubLabel .PARAMETER Label Current name of the label to be updated. - Emoji and codes are supported. For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ + Emoji and codes are supported. + For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ .PARAMETER NewName New name for the label being updated. - Emoji and codes are supported. For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ + Emoji and codes are supported. + For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ .PARAMETER Color Color (in HEX) for the new label. @@ -885,19 +890,26 @@ function Set-GitHubIssueLabel .EXAMPLE ('help wanted', 'good first issue') | Set-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 - Replaces labels on an issue in the PowerShellForGitHub project with 'help wanted' and 'good first issue'. + Replaces labels on an issue in the PowerShellForGitHub project + with 'help wanted' and 'good first issue'. .EXAMPLE Set-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Confirm:$false - Removes all labels from issue 1 in the PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified. - This is the same result as having called Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Confirm:$false + Removes all labels from issue 1 in the PowerShellForGitHub project. + Will not prompt for confirmation, as -Confirm:$false was specified. + + This is the same result as having called + Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Confirm:$false .EXAMPLE Set-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Force - Removes all labels from issue 1 in the PowerShellForGitHub project. Will not prompt for confirmation, as -Force was specified. - This is the same result as having called Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Force + Removes all labels from issue 1 in the PowerShellForGitHub project. + Will not prompt for confirmation, as -Force was specified. + + This is the same result as having called + Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Force .NOTES This is implemented as a function rather than a filter because the ValueFromPipeline @@ -1027,7 +1039,8 @@ filter Remove-GitHubIssueLabel .PARAMETER Label Name of the label to be deleted. If not provided, will delete all labels on the issue. - Emoji and codes are supported. For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ + Emoji and codes are supported. + For more information, see here: https://www.webpagefx.com/tools/emoji-cheat-sheet/ .PARAMETER Force If this switch is specified, you will not be prompted for confirmation of command execution. @@ -1050,12 +1063,14 @@ filter Remove-GitHubIssueLabel .EXAMPLE Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -Issue 1 -Confirm:$false - Removes the label called "TestLabel" from issue 1 in the PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified. + Removes the label called "TestLabel" from issue 1 in the PowerShellForGitHub project. + Will not prompt for confirmation, as -Confirm:$false was specified. .EXAMPLE Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -Issue 1 -Force - Removes the label called "TestLabel" from issue 1 in the PowerShellForGitHub project. Will not prompt for confirmation, as -Force was specified. + Removes the label called "TestLabel" from issue 1 in the PowerShellForGitHub project. + Will not prompt for confirmation, as -Force was specified. #> [CmdletBinding( SupportsShouldProcess, diff --git a/GitHubMiscellaneous.ps1 b/GitHubMiscellaneous.ps1 index ff7575fc..f54f75a3 100644 --- a/GitHubMiscellaneous.ps1 +++ b/GitHubMiscellaneous.ps1 @@ -48,7 +48,8 @@ function Get-GitHubRateLimit For these reasons, the Rate Limit API response categorizes your rate limit. Under resources, you'll see three objects: - The core object provides your rate limit status for all non-search-related resources in the REST API. + The core object provides your rate limit status for all non-search-related resources + in the REST API. The search object provides your rate limit status for the Search API. The graphql object provides your rate limit status for the GraphQL API. @@ -140,7 +141,9 @@ function ConvertFrom-GitHubMarkdown Mandatory, ValueFromPipeline)] [ValidateNotNullOrEmpty()] - [ValidateScript({if ([System.Text.Encoding]::UTF8.GetBytes($_).Count -lt 400000) { $true } else { throw "Content must be less than 400 KB." }})] + [ValidateScript({ + if ([System.Text.Encoding]::UTF8.GetBytes($_).Count -lt 400000) { $true } + else { throw "Content must be less than 400 KB." }})] [string] $Content, [ValidateSet('Markdown', 'GitHubFlavoredMarkdown')] diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index e9071228..555e5753 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -255,7 +255,8 @@ filter New-GitHubProject .EXAMPLE New-GitHubProject -Uri https://github.com/Microsoft/PowerShellForGitHub -ProjectName TestProject - Create a project for the microsoft\PowerShellForGitHub repository using the Uri called 'TestProject'. + Create a project for the microsoft\PowerShellForGitHub repository + using the Uri called 'TestProject'. .EXAMPLE New-GitHubProject -UserProject -ProjectName 'TestProject' diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index 7e3de9ed..a7ee5729 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -183,7 +183,8 @@ filter New-GitHubPullRequest Create a new pull request in the specified repository. .DESCRIPTION - Opens a new pull request from the given branch into the given branch in the specified repository. + Opens a new pull request from the given branch into the given branch + in the specified repository. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -266,7 +267,9 @@ filter New-GitHubPullRequest #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] - [CmdletBinding(SupportsShouldProcess, DefaultParameterSetName='Elements_Title')] + [CmdletBinding( + SupportsShouldProcess, + DefaultParameterSetName='Elements_Title')] param( [Parameter(ParameterSetName='Elements_Title')] [Parameter(ParameterSetName='Elements_Issue')] diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index 1c3b722c..30e48e20 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -211,7 +211,7 @@ filter Get-GitHubRelease 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubReleaseAdditionalProperties) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index fd06d787..04abff46 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -206,7 +206,7 @@ filter New-GitHubRepository 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } return (Invoke-GHRestMethod @params | Add-GitHubRepositoryAdditionalProperties) @@ -322,7 +322,7 @@ filter Remove-GitHubRepository 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } return Invoke-GHRestMethod @params @@ -430,7 +430,7 @@ filter Get-GitHubRepository .EXAMPLE $repo | Get-GitHubRepository - You can pipe in a previous repository to get its information again. + You can pipe in a previous repository to get its refreshed information. .EXAMPLE Get-GitHubRepository -OrganizationName PowerShell @@ -647,7 +647,7 @@ filter Get-GitHubRepository 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubRepositoryAdditionalProperties) @@ -674,7 +674,8 @@ filter Rename-GitHubRepository .PARAMETER Uri Uri for the repository to rename. You can supply this directly, or more easily by - using Get-GitHubRepository to get the repository as you please, and then piping the result to this cmdlet + using Get-GitHubRepository to get the repository as you please, + and then piping the result to this cmdlet. .PARAMETER NewName The new name to set for the given GitHub repository @@ -698,32 +699,39 @@ filter Rename-GitHubRepository .EXAMPLE Get-GitHubRepository -Owner octocat -RepositoryName hello-world | Rename-GitHubRepository -NewName hello-again-world - Get the given 'hello-world' repo from the user 'octocat' and rename it to be https://github.com/octocat/hello-again-world. + Get the given 'hello-world' repo from the user 'octocat' and then + rename it to be https://github.com/octocat/hello-again-world. .EXAMPLE Get-GitHubRepository -Uri https://github.com/octocat/hello-world | Rename-GitHubRepository -NewName hello-again-world -Confirm:$false - Get the repository at https://github.com/octocat/hello-world and then rename it https://github.com/octocat/hello-again-world. Will not prompt for confirmation, as -Confirm:$false was specified. + Get the repository at https://github.com/octocat/hello-world and then + rename it https://github.com/octocat/hello-again-world. + Will not prompt for confirmation, as -Confirm:$false was specified. .EXAMPLE Rename-GitHubRepository -Uri https://github.com/octocat/hello-world -NewName hello-again-world - Rename the repository at https://github.com/octocat/hello-world to https://github.com/octocat/hello-again-world. + Rename the repository at https://github.com/octocat/hello-world to + https://github.com/octocat/hello-again-world. .EXAMPLE New-GitHubRepositoryFork -Uri https://github.com/octocat/hello-world | Foreach-Object {$_ | Rename-GitHubRepository -NewName "$($_.name)_fork"} - Fork the `hello-world` repository from the user 'octocat', and then rename the newly forked repository by appending '_fork'. + Fork the `hello-world` repository from the user 'octocat', and then + rename the newly forked repository by appending '_fork'. .EXAMPLE Rename-GitHubRepository -Uri https://github.com/octocat/hello-world -NewName hello-again-world -Confirm:$false - Rename the repository at https://github.com/octocat/hello-world to https://github.com/octocat/hello-again-world without prompting for confirmation. + Rename the repository at https://github.com/octocat/hello-world to + https://github.com/octocat/hello-again-world without prompting for confirmation. .EXAMPLE Rename-GitHubRepository -Uri https://github.com/octocat/hello-world -NewName hello-again-world -Force - Rename the repository at https://github.com/octocat/hello-world to https://github.com/octocat/hello-again-world without prompting for confirmation. + Rename the repository at https://github.com/octocat/hello-world to + https://github.com/octocat/hello-again-world without prompting for confirmation. #> [CmdletBinding( SupportsShouldProcess, @@ -979,7 +987,7 @@ filter Update-GitHubRepository 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } return (Invoke-GHRestMethod @params | Add-GitHubRepositoryAdditionalProperties) @@ -1071,7 +1079,7 @@ filter Get-GitHubRepositoryTopic 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } return (Invoke-GHRestMethod @params | @@ -1235,7 +1243,7 @@ function Set-GitHubRepositoryTopic 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } return (Invoke-GHRestMethod @params | @@ -1354,7 +1362,7 @@ filter Get-GitHubRepositoryContributor 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } $results = Invoke-GHRestMethodMultipleResult @params @@ -1479,7 +1487,7 @@ filter Get-GitHubRepositoryCollaborator 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubUserAdditionalProperties) @@ -1570,7 +1578,7 @@ filter Get-GitHubRepositoryLanguage 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } return (Invoke-GHRestMethodMultipleResult @params | @@ -1661,7 +1669,7 @@ filter Get-GitHubRepositoryTag 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } return (Invoke-GHRestMethodMultipleResult @params | @@ -1771,7 +1779,7 @@ filter Move-GitHubRepositoryOwnership 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } return (Invoke-GHRestMethod @params | Add-GitHubRepositoryAdditionalProperties) diff --git a/GitHubRepositoryTraffic.ps1 b/GitHubRepositoryTraffic.ps1 index 5b461927..64739add 100644 --- a/GitHubRepositoryTraffic.ps1 +++ b/GitHubRepositoryTraffic.ps1 @@ -148,7 +148,8 @@ filter Get-GitHubPathTraffic .EXAMPLE Get-GitHubPathTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub - Get the top 10 popular contents over the last 14 days from the microsoft\PowerShellForGitHub project. + Get the top 10 popular contents over the last 14 days + from the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -210,11 +211,13 @@ filter Get-GitHubViewTraffic { <# .SYNOPSIS - Get the total number of views and breakdown per day or week for the last 14 days for the given GitHub Repository. + Get the total number of views and breakdown per day or week for the last 14 days for the + given GitHub Repository. .DESCRIPTION Get the total number of views and breakdown per day or week for the last 14 days. - Timestamps are aligned to UTC midnight of the beginning of the day or week. Week begins on Monday. + Timestamps are aligned to UTC midnight of the beginning of the day or week. + Week begins on Monday. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -250,7 +253,8 @@ filter Get-GitHubViewTraffic .EXAMPLE Get-GitHubViewTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub - Get the total number of views and breakdown per day or week for the last 14 days from the microsoft\PowerShellForGitHub project. + Get the total number of views and breakdown per day or week for the last 14 days from + the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, @@ -316,11 +320,13 @@ filter Get-GitHubCloneTraffic { <# .SYNOPSIS - Get the total number of clones and breakdown per day or week for the last 14 days for the given GitHub Repository. + Get the total number of clones and breakdown per day or week for the last 14 days for the + given GitHub Repository. .DESCRIPTION Get the total number of clones and breakdown per day or week for the last 14 days. - Timestamps are aligned to UTC midnight of the beginning of the day or week. Week begins on Monday. + Timestamps are aligned to UTC midnight of the beginning of the day or week. + Week begins on Monday. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -356,7 +362,8 @@ filter Get-GitHubCloneTraffic .EXAMPLE Get-GitHubCloneTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub - Get the total number of clones and breakdown per day or week for the last 14 days from the microsoft\PowerShellForGitHub project. + Get the total number of clones and breakdown per day or week for the last 14 days + from the microsoft\PowerShellForGitHub project. #> [CmdletBinding( SupportsShouldProcess, diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 78e93cdf..da2564da 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -21,7 +21,8 @@ filter Get-GitHubUser .PARAMETER User The GitHub user to retrieve information for. - If not specified, will retrieve information on all GitHub users (and may take a while to complete). + If not specified, will retrieve information on all GitHub users + (and may take a while to complete). .PARAMETER Current If specified, gets information on the current user. From 13844ff6da92329b9653fb2917a44c6ee84374c5 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Wed, 17 Jun 2020 14:43:57 -0700 Subject: [PATCH 78/80] Getting the formatting of the [Parameter] property consistent across all files --- GitHubBranches.ps1 | 3 +- GitHubContents.ps1 | 8 ++++-- GitHubEvents.ps1 | 59 ++++++++++++++++++++++++++++++--------- GitHubIssueComments.ps1 | 62 +++++++++++++++++++++++++++++++---------- GitHubLabels.ps1 | 23 +++++++++++---- GitHubMilestones.ps1 | 58 ++++++++++++++++++++++++++++---------- GitHubProjects.ps1 | 36 ++++++++++++++++++------ GitHubReleases.ps1 | 24 ++++++---------- GitHubRepositories.ps1 | 4 +-- Helpers.ps1 | 12 ++++---- UpdateCheck.ps1 | 15 ++++++---- 11 files changed, 215 insertions(+), 89 deletions(-) diff --git a/GitHubBranches.ps1 b/GitHubBranches.ps1 index 606c4e11..d8221ec5 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -76,7 +76,8 @@ filter Get-GitHubRepositoryBranch $branch | Get-GitHubRepositoryBranch Gets information only on the master branch for the specified repository, and then does it - again. + again. This tries to show some of the different types of objects you can pipe into this + function. #> [CmdletBinding( SupportsShouldProcess, diff --git a/GitHubContents.ps1 b/GitHubContents.ps1 index 4e1cd084..59677b52 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -88,10 +88,14 @@ [OutputType({$script:GitHubContentTypeName})] [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')] + [Parameter( + Mandatory, + ParameterSetName = 'Elements')] [string] $OwnerName, - [Parameter(Mandatory, ParameterSetName = 'Elements')] + [Parameter( + Mandatory, + ParameterSetName = 'Elements')] [string] $RepositoryName, [Parameter( diff --git a/GitHubEvents.ps1 b/GitHubEvents.ps1 index c074740b..3f1d264d 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -60,28 +60,61 @@ filter Get-GitHubEvent [OutputType({$script:GitHubEventTypeName})] [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='RepositoryElements')] - [Parameter(Mandatory, ParameterSetName='IssueElements')] - [Parameter(Mandatory, ParameterSetName='EventElements')] + [Parameter( + Mandatory, + ParameterSetName='RepositoryElements')] + [Parameter( + Mandatory, + ParameterSetName='IssueElements')] + [Parameter( + Mandatory, + ParameterSetName='EventElements')] [string] $OwnerName, - [Parameter(Mandatory, ParameterSetName='RepositoryElements')] - [Parameter(Mandatory, ParameterSetName='IssueElements')] - [Parameter(Mandatory, ParameterSetName='EventElements')] + [Parameter( + Mandatory, + ParameterSetName='RepositoryElements')] + [Parameter( + Mandatory, + ParameterSetName='IssueElements')] + [Parameter( + Mandatory, + ParameterSetName='EventElements')] [string] $RepositoryName, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='RepositoryUri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='EventUri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='RepositoryUri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='IssueUri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='EventUri')] [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='EventUri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='EventElements')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='EventUri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='EventElements')] [int64] $EventId, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueElements')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='IssueUri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='IssueElements')] [Alias('IssueNumber')] [int64] $Issue, diff --git a/GitHubIssueComments.ps1 b/GitHubIssueComments.ps1 index f4ebdc9e..2274c439 100644 --- a/GitHubIssueComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -100,7 +100,8 @@ filter Get-GitHubIssueComment $comment[0] | Get-GitHubIssueComment Get the most recent comment on Issue #1 in the microsoft\PowerShellForGitHub project by - passing it in via the pipeline. + passing it in via the pipeline. This shows some of the different types of objects you + can pipe into this function. #> [CmdletBinding( SupportsShouldProcess, @@ -109,29 +110,62 @@ filter Get-GitHubIssueComment [OutputType({$script:GitHubIssueCommentTypeName})] [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='RepositoryElements')] - [Parameter(Mandatory, ParameterSetName='IssueElements')] - [Parameter(Mandatory, ParameterSetName='CommentElements')] + [Parameter( + Mandatory, + ParameterSetName='RepositoryElements')] + [Parameter( + Mandatory, + ParameterSetName='IssueElements')] + [Parameter( + Mandatory, + ParameterSetName='CommentElements')] [string] $OwnerName, - [Parameter(Mandatory, ParameterSetName='RepositoryElements')] - [Parameter(Mandatory, ParameterSetName='IssueElements')] - [Parameter(Mandatory, ParameterSetName='CommentElements')] + [Parameter( + Mandatory, + ParameterSetName='RepositoryElements')] + [Parameter( + Mandatory, + ParameterSetName='IssueElements')] + [Parameter( + Mandatory, + ParameterSetName='CommentElements')] [string] $RepositoryName, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='RepositoryUri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='CommentUri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='RepositoryUri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='IssueUri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='CommentUri')] [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='CommentElements')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='CommentUri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='CommentElements')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='CommentUri')] [Alias('CommentId')] [string] $Comment, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueElements')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='IssueUri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='IssueElements')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='IssueUri')] [Alias('IssueNumber')] [int64] $Issue, diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 5bcfa80a..b7e93059 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -76,13 +76,20 @@ filter Get-GitHubLabel [OutputType({$script:GitHubLabelTypeName})] [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')] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $OwnerName, - [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $RepositoryName, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='Uri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Uri')] [Alias('RepositoryUrl')] [string] $Uri, @@ -161,7 +168,7 @@ filter Get-GitHubLabel $params = @{ 'UriFragment' = $uriFragment 'Description' = $description - 'AcceptHeader' = $scrit:symmetraAcceptHeader + 'AcceptHeader' = $script:symmetraAcceptHeader 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -760,10 +767,14 @@ function Add-GitHubIssueLabel [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( diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index 77d66098..ee0bd4bb 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -71,12 +71,20 @@ filter Get-GitHubMilestone DefaultParameterSetName='RepositoryElements')] [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='MilestoneElements')] - [Parameter(Mandatory, ParameterSetName='RepositoryElements')] + [Parameter( + Mandatory, + ParameterSetName='MilestoneElements')] + [Parameter( + Mandatory, + ParameterSetName='RepositoryElements')] [string] $OwnerName, - [Parameter(Mandatory, ParameterSetName='MilestoneElements')] - [Parameter(Mandatory, ParameterSetName='RepositoryElements')] + [Parameter( + Mandatory, + ParameterSetName='MilestoneElements')] + [Parameter( + Mandatory, + ParameterSetName='RepositoryElements')] [string] $RepositoryName, [Parameter( @@ -259,10 +267,14 @@ filter New-GitHubMilestone 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')] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $OwnerName, - [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $RepositoryName, [Parameter( @@ -421,10 +433,14 @@ filter Set-GitHubMilestone 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')] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $OwnerName, - [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $RepositoryName, [Parameter( @@ -445,8 +461,12 @@ filter Set-GitHubMilestone [Alias('MilestoneNumber')] [int64] $Milestone, - [Parameter(Mandatory, ParameterSetName='Uri')] - [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter( + Mandatory, + ParameterSetName='Uri')] + [Parameter( + Mandatory, + ParameterSetName='Elements')] [string] $Title, [ValidateSet('Open', 'Closed')] @@ -577,10 +597,14 @@ filter Remove-GitHubMilestone [Alias('Delete-GitHubMilestone')] [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( @@ -590,8 +614,14 @@ filter Remove-GitHubMilestone [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='Uri')] - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='Elements')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Uri')] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName='Elements')] [Alias('MilestoneNumber')] [int64] $Milestone, diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 555e5753..b6c4ba15 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -89,10 +89,14 @@ filter Get-GitHubProject [OutputType({$script:GitHubPullRequestTypeName})] [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')] + [Parameter( + Mandatory, + ParameterSetName = 'Elements')] [string] $OwnerName, - [Parameter(Mandatory, ParameterSetName = 'Elements')] + [Parameter( + Mandatory, + ParameterSetName = 'Elements')] [string] $RepositoryName, [Parameter( @@ -106,10 +110,14 @@ filter Get-GitHubProject [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName = 'Organization')] + [Parameter( + Mandatory, + ParameterSetName = 'Organization')] [string] $OrganizationName, - [Parameter(Mandatory, ParameterSetName = 'User')] + [Parameter( + Mandatory, + ParameterSetName = 'User')] [string] $UserName, [Parameter( @@ -269,10 +277,14 @@ filter New-GitHubProject [OutputType({$script:GitHubPullRequestTypeName})] [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')] + [Parameter( + Mandatory, + ParameterSetName = 'Elements')] [string] $OwnerName, - [Parameter(Mandatory, ParameterSetName = 'Elements')] + [Parameter( + Mandatory, + ParameterSetName = 'Elements')] [string] $RepositoryName, [Parameter( @@ -282,10 +294,14 @@ filter New-GitHubProject [Alias('RepositoryUrl')] [string] $Uri, - [Parameter(Mandatory, ParameterSetName = 'Organization')] + [Parameter( + Mandatory, + ParameterSetName = 'Organization')] [string] $OrganizationName, - [Parameter(Mandatory, ParameterSetName = 'User')] + [Parameter( + Mandatory, + ParameterSetName = 'User')] [switch] $UserProject, [Parameter( @@ -537,7 +553,9 @@ filter Remove-GitHubProject [Alias('Delete-GitHubProject')] [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, ValueFromPipelineByPropertyName)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] [Alias('ProjectId')] [int64] $Project, diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index 30e48e20..844516ff 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -96,24 +96,16 @@ filter Get-GitHubRelease [OutputType({$script:GitHubReleaseTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( - [Parameter( - ParameterSetName='Elements')] - [Parameter( - ParameterSetName="Elements-ReleaseId")] - [Parameter( - ParameterSetName="Elements-Latest")] - [Parameter( - ParameterSetName="Elements-Tag")] + [Parameter(ParameterSetName='Elements')] + [Parameter(ParameterSetName="Elements-ReleaseId")] + [Parameter(ParameterSetName="Elements-Latest")] + [Parameter(ParameterSetName="Elements-Tag")] [string] $OwnerName, - [Parameter( - ParameterSetName='Elements')] - [Parameter( - ParameterSetName="Elements-ReleaseId")] - [Parameter( - ParameterSetName="Elements-Latest")] - [Parameter( - ParameterSetName="Elements-Tag")] + [Parameter(ParameterSetName='Elements')] + [Parameter(ParameterSetName="Elements-ReleaseId")] + [Parameter(ParameterSetName="Elements-Latest")] + [Parameter(ParameterSetName="Elements-Tag")] [string] $RepositoryName, [Parameter( diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 04abff46..930d50ec 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -465,8 +465,8 @@ filter Get-GitHubRepository ParameterSetName='Organization')] [string] $OrganizationName, - [ValidateSet('All', 'Public', 'Private')] [Parameter(ParameterSetName='AuthenticatedUser')] + [ValidateSet('All', 'Public', 'Private')] [string] $Visibility, [Parameter(ParameterSetName='AuthenticatedUser')] @@ -1631,7 +1631,7 @@ filter Get-GitHubRepositoryTag [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [OutputType({$scrit:GitHubRepositoryTagTypeName})] + [OutputType({$script:GitHubRepositoryTagTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] diff --git a/Helpers.ps1 b/Helpers.ps1 index 1813d168..17fa80e2 100644 --- a/Helpers.ps1 +++ b/Helpers.ps1 @@ -281,13 +281,13 @@ function Write-Log [System.Management.Automation.ErrorRecord] $Exception ) - Begin + begin { # Accumulate the list of Messages, whether by pipeline or parameter. $messages = @() } - Process + process { foreach ($m in $Message) { @@ -295,7 +295,7 @@ function Write-Log } } - End + end { if ($null -ne $Exception) { @@ -499,6 +499,7 @@ function Write-InvocationLog } function DeepCopy-Object +{ <# .SYNOPSIS Creates a deep copy of a serializable object. @@ -524,7 +525,6 @@ function DeepCopy-Object .RETURNS An exact copy of the PSObject that was just deep copied. #> -{ [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseApprovedVerbs", "", Justification="Intentional. This isn't exported, and needed to be explicit relative to Copy-Object.")] param( @@ -682,9 +682,7 @@ function Resolve-UnverifiedPath #> [CmdletBinding()] param( - [Parameter( - Position=0, - ValueFromPipeline)] + [Parameter(ValueFromPipeline)] [string] $Path ) diff --git a/UpdateCheck.ps1 b/UpdateCheck.ps1 index c76bb253..0773f60c 100644 --- a/UpdateCheck.ps1 +++ b/UpdateCheck.ps1 @@ -58,7 +58,8 @@ function Invoke-UpdateCheck if ($state -eq 'Failed') { # We'll just assume we're up-to-date if we failed to check today. - Write-Log -Message '[$moduleName] update check failed for today (web request failed). Assuming up-to-date.' -Level Verbose + $message = '[$moduleName] update check failed for today (web request failed). Assuming up-to-date.' + Write-Log -Message $message -Level Verbose $script:HasLatestVersion = $true # Clear out the job info (even though we don't need the result) @@ -81,22 +82,26 @@ function Invoke-UpdateCheck $script:HasLatestVersion = $latestVersion -eq $moduleVersion if ($script:HasLatestVersion) { - Write-Log "[$moduleName] update check complete. Running latest version: $latestVersion" -Level Verbose + $message = "[$moduleName] update check complete. Running latest version: $latestVersion" + Write-Log =Message $message -Level Verbose } elseif ($moduleVersion -gt $latestVersion) { - Write-Log "[$moduleName] update check complete. This version ($moduleVersion) is newer than the latest published version ($latestVersion)." -Level Verbose + $message = "[$moduleName] update check complete. This version ($moduleVersion) is newer than the latest published version ($latestVersion)." + Write-Log -Message $message -Level Verbose } else { - Write-Log "A newer version of $moduleName is available ($latestVersion). Your current version is $moduleVersion. Run 'Update-Module $moduleName' to get up-to-date." -Level Warning + $message = "A newer version of $moduleName is available ($latestVersion). Your current version is $moduleVersion. Run 'Update-Module $moduleName' to get up-to-date." + Write-Log -Message $message -Level Warning } } catch { # This could happen if the server returned back an invalid (non-XML) response for the request # for some reason. - Write-Log -Message "[$moduleName] update check failed for today (invalid XML response). Assuming up-to-date." -Level Verbose + $message = "[$moduleName] update check failed for today (invalid XML response). Assuming up-to-date." + Write-Log -Message $message -Level Verbose $script:HasLatestVersion = $true } From 34f9f3e35b78c05d86b7f32e6fea981278f58943 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Wed, 17 Jun 2020 17:11:14 -0700 Subject: [PATCH 79/80] Updating INPUTS for all functions and adding RepositoryUrl to GitHub.Content --- GitHubAnalytics.ps1 | 7 ++ GitHubAssignees.ps1 | 63 +++++++++++ GitHubBranches.ps1 | 21 ++++ GitHubContents.ps1 | 32 ++++++ GitHubCore.ps1 | 13 +++ GitHubEvents.ps1 | 21 ++++ GitHubIssueComments.ps1 | 68 ++++++++++++ GitHubIssues.ps1 | 97 +++++++++++++++++ GitHubLabels.ps1 | 138 ++++++++++++++++++++++-- GitHubMilestones.ps1 | 66 ++++++++++++ GitHubMiscellaneous.ps1 | 41 ++++++++ GitHubOrganizations.ps1 | 12 +++ GitHubProjectCards.ps1 | 27 +++++ GitHubProjectColumns.ps1 | 29 +++++ GitHubProjects.ps1 | 66 ++++++++++++ GitHubPullRequests.ps1 | 34 +++++- GitHubReleases.ps1 | 21 ++++ GitHubRepositories.ps1 | 186 +++++++++++++++++++++++++++++++++ GitHubRepositoryForks.ps1 | 30 ++++++ GitHubRepositoryTraffic.ps1 | 60 +++++++++++ GitHubTeams.ps1 | 39 +++++++ GitHubUsers.ps1 | 16 +++ Tests/GitHubContents.tests.ps1 | 11 +- 23 files changed, 1089 insertions(+), 9 deletions(-) diff --git a/GitHubAnalytics.ps1 b/GitHubAnalytics.ps1 index 623b723f..0ee2310b 100644 --- a/GitHubAnalytics.ps1 +++ b/GitHubAnalytics.ps1 @@ -24,6 +24,9 @@ function Group-GitHubIssue The date property that should be inspected when determining which week grouping the issue if part of. + .INPUTS + GitHub.Issue + .OUTPUTS [PSCustomObject[]] Collection of issues and counts, by week, along with the total count of issues. @@ -149,6 +152,9 @@ function Group-GitHubPullRequest The date property that should be inspected when determining which week grouping the pull request if part of. + .INPUTS + GitHub.PullRequest + .OUTPUTS [PSCustomObject[]] Collection of pull requests and counts, by week, along with the total count of pull requests. @@ -274,6 +280,7 @@ function Get-WeekDate Get-WeekDate -Weeks 10 #> [CmdletBinding()] + [OutputType([DateTime[]])] param( [ValidateRange(0, 10000)] [int] $Weeks = 12 diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index 421a5b47..eccc9810 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -32,6 +32,22 @@ filter Get-GitHubAssignee the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + GitHub.User + .OUTPUTS GitHub.User @@ -128,6 +144,22 @@ filter Test-GitHubAssignee the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + GitHub.User + .OUTPUTS [bool] If the assignee can be assigned to issues in the repository. @@ -255,6 +287,22 @@ function New-GitHubAssignee the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + GitHub.User + .OUTPUTS GitHub.Issue @@ -415,6 +463,21 @@ function Remove-GitHubAssignee the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Issue diff --git a/GitHubBranches.ps1 b/GitHubBranches.ps1 index d8221ec5..357d5792 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -44,6 +44,21 @@ filter Get-GitHubRepositoryBranch the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Branch List of branches within the given repository. @@ -150,6 +165,12 @@ filter Add-GitHubBranchAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.Branch #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/GitHubContents.ps1 b/GitHubContents.ps1 index 59677b52..1514382e 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -56,6 +56,25 @@ the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + + .OUTPUTS + [String] + GitHub.Content + .EXAMPLE Get-GitHubContent -OwnerName microsoft -RepositoryName PowerShellForGitHub -Path README.md -MediaType Html @@ -189,6 +208,12 @@ filter Add-GitHubContentAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.Content #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] @@ -208,6 +233,13 @@ filter Add-GitHubContentAdditionalProperties { $item.PSObject.TypeNames.Insert(0, $TypeName) + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + $elements = Split-GitHubUri -Uri $item.url + $repositoryUrl = Join-GitHubUri @elements + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + } + Write-Output $item } } \ No newline at end of file diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 860a3a62..542ae5a8 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -743,6 +743,9 @@ filter Split-GitHubUri .PARAMETER RepositoryName Returns the Repository Name from the Uri if it can be identified. + .INPUTS + [String] + .OUTPUTS [PSCustomObject] - The OwnerName and RepositoryName elements from the provided URL @@ -960,6 +963,12 @@ filter ConvertTo-SmarterObject .PARAMETER InputObject The object to update + + .INPUTS + [object] + + .OUTPUTS + [object] #> [CmdletBinding()] param( @@ -1056,12 +1065,16 @@ function Get-MediaAcceptHeader .PARAMETER AcceptHeader The accept header that should be included with the MediaType accept header. + .OUTPUTS + [String] + .EXAMPLE Get-MediaAcceptHeader -MediaType Raw Returns a formatted AcceptHeader for v3 of the response object #> [CmdletBinding()] + [OutputType([String])] param( [ValidateSet('Raw', 'Text', 'Html', 'Full', 'Object')] [string] $MediaType = 'Raw', diff --git a/GitHubEvents.ps1 b/GitHubEvents.ps1 index 3f1d264d..c904bc6a 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -46,6 +46,21 @@ filter Get-GitHubEvent the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Event @@ -180,6 +195,12 @@ filter Add-GitHubEventAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.Event #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/GitHubIssueComments.ps1 b/GitHubIssueComments.ps1 index 2274c439..a388db93 100644 --- a/GitHubIssueComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -67,6 +67,21 @@ filter Get-GitHubIssueComment the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.IssueComment @@ -316,6 +331,22 @@ filter New-GitHubIssueComment the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + GitHub.User + .OUTPUTS GitHub.IssueComment @@ -443,6 +474,22 @@ filter Set-GitHubIssueComment the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + GitHub.User + .OUTPUTS GitHub.IssueComment @@ -557,6 +604,21 @@ filter Remove-GitHubIssueComment the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .EXAMPLE Remove-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Comment 1 @@ -653,6 +715,12 @@ filter Add-GitHubIssueCommentAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.IssueComment #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index 77098945..8e903c00 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -116,6 +116,22 @@ filter Get-GitHubIssue the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + GitHub.User + .OUTPUTS GitHub.Issue @@ -399,6 +415,21 @@ filter Get-GitHubIssueTimeline the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Event @@ -522,6 +553,21 @@ filter New-GitHubIssue the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Issue @@ -675,6 +721,21 @@ filter Update-GitHubIssue the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Issue @@ -809,6 +870,21 @@ filter Lock-GitHubIssue the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .EXAMPLE Lock-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 4 -Title 'Test Issue' -Reason Spam #> @@ -924,6 +1000,21 @@ filter Unlock-GitHubIssue the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .EXAMPLE Unlock-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 4 #> @@ -993,6 +1084,12 @@ filter Add-GitHubIssueAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.Issue #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index b7e93059..b020e54c 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -51,6 +51,21 @@ filter Get-GitHubLabel the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Label @@ -223,6 +238,21 @@ filter New-GitHubLabel the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Label @@ -349,6 +379,21 @@ filter Remove-GitHubLabel the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .EXAMPLE Remove-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel @@ -491,6 +536,21 @@ filter Update-GitHubLabel the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Label @@ -621,12 +681,20 @@ filter Set-GitHubLabel the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. - .NOTES - This method does not rename any existing labels, as it doesn't have any context regarding - which Label the new name is for. Therefore, it is possible that by running this function - on a repository with Issues that have already been assigned Labels, you may experience data - loss as a minor correction to you (maybe fixing a typo) will result in the old Label being - removed (and thus unassigned from existing Issues) and then the new one created. + .INPUTS + GitHub.Branch + GitHub.Content + GitHub.Event + GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + GitHub.Release + GitHub.Repository .EXAMPLE Set-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label @(@{'name' = 'TestLabel'; 'color' = 'EEEEEE'}, @{'name' = 'critical'; 'color' = 'FF000000'; 'description' = 'Needs immediate attention'}) @@ -634,6 +702,13 @@ filter Set-GitHubLabel Removes any labels not in this Label array, ensure the current assigned color and descriptions match what's in the array for the labels that do already exist, and then creates new labels for any remaining ones in the Label list. + + .NOTES + This method does not rename any existing labels, as it doesn't have any context regarding + which Label the new name is for. Therefore, it is possible that by running this function + on a repository with Issues that have already been assigned Labels, you may experience data + loss as a minor correction to you (maybe fixing a typo) will result in the old Label being + removed (and thus unassigned from existing Issues) and then the new one created. #> [CmdletBinding( SupportsShouldProcess, @@ -745,6 +820,21 @@ function Add-GitHubIssueLabel the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Label @@ -890,6 +980,21 @@ function Set-GitHubIssueLabel the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Label @@ -1066,6 +1171,21 @@ filter Remove-GitHubIssueLabel the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .EXAMPLE Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -Issue 1 @@ -1178,6 +1298,12 @@ filter Add-GitHubLabelAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.Label #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index ee0bd4bb..70b5b003 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -55,6 +55,21 @@ filter Get-GitHubMilestone the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Milestone @@ -242,6 +257,21 @@ filter New-GitHubMilestone the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Milestone @@ -408,6 +438,21 @@ filter Set-GitHubMilestone the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Milestone @@ -573,6 +618,21 @@ filter Remove-GitHubMilestone the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .EXAMPLE Remove-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1 @@ -676,6 +736,12 @@ filter Add-GitHubMilestoneAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.Milestone #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/GitHubMiscellaneous.ps1 b/GitHubMiscellaneous.ps1 index f54f75a3..b137d6ea 100644 --- a/GitHubMiscellaneous.ps1 +++ b/GitHubMiscellaneous.ps1 @@ -124,6 +124,9 @@ function ConvertFrom-GitHubMarkdown the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + [String] + .OUTPUTS [String] The HTML version of the Markdown content. @@ -232,6 +235,24 @@ 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 + GitHub.Content + GitHub.Event + GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + GitHub.Release + GitHub.Repository + + .OUTPUTS GitHub.License @@ -443,6 +464,23 @@ filter Get-GitHubCodeOfConduct 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 + GitHub.Content + GitHub.Event + GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + GitHub.Release + GitHub.Repository + + .OUTPUTS GitHub.CodeOfConduct @@ -573,6 +611,9 @@ filter Get-GitHubGitIgnore the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + [String] + .OUTPUTS GitHub.Gitignore diff --git a/GitHubOrganizations.ps1 b/GitHubOrganizations.ps1 index 62c8ee2e..021ba709 100644 --- a/GitHubOrganizations.ps1 +++ b/GitHubOrganizations.ps1 @@ -31,6 +31,9 @@ filter Get-GitHubOrganizationMember the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + [String] + .OUTPUTS GitHub.User List of members within the organization. @@ -101,6 +104,9 @@ filter Test-GitHubOrganizationMember the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + [String] + .OUTPUTS [Bool] @@ -169,6 +175,12 @@ filter Add-GitHubOrganizationAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.Organization #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/GitHubProjectCards.ps1 b/GitHubProjectCards.ps1 index 814beda1..ed911fa5 100644 --- a/GitHubProjectCards.ps1 +++ b/GitHubProjectCards.ps1 @@ -32,6 +32,10 @@ filter Get-GitHubProjectCard the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.ProjectCard + GitHub.ProjectColumn + .OUTPUTS GitHub.ProjectCard @@ -161,6 +165,13 @@ filter New-GitHubProjectCard the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.IssueComment + GitHub.Issue + GitHub.PullRequest + GitHub.ProjectCard + GitHub.ProjectColumn + .OUTPUTS GitHub.ProjectCard @@ -295,6 +306,9 @@ filter Set-GitHubProjectCard the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.ProjectCard + .OUTPUTS GitHub.ProjectCard @@ -405,6 +419,9 @@ filter Remove-GitHubProjectCard the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.ProjectCard + .EXAMPLE Remove-GitHubProjectCard -Card 999999 @@ -501,6 +518,10 @@ filter Move-GitHubProjectCard the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.ProjectCard + GitHub.ProjectColumn + .EXAMPLE Move-GitHubProjectCard -Card 999999 -Top @@ -610,6 +631,12 @@ filter Add-GitHubProjectCardAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.ProjectCard #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index 86235287..f65cd309 100644 --- a/GitHubProjectColumns.ps1 +++ b/GitHubProjectColumns.ps1 @@ -31,6 +31,11 @@ filter Get-GitHubProjectColumn the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + .OUTPUTS GitHub.ProjectColumn @@ -130,6 +135,12 @@ filter New-GitHubProjectColumn 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.Project + GitHub.ProjectCard + GitHub.ProjectColumn + .OUTPUTS GitHub.ProjectColumn @@ -212,6 +223,10 @@ filter Set-GitHubProjectColumn the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.ProjectCard + GitHub.ProjectColumn + .OUTPUTS GitHub.ProjectColumn @@ -290,6 +305,10 @@ filter Remove-GitHubProjectColumn the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.ProjectCard + GitHub.ProjectColumn + .EXAMPLE Remove-GitHubProjectColumn -Column 999999 @@ -384,6 +403,10 @@ filter Move-GitHubProjectColumn the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.ProjectCard + GitHub.ProjectColumn + .EXAMPLE Move-GitHubProjectColumn -Column 999999 -First @@ -476,6 +499,12 @@ filter Add-GitHubProjectColumnAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.ProjectColumn #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index b6c4ba15..3476f263 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -50,6 +50,21 @@ filter Get-GitHubProject the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Project @@ -247,6 +262,21 @@ filter New-GitHubProject the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Project @@ -412,6 +442,21 @@ filter Set-GitHubProject the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Project @@ -525,6 +570,21 @@ filter Remove-GitHubProject the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .EXAMPLE Remove-GitHubProject -Project 4387531 @@ -607,6 +667,12 @@ filter Add-GitHubProjectAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.Project #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index a7ee5729..c08c887a 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -64,9 +64,24 @@ filter Get-GitHubPullRequest the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. - .OUTPUTS + .INPUTS + GitHub.Branch + GitHub.Content + GitHub.Event + GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + GitHub.Release GitHub.Repository + .OUTPUTS + GitHub.PulLRequest + .EXAMPLE $pullRequests = Get-GitHubPullRequest -Uri 'https://github.com/PowerShell/PowerShellForGitHub' @@ -244,9 +259,24 @@ filter New-GitHubPullRequest the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. - .OUTPUTS + .INPUTS + GitHub.Branch + GitHub.Content + GitHub.Event + GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + GitHub.Release GitHub.Repository + .OUTPUTS + GitHub.PullRequest + .EXAMPLE $prParams = @{ OwnerName = 'Microsoft' diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index 844516ff..6083f669 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -53,6 +53,21 @@ filter Get-GitHubRelease the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Release @@ -221,6 +236,12 @@ filter Add-GitHubReleaseAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.Release #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 930d50ec..c59e33e5 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -95,6 +95,21 @@ filter New-GitHubRepository the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Repository @@ -249,6 +264,21 @@ filter Remove-GitHubRepository the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .EXAMPLE Remove-GitHubRepository -OwnerName You -RepositoryName YourRepoToDelete @@ -399,6 +429,21 @@ filter Get-GitHubRepository the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Repository @@ -693,6 +738,21 @@ filter Rename-GitHubRepository the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Repository @@ -859,6 +919,21 @@ filter Update-GitHubRepository the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Repository @@ -1027,6 +1102,21 @@ filter Get-GitHubRepositoryTopic the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.RepositoryTopic @@ -1126,6 +1216,21 @@ function Set-GitHubRepositoryTopic the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.RepositoryTopic @@ -1298,6 +1403,21 @@ filter Get-GitHubRepositoryContributor the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.User GitHub.RepositoryContributorStatistics @@ -1430,6 +1550,21 @@ filter Get-GitHubRepositoryCollaborator the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.User @@ -1527,6 +1662,21 @@ filter Get-GitHubRepositoryLanguage the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.RepositoryLanguage - The value shown for each language is the number of bytes of code written in that language. @@ -1619,6 +1769,21 @@ filter Get-GitHubRepositoryTag the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.RepositoryTag @@ -1717,6 +1882,21 @@ filter Move-GitHubRepositoryOwnership the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Repository @@ -1804,6 +1984,12 @@ filter Add-GitHubRepositoryAdditionalProperties .PARAMETER RepositoryName Name of the repository. This information might be obtainable from InputObject, so this is optional based on what InputObject contains. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.Repository #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/GitHubRepositoryForks.ps1 b/GitHubRepositoryForks.ps1 index d0327904..3322c726 100644 --- a/GitHubRepositoryForks.ps1 +++ b/GitHubRepositoryForks.ps1 @@ -38,6 +38,21 @@ filter Get-GitHubRepositoryFork the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Repository @@ -140,6 +155,21 @@ filter New-GitHubRepositoryFork the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.Repository diff --git a/GitHubRepositoryTraffic.ps1 b/GitHubRepositoryTraffic.ps1 index 64739add..bcdcda13 100644 --- a/GitHubRepositoryTraffic.ps1 +++ b/GitHubRepositoryTraffic.ps1 @@ -44,6 +44,21 @@ filter Get-GitHubReferrerTraffic the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.ReferrerTraffic @@ -142,6 +157,21 @@ filter Get-GitHubPathTraffic the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.PathTraffic @@ -247,6 +277,21 @@ filter Get-GitHubViewTraffic the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.ViewTraffic @@ -356,6 +401,21 @@ filter Get-GitHubCloneTraffic the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + .OUTPUTS GitHub.CloneTraffic diff --git a/GitHubTeams.ps1 b/GitHubTeams.ps1 index 538b52c7..fa6da2cc 100644 --- a/GitHubTeams.ps1 +++ b/GitHubTeams.ps1 @@ -47,6 +47,23 @@ filter Get-GitHubTeam the background, enabling the command prompt to provide status information. 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.Organization + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + GitHub.Release + GitHub.Repository + GitHub.Team + .OUTPUTS GitHub.Team @@ -170,6 +187,22 @@ filter Get-GitHubTeamMember the background, enabling the command prompt to provide status information. 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.Release + GitHub.Repository + GitHub.Team + .OUTPUTS GitHub.User @@ -254,6 +287,12 @@ filter Add-GitHubTeamAdditionalProperties .PARAMETER TypeName The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.Team #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index da2564da..ed2b2cb9 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -46,6 +46,9 @@ filter Get-GitHubUser which provides an email entry for this endpoint. If the user does not set a public email address for email, then it will have a value of null. + .INPUTS + GitHub.User + .OUTPUTS GitHub.User @@ -159,6 +162,13 @@ filter Get-GitHubUserContextualInformation 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.Organization + GitHub.PullRequest + GitHub.Repository + GitHub.User + .OUTPUTS GitHub.UserContextualInformation @@ -408,6 +418,12 @@ filter Add-GitHubUserAdditionalProperties .PARAMETER Id The ID of the user. This information might be obtainable from InputObject, so this is optional based on what InputObject contains. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.User #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] diff --git a/Tests/GitHubContents.tests.ps1 b/Tests/GitHubContents.tests.ps1 index eda60f03..806d373c 100644 --- a/Tests/GitHubContents.tests.ps1 +++ b/Tests/GitHubContents.tests.ps1 @@ -67,8 +67,9 @@ try $folderOutput.entries[0].path | Should -Be $readmeFileName } - It "Should have the expected type" { + It "Should have the expected type and additional properties" { $folderOutput.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + $folderOutput.RepositoryUrl | Should -Be $repo.RepositoryUrl } } @@ -98,6 +99,7 @@ try It "Should have the expected type" { $folderOutput.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + $folderOutput.RepositoryUrl | Should -Be $repo.RepositoryUrl } } @@ -127,6 +129,7 @@ try It "Should have the expected type" { $folderOutput.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + $folderOutput.RepositoryUrl | Should -Be $repo.RepositoryUrl } } @@ -140,6 +143,7 @@ try It "Should have the expected type" { $readmeFileString.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Content' + $readmeFileString.RepositoryUrl | Should -BeNullOrEmpty } } @@ -152,6 +156,7 @@ try It "Should have the expected type" { $readmeFileString.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Content' + $readmeFileString.RepositoryUrl | Should -BeNullOrEmpty } } @@ -170,6 +175,7 @@ try It "Should have the expected type" { $readmeNoBreaks.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Content' + $readmeNoBreaks.RepositoryUrl | Should -BeNullOrEmpty } } @@ -187,6 +193,7 @@ try It "Should have the expected type" { $readmeFileString.PSObject.TypeNames[0] | Should -Not -Be 'GitHub.Content' + $readmeFileString.RepositoryUrl | Should -BeNullOrEmpty } } @@ -217,6 +224,7 @@ try It "Should have the expected type" { $readmeFileObject.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + $readmeFileObject.RepositoryUrl | Should -Be $repo.RepositoryUrl } } @@ -242,6 +250,7 @@ try It "Should have the expected type" { $readmeFileObject.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' + $readmeFileObject.RepositoryUrl | Should -Be $repo.RepositoryUrl } } } From 1095a3d43d63a67cd4a8f7a4098412fe6eae1c71 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Wed, 17 Jun 2020 22:23:13 -0700 Subject: [PATCH 80/80] Minor update to CONTRIBUTING.md --- CONTRIBUTING.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 498d5130..1f690f71 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -336,6 +336,11 @@ new functionality added to the module embraces this design. and you should be sure to both specify it in the `.OUTPUTS` section of the Comment Based Help (CBH) for the command, as well as with `[OutputType({$script:GitHubUserTypeName})]` (for example). + * Going along with the `.OUTPUTS` is the `.INPUTS` section. Please maintain this section as well. + If you add any new type that will gain a `RepositoryUrl` property, then you'll need to update + virtually _all_ of the `.INPUTS` entries across all of the files where the function has a `Uri` + parameter. Please keep these type names alphabetical. + * To enable debugging issues involving pipeline support, there is an additional configuration property that you might use: `Set-GitHubConfiguration -DisablePipelineSupport`. That will prevent the module from adding _any_ additional properties to the objects.