Skip to content

Commit

Permalink
Initial thinking on pipelining
Browse files Browse the repository at this point in the history
  • Loading branch information
HowardWolosky committed Jun 4, 2020
1 parent 742b853 commit c1e88b6
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 8 deletions.
35 changes: 35 additions & 0 deletions GitHubCore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,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
{
<#
Expand Down
84 changes: 76 additions & 8 deletions GitHubRepositories.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,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
Expand Down Expand Up @@ -237,7 +242,9 @@ function Remove-GitHubRepository

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='Uri')]
[Alias('RepositoryUrl')]
[string] $Uri,

[string] $AccessToken,
Expand Down Expand Up @@ -380,7 +387,9 @@ function Get-GitHubRepository

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='Uri')]
[Alias('RepositoryUrl')]
[string] $Uri,

[Parameter(ParameterSetName='Organization')]
Expand Down Expand Up @@ -572,7 +581,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
Expand Down Expand Up @@ -642,10 +659,11 @@ function Rename-GitHubRepository
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='Uri')]
[Alias("html_url")]
[Alias("RepositoryUrl")]
[string] $Uri,

[parameter(Mandatory)][String]$NewName,
[parameter(Mandatory)]
[String]$NewName,

[string] $AccessToken,

Expand Down Expand Up @@ -678,7 +696,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
}
}
}
Expand Down Expand Up @@ -776,7 +799,9 @@ function Update-GitHubRepository

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='Uri')]
[Alias('RepositoryUrl')]
[string] $Uri,

[string] $Description,
Expand Down Expand Up @@ -844,7 +869,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
Expand Down Expand Up @@ -900,7 +930,9 @@ function Get-GitHubRepositoryTopic

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='Uri')]
[Alias('RepositoryUrl')]
[string] $Uri,

[string] $AccessToken,
Expand Down Expand Up @@ -931,6 +963,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
Expand Down Expand Up @@ -994,10 +1031,13 @@ function Set-GitHubRepositoryTopic

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='UriName')]
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='UriClear')]
[Alias('RepositoryUrl')]
[string] $Uri,

[Parameter(
Expand Down Expand Up @@ -1060,6 +1100,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
Expand Down Expand Up @@ -1131,7 +1176,9 @@ function Get-GitHubRepositoryContributor

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='Uri')]
[Alias('RepositoryUrl')]
[string] $Uri,

[switch] $IncludeAnonymousContributors,
Expand Down Expand Up @@ -1230,7 +1277,9 @@ function Get-GitHubRepositoryCollaborator

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='Uri')]
[Alias('RepositoryUrl')]
[string] $Uri,

[string] $AccessToken,
Expand Down Expand Up @@ -1318,7 +1367,9 @@ function Get-GitHubRepositoryLanguage

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='Uri')]
[Alias('RepositoryUrl')]
[string] $Uri,

[string] $AccessToken,
Expand Down Expand Up @@ -1402,7 +1453,9 @@ function Get-GitHubRepositoryTag

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='Uri')]
[Alias('RepositoryUrl')]
[string] $Uri,

[string] $AccessToken,
Expand Down Expand Up @@ -1430,7 +1483,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
Expand Down Expand Up @@ -1491,7 +1552,9 @@ function Move-GitHubRepositoryOwnership

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='Uri')]
[Alias('RepositoryUrl')]
[string] $Uri,

[Parameter(Mandatory)]
Expand Down Expand Up @@ -1533,5 +1596,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
}

0 comments on commit c1e88b6

Please sign in to comment.