Skip to content

Commit 22e06e8

Browse files
🚀 [Feature]: Rename parameter from 'Repository' to 'Name' in Get-GitHubRepository functions and update related tests (#325)
## Description This pull request includes changes to the `Get-GitHubRepository` function and its associated tests. The main updates involve renaming a parameter and restructuring the tests to improve clarity and maintainability. 🚀 As this is a breaking change, but still in a "prerelease", ill only bump the minor version. Changes to `Get-GitHubRepository` function: * Renamed the `$Repository` parameter to `$Name` in `src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1` and `src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1`. [[1]](diffhunk://#diff-b4a4cb5e832f1cfd8800d3475420db564b0f9143e06e1308d9ead8becf326f8aL31-R31) [[2]](diffhunk://#diff-b4a4cb5e832f1cfd8800d3475420db564b0f9143e06e1308d9ead8becf326f8aL48-R48) [[3]](diffhunk://#diff-66a3268a746481d358ea9af82c325602932d961a369436ab797b92f608f0e782L92-R92) [[4]](diffhunk://#diff-66a3268a746481d358ea9af82c325602932d961a369436ab797b92f608f0e782L208-R208) Changes to tests: * Removed redundant test contexts related to `Get-GitHubRepository` in `tests/API.Tests.ps1`. [[1]](diffhunk://#diff-b500c6dc057d1bba6364ffe23cfa1c71971e3212b5227ff6201f612930b5d9ddL80-L99) [[2]](diffhunk://#diff-b500c6dc057d1bba6364ffe23cfa1c71971e3212b5227ff6201f612930b5d9ddL187-L206) * Added a new test file `tests/Repositories.Tests.ps1` with structured test cases for different authentication methods, including fine-grained PAT tokens, classic PAT tokens, GitHub Actions, and GitHub Apps. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [x] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent a7cbcc5 commit 22e06e8

File tree

4 files changed

+112
-46
lines changed

4 files changed

+112
-46
lines changed

‎src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
# The name of the repository without the .git extension. The name is not case sensitive.
3030
[Parameter(Mandatory)]
31-
[string] $Repository,
31+
[string] $Name,
3232

3333
# The context to run the command in. Used to get the details for the API call.
3434
# Can be either a string or a GitHubContext object.
@@ -45,7 +45,7 @@
4545
process {
4646
$inputObject = @{
4747
Method = 'GET'
48-
APIEndpoint = "/repos/$Owner/$Repository"
48+
APIEndpoint = "/repos/$Owner/$Name"
4949
Context = $Context
5050
}
5151

‎src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ filter Get-GitHubRepository {
8989
Mandatory,
9090
ParameterSetName = 'ByName'
9191
)]
92-
[string] $Repository,
92+
[string] $Name,
9393

9494
# The handle for the GitHub user account.
9595
[Parameter(
@@ -203,9 +203,9 @@ filter Get-GitHubRepository {
203203
}
204204
'ByName' {
205205
$params = @{
206-
Context = $Context
207-
Owner = $Owner
208-
Repository = $Repository
206+
Context = $Context
207+
Owner = $Owner
208+
Name = $Name
209209
}
210210
$params | Remove-HashtableEntry -NullOrEmptyValues
211211
Write-Verbose ($params | Format-List | Out-String)

‎tests/API.Tests.ps1

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,6 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)
7777
{ Get-GitHubLicense -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw
7878
}
7979
}
80-
Context 'Repository' {
81-
It "Get-GitHubRepository - Gets the authenticated user's repositories (USER_FG_PAT)" {
82-
{ Get-GitHubRepository } | Should -Not -Throw
83-
}
84-
It "Get-GitHubRepository - Gets the authenticated user's public repositories (USER_FG_PAT)" {
85-
{ Get-GitHubRepository -Type 'public' } | Should -Not -Throw
86-
}
87-
It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner (USER_FG_PAT)' {
88-
{ Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' } | Should -Not -Throw
89-
}
90-
It 'Get-GitHubRepository - Gets a specific repository (USER_FG_PAT)' {
91-
{ Get-GitHubRepository -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw
92-
}
93-
It 'Get-GitHubRepository - Gets all repositories from a organization (USER_FG_PAT)' {
94-
{ Get-GitHubRepository -Owner 'PSModule' } | Should -Not -Throw
95-
}
96-
It 'Get-GitHubRepository - Gets all repositories from a user (USER_FG_PAT)' {
97-
{ Get-GitHubRepository -Username 'MariusStorhaug' } | Should -Not -Throw
98-
}
99-
}
10080
Context 'GitIgnore' {
10181
It 'Get-GitHubGitignore - Gets a list of all gitignore templates names (USER_FG_PAT)' {
10282
{ Get-GitHubGitignore } | Should -Not -Throw
@@ -184,26 +164,6 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_
184164
{ Get-GitHubLicense -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw
185165
}
186166
}
187-
Context 'Repository' {
188-
It "Get-GitHubRepository - Gets the authenticated user's repositories (ORG_FG_PAT)" {
189-
{ Get-GitHubRepository } | Should -Not -Throw
190-
}
191-
It "Get-GitHubRepository - Gets the authenticated user's public repositories (ORG_FG_PAT)" {
192-
{ Get-GitHubRepository -Type 'public' } | Should -Not -Throw
193-
}
194-
It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner (ORG_FG_PAT)' {
195-
{ Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' } | Should -Not -Throw
196-
}
197-
It 'Get-GitHubRepository - Gets a specific repository (ORG_FG_PAT)' {
198-
{ Get-GitHubRepository -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw
199-
}
200-
It 'Get-GitHubRepository - Gets all repositories from a organization (ORG_FG_PAT)' {
201-
{ Get-GitHubRepository -Owner 'PSModule' } | Should -Not -Throw
202-
}
203-
It 'Get-GitHubRepository - Gets all repositories from a user (ORG_FG_PAT)' {
204-
{ Get-GitHubRepository -Username 'MariusStorhaug' } | Should -Not -Throw
205-
}
206-
}
207167
Context 'GitIgnore' {
208168
It 'Get-GitHubGitignore - Gets a list of all gitignore templates names (ORG_FG_PAT)' {
209169
{ Get-GitHubGitignore } | Should -Not -Throw

‎tests/Repositories.Tests.ps1

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' }
2+
3+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
4+
'PSUseDeclaredVarsMoreThanAssignments', '',
5+
Justification = 'Pester grouping syntax: known issue.'
6+
)]
7+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
8+
'PSAvoidUsingConvertToSecureStringWithPlainText', '',
9+
Justification = 'Used to create a secure string for testing.'
10+
)]
11+
[CmdletBinding()]
12+
param()
13+
14+
Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' {
15+
BeforeAll {
16+
Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT
17+
}
18+
AfterAll {
19+
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount
20+
}
21+
Context 'Repository' {
22+
It "Get-GitHubRepository - Gets the authenticated user's repositories (USER_FG_PAT)" {
23+
{ Get-GitHubRepository } | Should -Not -Throw
24+
}
25+
It "Get-GitHubRepository - Gets the authenticated user's public repositories (USER_FG_PAT)" {
26+
{ Get-GitHubRepository -Type 'public' } | Should -Not -Throw
27+
}
28+
It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner (USER_FG_PAT)' {
29+
{ Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' } | Should -Not -Throw
30+
}
31+
It 'Get-GitHubRepository - Gets a specific repository (USER_FG_PAT)' {
32+
{ Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' } | Should -Not -Throw
33+
}
34+
It 'Get-GitHubRepository - Gets all repositories from a organization (USER_FG_PAT)' {
35+
{ Get-GitHubRepository -Owner 'PSModule' } | Should -Not -Throw
36+
}
37+
It 'Get-GitHubRepository - Gets all repositories from a user (USER_FG_PAT)' {
38+
{ Get-GitHubRepository -Username 'MariusStorhaug' } | Should -Not -Throw
39+
}
40+
}
41+
}
42+
43+
Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' {
44+
BeforeAll {
45+
Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT
46+
}
47+
AfterAll {
48+
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount
49+
}
50+
Context 'Repository' {
51+
It "Get-GitHubRepository - Gets the authenticated user's repositories (ORG_FG_PAT)" {
52+
{ Get-GitHubRepository } | Should -Not -Throw
53+
}
54+
It "Get-GitHubRepository - Gets the authenticated user's public repositories (ORG_FG_PAT)" {
55+
{ Get-GitHubRepository -Type 'public' } | Should -Not -Throw
56+
}
57+
It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner (ORG_FG_PAT)' {
58+
{ Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' } | Should -Not -Throw
59+
}
60+
It 'Get-GitHubRepository - Gets a specific repository (ORG_FG_PAT)' {
61+
{ Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' } | Should -Not -Throw
62+
}
63+
It 'Get-GitHubRepository - Gets all repositories from a organization (ORG_FG_PAT)' {
64+
{ Get-GitHubRepository -Owner 'PSModule' } | Should -Not -Throw
65+
}
66+
It 'Get-GitHubRepository - Gets all repositories from a user (ORG_FG_PAT)' {
67+
{ Get-GitHubRepository -Username 'MariusStorhaug' } | Should -Not -Throw
68+
}
69+
}
70+
}
71+
72+
Describe 'As a user - Classic PAT token (PAT)' {
73+
BeforeAll {
74+
Connect-GitHubAccount -Token $env:TEST_USER_PAT
75+
}
76+
AfterAll {
77+
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount
78+
}
79+
}
80+
81+
Describe 'As GitHub Actions (GHA)' {
82+
BeforeAll {
83+
Connect-GitHubAccount
84+
}
85+
AfterAll {
86+
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount
87+
}
88+
}
89+
90+
Describe 'As a GitHub App - Enterprise (APP_ENT)' {
91+
BeforeAll {
92+
Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY
93+
}
94+
AfterAll {
95+
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount
96+
}
97+
}
98+
99+
Describe 'As a GitHub App - Organization (APP_ORG)' {
100+
BeforeAll {
101+
Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY
102+
}
103+
AfterAll {
104+
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount
105+
}
106+
}

0 commit comments

Comments
 (0)