From 78acd2381563854883b483940fe424ad165a89d1 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sun, 31 May 2020 10:59:41 +0100 Subject: [PATCH 1/8] GitHubRepositores: Add Output Types --- PowerShellForGitHub.Format.ps1xml | 29 +++++++++++++++++++++++++++++ PowerShellForGitHub.psd1 | 3 +++ 2 files changed, 32 insertions(+) create mode 100644 PowerShellForGitHub.Format.ps1xml diff --git a/PowerShellForGitHub.Format.ps1xml b/PowerShellForGitHub.Format.ps1xml new file mode 100644 index 00000000..7a8820cc --- /dev/null +++ b/PowerShellForGitHub.Format.ps1xml @@ -0,0 +1,29 @@ + + + + + + GitHub.Repository + + GitHub.Repository + + + + + + + full_name + + + private + + + description + + + + + + + + diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index c7f51c82..594d4ba3 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -13,6 +13,9 @@ # Script module or binary module file associated with this manifest. RootModule = 'PowerShellForGitHub.psm1' + # Format files (.ps1xml) to be loaded when importing this module + FormatsToProcess = 'PowerShellForGitHub.Format.ps1xml' + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess NestedModules = @( # Ideally this list would be kept completely alphabetical, but other scripts (like From 9a2ec77477a0655f074ecd92afeece671bf6cc63 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sun, 31 May 2020 12:18:20 +0100 Subject: [PATCH 2/8] Update formats --- PowerShellForGitHub.Format.ps1xml | 116 ++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/PowerShellForGitHub.Format.ps1xml b/PowerShellForGitHub.Format.ps1xml index 7a8820cc..a8de034b 100644 --- a/PowerShellForGitHub.Format.ps1xml +++ b/PowerShellForGitHub.Format.ps1xml @@ -25,5 +25,121 @@ + + + GitHub.RepositoryTopic + + GitHub.RepositoryTopic + + + + + + + names + + + + + + + + + GitHub.RepositoryContributor + + GitHub.RepositoryContributor + + + + + + + login + + + type + + + contributions + + + + + + + + + GitHub.RepositoryCollaborator + + GitHub.RepositoryCollaborator + + + + + + + + + + + + + + + + + + + login + + + + $_.permissions.admin + + + + + $_.permissions.push + + + + + $_.permissions.pull + + + + + + + + + + GitHub.RepositoryTag + + GitHub.RepositoryTag + + + + + + + + + + + + + name + + + + $_.commit.sha + + + + + + + From 0a099aa6a7a7cedfd94f9c336b83079e49b98b65 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 2 Jun 2020 17:39:55 +0100 Subject: [PATCH 3/8] Review updates --- PowerShellForGitHub.Format.ps1xml | 2 +- PowerShellForGitHub.wiki | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 160000 PowerShellForGitHub.wiki diff --git a/PowerShellForGitHub.Format.ps1xml b/PowerShellForGitHub.Format.ps1xml index a8de034b..dd3a7ea6 100644 --- a/PowerShellForGitHub.Format.ps1xml +++ b/PowerShellForGitHub.Format.ps1xml @@ -15,7 +15,7 @@ full_name - private + visibility description diff --git a/PowerShellForGitHub.wiki b/PowerShellForGitHub.wiki new file mode 160000 index 00000000..7b089874 --- /dev/null +++ b/PowerShellForGitHub.wiki @@ -0,0 +1 @@ +Subproject commit 7b0898749c804dd96ffd059fead279df50122702 From d7b8789b13edadc06238e8a8462aaf3c89884301 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 2 Jun 2020 18:16:03 +0100 Subject: [PATCH 4/8] Review updates --- .../GitHubRepositories.Format.ps1xml | 0 PowerShellForGitHub.psd1 | 4 +++- 2 files changed, 3 insertions(+), 1 deletion(-) rename PowerShellForGitHub.Format.ps1xml => Formatters/GitHubRepositories.Format.ps1xml (100%) diff --git a/PowerShellForGitHub.Format.ps1xml b/Formatters/GitHubRepositories.Format.ps1xml similarity index 100% rename from PowerShellForGitHub.Format.ps1xml rename to Formatters/GitHubRepositories.Format.ps1xml diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index 594d4ba3..7ddf4e1b 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -14,7 +14,9 @@ RootModule = 'PowerShellForGitHub.psm1' # Format files (.ps1xml) to be loaded when importing this module - FormatsToProcess = 'PowerShellForGitHub.Format.ps1xml' + FormatsToProcess = @( + 'Formatters/GitHubRepositories.Format.ps1xml' + ) # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess NestedModules = @( From 6da99b89ab078cbe348dec8ebf3c6f9bec0fd44d Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sun, 21 Jun 2020 11:49:22 +0100 Subject: [PATCH 5/8] Remove Wiki --- PowerShellForGitHub.wiki | 1 - 1 file changed, 1 deletion(-) delete mode 160000 PowerShellForGitHub.wiki diff --git a/PowerShellForGitHub.wiki b/PowerShellForGitHub.wiki deleted file mode 160000 index 7b089874..00000000 --- a/PowerShellForGitHub.wiki +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7b0898749c804dd96ffd059fead279df50122702 From ecbabdc445c49016dbaaef1fb2a94893be8df6f3 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 27 Jun 2020 17:29:13 +0100 Subject: [PATCH 6/8] Typename updates --- GitHubRepositories.ps1 | 197 ++++++++++++++++++++++++++++- Tests/GitHubRepositories.tests.ps1 | 8 +- 2 files changed, 197 insertions(+), 8 deletions(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 50849b7a..fe2a0404 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -4,6 +4,8 @@ @{ GitHubRepositoryTypeName = 'GitHub.Repository' GitHubRepositoryTopicTypeName = 'GitHub.RepositoryTopic' + GitHubRepositoryContributorTypeName = 'GitHub.RepositoryContributor' + GitHubRepositoryCollaboratorTypeName = 'GitHub.RepositoryCollaborator' GitHubRepositoryContributorStatisticsTypeName = 'GitHub.RepositoryContributorStatistics' GitHubRepositoryLanguageTypeName = 'GitHub.RepositoryLanguage' GitHubRepositoryTagTypeName = 'GitHub.RepositoryTag' @@ -1606,7 +1608,7 @@ filter Get-GitHubRepositoryContributor [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [OutputType({$script:GitHubUserTypeName})] + [OutputType({$script:GitHubRepositoryContributorTypeName})] [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.")] [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.")] @@ -1679,7 +1681,7 @@ filter Get-GitHubRepositoryContributor } else { - $results = $results | Add-GitHubUserAdditionalProperties + $results = $results | Add-GitHubRepositoryContributorAdditionalProperties } return $results @@ -1753,7 +1755,7 @@ filter Get-GitHubRepositoryCollaborator [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [OutputType({$script:GitHubUserTypeName})] + [OutputType({$script:GitHubRepositoryCollaboratorTypeName})] [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( @@ -1802,7 +1804,8 @@ filter Get-GitHubRepositoryCollaborator 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return (Invoke-GHRestMethodMultipleResult @params | Add-GitHubUserAdditionalProperties) + return (Invoke-GHRestMethodMultipleResult @params | + Add-GitHubRepositoryCollaboratorAdditionalProperties) } filter Get-GitHubRepositoryLanguage @@ -2850,3 +2853,189 @@ filter Add-GitHubRepositoryAdditionalProperties Write-Output $item } } + +filter Add-GitHubRepositoryContributorAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Contributor 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 Contributor. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. + + .PARAMETER Id + The ID of the Contributor. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. + + .INPUTS + PSCustomObject + + .OUTPUTS + GitHub.RepositoryContributor +#> + [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:GitHubRepositoryContributorTypeName, + + [string] $Name, + + [int64] $Id + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + $UserName = $item.login + if ([String]::IsNullOrEmpty($UserName) -and $PSBoundParameters.ContainsKey('Name')) + { + $UserName = $Name + } + + if (-not [String]::IsNullOrEmpty($UserName)) + { + $addMemberParms = @{ + InputObject = $item + Name = 'UserName' + Value = $UserName + MemberType = 'NoteProperty' + Force = $true + } + Add-Member @addMemberParms + } + + $UserId = $item.id + if (($UserId -eq 0) -and $PSBoundParameters.ContainsKey('Id')) + { + $UserId = $Id + } + + if ($UserId -ne 0) + { + $addMemberParms = @{ + InputObject = $item + Name = 'UserId' + Value = $UserId + MemberType = 'NoteProperty' + Force = $true + } + + Add-Member @addMemberParms + } + } + + Write-Output $item + } +} + +filter Add-GitHubRepositoryCollaboratorAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Collaborator 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 Collaborator. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. + + .PARAMETER Id + The ID of the Collaborator. This information might be obtainable from InputObject, so this + is optional based on what InputObject contains. + + .INPUTS + PSCustomObject + + .OUTPUTS + GitHub.RepositoryCollaborator +#> + [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:GitHubRepositoryCollaboratorTypeName, + + [string] $Name, + + [int64] $Id + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + $UserName = $item.login + if ([String]::IsNullOrEmpty($UserName) -and $PSBoundParameters.ContainsKey('Name')) + { + $UserName = $Name + } + + if (-not [String]::IsNullOrEmpty($UserName)) + { + $addMemberParms = @{ + InputObject = $item + Name = 'UserName' + Value = $UserName + MemberType = 'NoteProperty' + Force = $true + } + + Add-Member @addMemberParms + } + + $UserId = $item.id + if (($UserId -eq 0) -and $PSBoundParameters.ContainsKey('Id')) + { + $UserId = $Id + } + + if ($UserId -ne 0) + { + $addMemberParms = @{ + InputObject = $item + Name = 'UserId' + Value = $UserId + MemberType = 'NoteProperty' + Force = $true + } + + Add-Member @addMemberParms + } + } + + Write-Output $item + } +} diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 6575f249..96e90cff 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -840,7 +840,7 @@ try It 'Should return expected number of contributors' { $contributors.Count | Should -Be 1 - $contributors[0].PSObject.TypeNames[0] = 'GitHub.User' + $contributors[0].PSObject.TypeNames[0] = 'GitHub.RepositoryContributor' } } @@ -849,7 +849,7 @@ try It 'Should return expected number of contributors' { $contributors.Count | Should -Be 1 - $contributors[0].PSObject.TypeNames[0] = 'GitHub.User' + $contributors[0].PSObject.TypeNames[0] = 'GitHub.RepositoryContributor' } } @@ -878,7 +878,7 @@ try It 'Should return expected number of collaborators' { $collaborators.Count | Should -Be 1 - $collaborators[0].PSObject.TypeNames[0] = 'GitHub.User' + $collaborators[0].PSObject.TypeNames[0] = 'GitHub.RepositoryCollaborator' } } @@ -887,7 +887,7 @@ try It 'Should return expected number of collaborators' { $collaborators.Count | Should -Be 1 - $collaborators[0].PSObject.TypeNames[0] = 'GitHub.User' + $collaborators[0].PSObject.TypeNames[0] = 'GitHub.RepositoryCollaborator' } } } From d3d5df1151eab512d7d9446251fdb732de49dda1 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 27 Jun 2020 17:29:27 +0100 Subject: [PATCH 7/8] Type view updates --- Formatters/GitHubRepositories.Format.ps1xml | 40 +++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/Formatters/GitHubRepositories.Format.ps1xml b/Formatters/GitHubRepositories.Format.ps1xml index dd3a7ea6..5325fd19 100644 --- a/Formatters/GitHubRepositories.Format.ps1xml +++ b/Formatters/GitHubRepositories.Format.ps1xml @@ -38,6 +38,9 @@ names + + RepositoryUrl + @@ -54,7 +57,7 @@ - login + UserName type @@ -67,6 +70,39 @@ + + + GitHub.RepositoryContributorStatistics + + GitHub.RepositoryContributorStatistics + + + + + + + + + + + + + + + $_.author.UserName + + + + total + + + weeks + + + + + + GitHub.RepositoryCollaborator @@ -90,7 +126,7 @@ - login + UserName From db557628afd909d2aef5770a36f7fa0f3975e7b7 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 27 Jun 2020 23:08:35 +0100 Subject: [PATCH 8/8] Fix review comments --- GitHubRepositories.ps1 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index fe2a0404..f5c0d8f4 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -2997,18 +2997,18 @@ filter Add-GitHubRepositoryCollaboratorAdditionalProperties if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) { - $UserName = $item.login - if ([String]::IsNullOrEmpty($UserName) -and $PSBoundParameters.ContainsKey('Name')) + $userName = $item.login + if ([String]::IsNullOrEmpty($userName) -and $PSBoundParameters.ContainsKey('Name')) { - $UserName = $Name + $userName = $Name } - if (-not [String]::IsNullOrEmpty($UserName)) + if (-not [String]::IsNullOrEmpty($userName)) { $addMemberParms = @{ InputObject = $item Name = 'UserName' - Value = $UserName + Value = $userName MemberType = 'NoteProperty' Force = $true } @@ -3016,18 +3016,18 @@ filter Add-GitHubRepositoryCollaboratorAdditionalProperties Add-Member @addMemberParms } - $UserId = $item.id - if (($UserId -eq 0) -and $PSBoundParameters.ContainsKey('Id')) + $userId = $item.id + if (($userId -eq 0) -and $PSBoundParameters.ContainsKey('Id')) { - $UserId = $Id + $userId = $Id } - if ($UserId -ne 0) + if ($userId -ne 0) { $addMemberParms = @{ InputObject = $item Name = 'UserId' - Value = $UserId + Value = $userId MemberType = 'NoteProperty' Force = $true }