Skip to content

Commit

Permalink
Fix pipeline support and testing for New-GitHubRepositoryFromTemplate
Browse files Browse the repository at this point in the history
Added in microsoft#221, `New-GitHubRepositoryFromTemplate was not capturing
the passed-in value for the RepositoryName if provided via a Uri
parameter.

There was a pipeline test in place, however it missed this fact
because it was only testing the pipeline input scenario using `-WhatIf`,
and the error was only found when calling the actual REST API and
GitHub noticed that the `RepositoryName` was missing from the URI.
  • Loading branch information
HowardWolosky committed Jun 30, 2020
1 parent 4287ac9 commit 4ad189e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions GitHubRepositories.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ filter New-GitHubRepositoryFromTemplate

$elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters
$OwnerName = $elements.ownerName
$RepositoryName = $elements.repositoryName

$telemetryProperties = @{
RepositoryName = (Get-PiiSafeString -PlainText $RepositoryName)
Expand Down
38 changes: 35 additions & 3 deletions Tests/GitHubRepositories.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,48 @@ try
}

$repo = New-GitHubRepositoryFromTemplate @newGitHubRepositoryFromTemplateParms
Start-Sleep -Seconds 1 # To work around a delay that GitHub may have with generating the repo
}

It 'Should support pipeline input for the uri parameter' {
It 'Should have the expected type and addititional properties' {
$repo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository'
$repo.name | Should -Be $repoName
$repo.private | Should -BeFalse
$repo.owner.login | Should -Be $script:ownerName
$repo.description | Should -Be $newRepoDesc
$repo.is_template | Should -BeFalse
$repo.RepositoryId | Should -Be $repo.id
$repo.RepositoryUrl | Should -Be $repo.html_url
}

It 'Should have created a .gitignore file' {
{ Get-GitHubContent -Uri $repo.svn_url -Path '.gitignore' } | Should -Not -Throw
}

It 'Should have created a LICENSE file' {
{ Get-GitHubContent -Uri $repo.svn_url -Path 'LICENSE' } | Should -Not -Throw
}

AfterAll {
if (Get-Variable -Name repo -ErrorAction SilentlyContinue)
{
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
}

Context 'When creating a public repository from a template (via pipeline input)' {
BeforeAll {
$repoName = ([Guid]::NewGuid().Guid)
$newRepoDesc = 'New Repo Description'
$newGitHubRepositoryFromTemplateParms = @{
TargetOwnerName = $ownerName
TargetRepositoryName = $repoName
Description = $newRepoDesc
}

{ $templateRepo | New-GitHubRepositoryFromTemplate @newGitHubRepositoryFromTemplateParms -WhatIf } |
Should -Not -Throw
$repo = $templateRepo | New-GitHubRepositoryFromTemplate @newGitHubRepositoryFromTemplateParms
Start-Sleep -Seconds 1 # To work around a delay that GitHub may have with generating the repo
}

It 'Should have the expected type and addititional properties' {
Expand Down

0 comments on commit 4ad189e

Please sign in to comment.