Skip to content

Commit f31d791

Browse files
Fix pipeline support and testing for New-GitHubRepositoryFromTemplate (#259)
Added in #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.
1 parent 4287ac9 commit f31d791

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

GitHubRepositories.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ filter New-GitHubRepositoryFromTemplate
364364

365365
$elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters
366366
$OwnerName = $elements.ownerName
367+
$RepositoryName = $elements.repositoryName
367368

368369
$telemetryProperties = @{
369370
RepositoryName = (Get-PiiSafeString -PlainText $RepositoryName)

Tests/GitHubRepositories.tests.ps1

+35-3
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,48 @@ try
321321
}
322322

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

326-
It 'Should support pipeline input for the uri parameter' {
327+
It 'Should have the expected type and addititional properties' {
328+
$repo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository'
329+
$repo.name | Should -Be $repoName
330+
$repo.private | Should -BeFalse
331+
$repo.owner.login | Should -Be $script:ownerName
332+
$repo.description | Should -Be $newRepoDesc
333+
$repo.is_template | Should -BeFalse
334+
$repo.RepositoryId | Should -Be $repo.id
335+
$repo.RepositoryUrl | Should -Be $repo.html_url
336+
}
337+
338+
It 'Should have created a .gitignore file' {
339+
{ Get-GitHubContent -Uri $repo.svn_url -Path '.gitignore' } | Should -Not -Throw
340+
}
341+
342+
It 'Should have created a LICENSE file' {
343+
{ Get-GitHubContent -Uri $repo.svn_url -Path 'LICENSE' } | Should -Not -Throw
344+
}
345+
346+
AfterAll {
347+
if (Get-Variable -Name repo -ErrorAction SilentlyContinue)
348+
{
349+
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
350+
}
351+
}
352+
}
353+
354+
Context 'When creating a public repository from a template (via pipeline input)' {
355+
BeforeAll {
356+
$repoName = ([Guid]::NewGuid().Guid)
357+
$newRepoDesc = 'New Repo Description'
327358
$newGitHubRepositoryFromTemplateParms = @{
328359
TargetOwnerName = $ownerName
329360
TargetRepositoryName = $repoName
361+
Description = $newRepoDesc
330362
}
331363

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

336368
It 'Should have the expected type and addititional properties' {

0 commit comments

Comments
 (0)