Skip to content

Commit ea0356f

Browse files
Merge branch 'master' into issue-#96-gitrefs-implement
2 parents 111ed3f + 742b853 commit ea0356f

File tree

4 files changed

+204
-34
lines changed

4 files changed

+204
-34
lines changed

Diff for: .github/PULL_REQUEST_TEMPLATE.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
-->
77
#### Description
88

9-
109
#### Issues Fixed
1110
<!--
1211
If this PR does not fix an open issue, replace this comment block with None.
@@ -17,6 +16,11 @@
1716
- Fixes #124
1817
-->
1918

19+
#### References
20+
<!--
21+
If you are adding/changing functionality based on the GitHub API, please provide
22+
a link to the relevant documentation so that the changes can be more easily verified.
23+
-->
2024

2125
#### Checklist
2226
<!--

Diff for: CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ Thank you to all of our contributors, no matter how big or small the contributio
485485
- **[Matt Boren (@mtboren)](https://github.com./mtboren)**
486486
- **[Shannon Deminick (@Shazwazza)](https://github.com./Shazwazza)**
487487
- **[Jess Pomfret (@jpomfret)](https://github.com./jpomfret)**
488+
- **[Giuseppe Campanelli (@themilanfan)](https://github.com./themilanfan)**
488489

489490
----------
490491

Diff for: GitHubRepositories.ps1

+10-4
Original file line numberDiff line numberDiff line change
@@ -1033,12 +1033,18 @@ function Set-GitHubRepositoryTopic
10331033
'Clear' = $PSBoundParameters.ContainsKey('Clear')
10341034
}
10351035

1036-
$description = "Replacing topics in $RepositoryName"
1037-
if ($Clear) { $description = "Clearing topics in $RepositoryName" }
1036+
if ($Clear)
1037+
{
1038+
$description = "Clearing topics in $RepositoryName"
1039+
$Name = @()
1040+
}
1041+
else
1042+
{
1043+
$description = "Replacing topics in $RepositoryName"
1044+
}
10381045

1039-
$names = @($Name)
10401046
$hashBody = @{
1041-
'names' = $names
1047+
'names' = $Name
10421048
}
10431049

10441050
$params = @{

Diff for: Tests/GitHubRepositories.tests.ps1

+188-29
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
<#
55
.Synopsis
66
Tests for GitHubRepositories.ps1 module
7-
.Description
8-
Many cmdlets are indirectly tested in the course of other tests (New-GitHubRepository, Remove-GitHubRepository), and may not have explicit tests here
97
#>
108

119
# This is common test code setup logic for all Pester test files
@@ -14,6 +12,15 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent
1412

1513
try
1614
{
15+
# Define Script-scoped, readonly, hidden variables.
16+
@{
17+
defaultRepoDesc = "This is a description."
18+
defaultRepoHomePage = "https://www.microsoft.com/"
19+
defaultRepoTopic = "microsoft"
20+
}.GetEnumerator() | ForEach-Object {
21+
Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value
22+
}
23+
1724
Describe 'Getting repositories' {
1825
Context 'For authenticated user' {
1926
BeforeAll -Scriptblock {
@@ -25,22 +32,23 @@ try
2532
$privateRepo = $privateRepo
2633
}
2734

28-
$publicRepos = @(Get-GitHubRepository -Visibility Public)
29-
$privateRepos = @(Get-GitHubRepository -Visibility Private)
30-
3135
It "Should have the public repo" {
32-
$publicRepo.Name | Should BeIn $publicRepos.Name
33-
$publicRepo.Name | Should Not BeIn $privateRepos.Name
36+
$publicRepos = @(Get-GitHubRepository -Visibility Public)
37+
$privateRepos = @(Get-GitHubRepository -Visibility Private)
38+
$publicRepo.name | Should -BeIn $publicRepos.name
39+
$publicRepo.name | Should -Not -BeIn $privateRepos.name
3440
}
3541

3642
It "Should have the private repo" {
37-
$privateRepo.Name | Should BeIn $privateRepos.Name
38-
$privateRepo.Name | Should Not BeIn $publicRepos.Name
43+
$publicRepos = @(Get-GitHubRepository -Visibility Public)
44+
$privateRepos = @(Get-GitHubRepository -Visibility Private)
45+
$privateRepo.name | Should -BeIn $privateRepos.name
46+
$privateRepo.name | Should -Not -BeIn $publicRepos.name
3947
}
4048

4149
It 'Should not permit bad combination of parameters' {
42-
{ Get-GitHubRepository -Type All -Visibility All } | Should Throw
43-
{ Get-GitHubRepository -Type All -Affiliation Owner } | Should Throw
50+
{ Get-GitHubRepository -Type All -Visibility All } | Should -Throw
51+
{ Get-GitHubRepository -Type All -Affiliation Owner } | Should -Throw
4452
}
4553

4654
AfterAll -ScriptBlock {
@@ -50,11 +58,10 @@ try
5058
}
5159

5260
Context 'For any user' {
53-
$repos = @(Get-GitHubRepository -OwnerName 'octocat' -Type Public)
54-
5561
It "Should have results for The Octocat" {
62+
$repos = @(Get-GitHubRepository -OwnerName 'octocat' -Type Public)
5663
$repos.Count | Should -BeGreaterThan 0
57-
$repos[0].owner.login | Should Be 'octocat'
64+
$repos[0].owner.login | Should -Be 'octocat'
5865
}
5966
}
6067

@@ -66,9 +73,9 @@ try
6673
$repo = $repo
6774
}
6875

69-
$repos = @(Get-GitHubRepository -OrganizationName $script:organizationName -Type All)
7076
It "Should have results for the organization" {
71-
$repo.name | Should BeIn $repos.name
77+
$repos = @(Get-GitHubRepository -OrganizationName $script:organizationName -Type All)
78+
$repo.name | Should -BeIn $repos.name
7279
}
7380

7481
AfterAll -ScriptBlock {
@@ -82,30 +89,60 @@ try
8289
}
8390

8491
Context 'For a specific repo' {
85-
BeforeAll -Scriptblock {
92+
BeforeAll -ScriptBlock {
8693
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
8794

8895
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
8996
$repo = $repo
9097
}
9198

92-
$result = Get-GitHubRepository -Uri $repo.svn_url
9399
It "Should be a single result using Uri ParameterSet" {
100+
$result = Get-GitHubRepository -Uri $repo.svn_url
94101
$result | Should -BeOfType PSCustomObject
95102
}
96103

97-
$result = Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.Name
98104
It "Should be a single result using Elements ParameterSet" {
105+
$result = Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name
99106
$result | Should -BeOfType PSCustomObject
100107
}
101108

102109
It 'Should not permit additional parameters' {
103-
{ Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.Name -Type All } | Should Throw
110+
{ Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Type All } | Should -Throw
104111
}
105112

106113
It 'Should require both OwnerName and RepositoryName' {
107-
{ Get-GitHubRepository -RepositoryName $repo.Name } | Should Throw
108-
{ Get-GitHubRepository -Uri "https://github.com./$script:ownerName" } | Should Throw
114+
{ Get-GitHubRepository -RepositoryName $repo.name } | Should -Throw
115+
{ Get-GitHubRepository -Uri "https://github.com./$script:ownerName" } | Should -Throw
116+
}
117+
118+
AfterAll -ScriptBlock {
119+
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
120+
}
121+
}
122+
}
123+
124+
Describe 'Creating repositories' {
125+
126+
Context -Name 'For creating a repository' -Fixture {
127+
BeforeAll -ScriptBlock {
128+
$repoName = ([Guid]::NewGuid().Guid)
129+
$repo = New-GitHubRepository -RepositoryName $repoName -Description $defaultRepoDesc -AutoInit
130+
131+
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
132+
$repoName = $repoName
133+
$repo = $repo
134+
}
135+
136+
It 'Should get repository' {
137+
$repo | Should -Not -BeNullOrEmpty
138+
}
139+
140+
It 'Name is correct' {
141+
$repo.name | Should -Be $repoName
142+
}
143+
144+
It 'Description is correct' {
145+
$repo.description | Should -Be $defaultRepoDesc
109146
}
110147

111148
AfterAll -ScriptBlock {
@@ -114,30 +151,152 @@ try
114151
}
115152
}
116153

117-
Describe 'Modifying repositories' {
154+
Describe 'Deleting repositories' {
155+
156+
Context -Name 'For deleting a repository' -Fixture {
157+
BeforeAll -ScriptBlock {
158+
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -Description $defaultRepoDesc -AutoInit
159+
160+
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
161+
$repo = $repo
162+
}
163+
164+
It 'Should get no content' {
165+
Remove-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Confirm:$false
166+
{ Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name } | Should -Throw
167+
}
168+
}
169+
}
170+
171+
Describe 'Renaming repositories' {
172+
118173
Context -Name 'For renaming a repository' -Fixture {
119174
BeforeEach -Scriptblock {
120175
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
121176
$suffixToAddToRepo = "_renamed"
122-
$newRepoName = "$($repo.Name)$suffixToAddToRepo"
123-
Write-Verbose "New repo name shall be: '$newRepoName'"
177+
$newRepoName = "$($repo.name)$suffixToAddToRepo"
178+
179+
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
180+
$newRepoName = $newRepoName
124181
}
182+
125183
It "Should have the expected new repository name - by URI" {
126184
$renamedRepo = $repo | Rename-GitHubRepository -NewName $newRepoName -Confirm:$false
127-
$renamedRepo.Name | Should be $newRepoName
185+
$renamedRepo.name | Should -Be $newRepoName
128186
}
129187

130188
It "Should have the expected new repository name - by Elements" {
131189
$renamedRepo = Rename-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -NewName $newRepoName -Confirm:$false
132-
$renamedRepo.Name | Should be $newRepoName
190+
$renamedRepo.name | Should -Be $newRepoName
133191
}
134-
## cleanup temp testing repository
192+
135193
AfterEach -Scriptblock {
136-
## variables from BeforeEach scriptblock are accessible here, but not variables from It scriptblocks, so need to make URI (instead of being able to use $renamedRepo variable from It scriptblock)
137194
Remove-GitHubRepository -Uri "$($repo.svn_url)$suffixToAddToRepo" -Confirm:$false
138195
}
139196
}
140197
}
198+
199+
Describe 'Updating repositories' {
200+
201+
Context -Name 'For creating a repository' -Fixture {
202+
BeforeAll -ScriptBlock {
203+
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -Description $defaultRepoDesc -AutoInit
204+
205+
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
206+
$repo = $repo
207+
}
208+
209+
It 'Should have the new updated description' {
210+
$modifiedRepoDesc = $defaultRepoDesc + "_modified"
211+
$updatedRepo = Update-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Description $modifiedRepoDesc
212+
$updatedRepo.description | Should -Be $modifiedRepoDesc
213+
}
214+
215+
It 'Should have the new updated homepage url' {
216+
$updatedRepo = Update-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Homepage $defaultRepoHomePage
217+
$updatedRepo.homepage | Should -Be $defaultRepoHomePage
218+
}
219+
220+
AfterAll -ScriptBlock {
221+
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
222+
}
223+
}
224+
}
225+
226+
Describe 'Get/set repository topic' {
227+
228+
Context -Name 'For creating and getting a repository topic' -Fixture {
229+
BeforeAll -ScriptBlock {
230+
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
231+
232+
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
233+
$repo = $repo
234+
}
235+
236+
It 'Should have the expected topic' {
237+
Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name -Name $defaultRepoTopic
238+
$topic = Get-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name
239+
$topic.names | Should -Be $defaultRepoTopic
240+
}
241+
242+
It 'Should have no topics' {
243+
Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name -Clear
244+
$topic = Get-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name
245+
$topic.names | Should -BeNullOrEmpty
246+
}
247+
248+
AfterAll -ScriptBlock {
249+
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
250+
}
251+
}
252+
}
253+
254+
Describe 'Get repository languages' {
255+
256+
Context -Name 'For getting repository languages' -Fixture {
257+
BeforeAll -ScriptBlock {
258+
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
259+
260+
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
261+
$repo = $repo
262+
}
263+
264+
It 'Should be empty' {
265+
$languages = Get-GitHubRepositoryLanguage -OwnerName $repo.owner.login -RepositoryName $repo.name
266+
$languages | Should -BeNullOrEmpty
267+
}
268+
269+
It 'Should contain PowerShell' {
270+
$languages = Get-GitHubRepositoryLanguage -OwnerName "microsoft" -RepositoryName "PowerShellForGitHub"
271+
$languages.PowerShell | Should -Not -BeNullOrEmpty
272+
}
273+
274+
AfterAll -ScriptBlock {
275+
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
276+
}
277+
}
278+
}
279+
280+
Describe 'Get repository tags' {
281+
282+
Context -Name 'For getting repository tags' -Fixture {
283+
BeforeAll -ScriptBlock {
284+
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
285+
286+
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
287+
$repo = $repo
288+
}
289+
290+
It 'Should be empty' {
291+
$tags = Get-GitHubRepositoryTag -OwnerName $repo.owner.login -RepositoryName $repo.name
292+
$tags | Should -BeNullOrEmpty
293+
}
294+
295+
AfterAll -ScriptBlock {
296+
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
297+
}
298+
}
299+
}
141300
}
142301
finally
143302
{

0 commit comments

Comments
 (0)