Skip to content

Commit e61cccb

Browse files
🧪[Tests]: Refactor and enable source code tests (#234)
## Description - Refactor and enable source code tests ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [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 ff9ac50 commit e61cccb

File tree

117 files changed

+792
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+792
-228
lines changed

.github/workflows/Nightly-Run.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ permissions:
1010
pull-requests: write
1111
statuses: write
1212

13-
env:
14-
TEST_APP_CLIENT_ID: ${{ secrets.TEST_APP_CLIENT_ID }}
15-
TEST_APP_PRIVATE_KEY: ${{ secrets.TEST_APP_PRIVATE_KEY }}
16-
TEST_FG_PAT: ${{ secrets.TEST_FG_PAT }}
17-
TEST_PAT: ${{ secrets.TEST_PAT }}
18-
1913
jobs:
2014
Process-PSModule:
2115
uses: PSModule/Process-PSModule/.github/workflows/CI.yml@v3
22-
secrets: inherit
16+
secrets:
17+
APIKey: ${{ secrets.APIKey }}
18+
TEST_APP_ENT_CLIENT_ID: ${{ secrets.TEST_APP_ENT_CLIENT_ID }}
19+
TEST_APP_ENT_PRIVATE_KEY: ${{ secrets.TEST_APP_ENT_PRIVATE_KEY }}
20+
TEST_APP_ORG_CLIENT_ID: ${{ secrets.TEST_APP_ORG_CLIENT_ID }}
21+
TEST_APP_ORG_PRIVATE_KEY: ${{ secrets.TEST_APP_ORG_PRIVATE_KEY }}
22+
TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }}
23+
TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }}
24+
TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }}

.github/workflows/Process-PSModule.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ permissions:
2424
pages: write
2525
id-token: write
2626

27-
env:
28-
TEST_APP_CLIENT_ID: ${{ secrets.TEST_APP_CLIENT_ID }}
29-
TEST_APP_PRIVATE_KEY: ${{ secrets.TEST_APP_PRIVATE_KEY }}
30-
TEST_FG_PAT: ${{ secrets.TEST_FG_PAT }}
31-
TEST_PAT: ${{ secrets.TEST_PAT }}
32-
3327
jobs:
3428
Process-PSModule:
3529
uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@v3
36-
secrets: inherit
30+
secrets:
31+
APIKey: ${{ secrets.APIKey }}
32+
TEST_APP_ENT_CLIENT_ID: ${{ secrets.TEST_APP_ENT_CLIENT_ID }}
33+
TEST_APP_ENT_PRIVATE_KEY: ${{ secrets.TEST_APP_ENT_PRIVATE_KEY }}
34+
TEST_APP_ORG_CLIENT_ID: ${{ secrets.TEST_APP_ORG_CLIENT_ID }}
35+
TEST_APP_ORG_PRIVATE_KEY: ${{ secrets.TEST_APP_ORG_PRIVATE_KEY }}
36+
TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }}
37+
TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }}
38+
TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }}
3739
with:
38-
SkipTests: SourceCode
3940
Debug: true
4041
Verbose: true

src/functions/public/Auth/Update-GitHubUserAccessToken.ps1 renamed to src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' }
2-
3-
function Update-GitHubUserAccessToken {
1+
function Update-GitHubUserAccessToken {
42
<#
53
.SYNOPSIS
64
Updates the GitHub access token.
@@ -21,12 +19,11 @@ function Update-GitHubUserAccessToken {
2119
.NOTES
2220
[Refreshing user access tokens](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/refreshing-user-access-tokens)
2321
#>
22+
[CmdletBinding(SupportsShouldProcess)]
2423
[OutputType([securestring])]
25-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links for documentation.')]
2624
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')]
27-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '',
28-
Justification = 'The tokens are recieved as clear text. Mitigating exposure by removing variables and performing garbage collection.')]
29-
[CmdletBinding(SupportsShouldProcess)]
25+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'The tokens are recieved as clear text. Mitigating exposure by removing variables and performing garbage collection.')]
26+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Reason for suppressing')]
3027
param(
3128
# The context to run the command in. Used to get the details for the API call.
3229
# Can be either a string or a GitHubContext object.

src/functions/private/License/Get-GitHubLicenseList.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
[OutputType([string[]])]
2121
[CmdletBinding()]
2222
param(
23-
# The context to run the command in.
23+
# The context to run the command in. Used to get the details for the API call.
24+
# Can be either a string or a GitHubContext object.
2425
[Parameter()]
25-
[string] $Context
26+
[object] $Context = (Get-GitHubContext)
2627
)
2728

2829
begin {

src/functions/private/License/Get-GitHubRepositoryLicense.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Get the license for the Hello-World repository from the octocat account.
1616
1717
.NOTES
18-
https://docs.github.com/rest/licenses/licenses#get-the-license-for-a-repository
18+
[Get the license for a repository](https://docs.github.com/rest/licenses/licenses#get-the-license-for-a-repository)
1919
2020
#>
2121
[CmdletBinding()]
@@ -28,6 +28,11 @@
2828
[Parameter()]
2929
[string] $Repo,
3030

31+
# The type of data to return. Can be either 'raw' or 'html'.
32+
[Parameter()]
33+
[ValidateSet('raw', 'html')]
34+
[string] $Type = 'raw',
35+
3136
# The context to run the command in. Used to get the details for the API call.
3237
# Can be either a string or a GitHubContext object.
3338
[Parameter()]
@@ -49,14 +54,19 @@
4954
$Repo = $Context.Repo
5055
}
5156
Write-Debug "Repo: [$Repo]"
57+
58+
$contentType = switch ($Type) {
59+
'raw' { 'application/vnd.github.raw+json' }
60+
'html' { 'application/vnd.github.html+json' }
61+
}
5262
}
5363

5464
process {
5565
try {
5666
$inputObject = @{
5767
Context = $Context
5868
APIEndpoint = "/repos/$Owner/$Repo/license"
59-
Accept = 'application/vnd.github+json'
69+
ContentType = $contentType
6070
Method = 'GET'
6171
}
6272

src/functions/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,26 @@
123123
process {
124124
try {
125125
$body = @{
126-
type = $Type
127126
sort = $Sort
128127
direction = $Direction
129128
per_page = $PerPage
130129
}
131-
132-
if ($PSBoundParameters.ContainsKey('Affiliation')) {
133-
$body['affiliation'] = $Affiliation -join ','
134-
}
135130
if ($PSBoundParameters.ContainsKey('Since')) {
136131
$body['since'] = $Since.ToString('yyyy-MM-ddTHH:mm:ssZ')
137132
}
138133
if ($PSBoundParameters.ContainsKey('Before')) {
139134
$body['before'] = $Before.ToString('yyyy-MM-ddTHH:mm:ssZ')
140135
}
136+
Write-Debug "ParamSet: [$($PSCmdlet.ParameterSetName)]"
137+
switch ($PSCmdlet.ParameterSetName) {
138+
'Aff-Vis' {
139+
$body['affiliation'] = $Affiliation -join ','
140+
$body['visibility'] = $Visibility
141+
}
142+
'Type' {
143+
$body['type'] = $Type
144+
}
145+
}
141146

142147
$inputObject = @{
143148
Context = $Context

src/functions/private/Teams/Get-GitHubRESTTeamByName.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function Get-GitHubTeamByName {
1+
function Get-GitHubRESTTeamByName {
22
<#
33
.SYNOPSIS
44
Get a team by name
@@ -8,7 +8,7 @@
88
and replaces spaces with a - separator. For example, "My TEam Näme" would become my-team-name.
99
1010
.EXAMPLE
11-
Get-GitHubTeamByName -Organization 'github' -Name 'my-team-name'
11+
Get-GitHubRESTTeamByName -Organization 'github' -Name 'my-team-name'
1212
#>
1313
[OutputType([void])]
1414
[CmdletBinding()]

src/functions/private/Teams/Get-GitHubRESTTeamListByOrg.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function Get-GitHubTeamListByOrg {
1+
function Get-GitHubRESTTeamListByOrg {
22
<#
33
.SYNOPSIS
44
List teams
@@ -7,7 +7,7 @@
77
Lists all teams in an organization that are visible to the authenticated user.
88
99
.EXAMPLE
10-
Get-GitHubTeamListByOrg -Organization 'github'
10+
Get-GitHubRESTTeamListByOrg -Organization 'github'
1111
1212
.NOTES
1313
[List teams](https://docs.github.com/rest/teams/teams#list-teams)

src/functions/private/Utilities/PowerShell/Get-PSCallStackPath.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
Get-PSCallStackPath
1414
First-Function\Second-Function\Third-Function
1515
16-
Shows the call stack of the last function called, Third-Function, with the first (<ScriptBlock>) and last (Get-PSCallStackPath) functions removed.
16+
Shows the call stack of the last function called, Third-Function, with the first (<ScriptBlock>)
17+
and last (Get-PSCallStackPath) functions removed.
1718
1819
.EXAMPLE
1920
Get-PSCallStackPath -SkipFirst 0

src/functions/public/API/Invoke-GitHubAPI.ps1

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@
9595

9696
process {
9797
$Token = $Context.Token
98-
Write-Debug "Token : [$Token]"
98+
Write-Debug "Token : [$Token]"
9999

100100
if ([string]::IsNullOrEmpty($TokenType)) {
101101
$TokenType = $Context.TokenType
102102
}
103-
Write-Debug "TokenType : [$($Context.TokenType)]"
103+
Write-Debug "TokenType : [$($Context.TokenType)]"
104104

105105
if ([string]::IsNullOrEmpty($ApiBaseUri)) {
106106
$ApiBaseUri = $Context.ApiBaseUri
@@ -194,6 +194,9 @@
194194
'text/plain' {
195195
$results = $response.Content
196196
}
197+
'text/html' {
198+
$results = $response.Content
199+
}
197200
'application/octocat-stream' {
198201
[byte[]]$byteArray = $response.Content
199202
$results = [System.Text.Encoding]::UTF8.GetString($byteArray)
@@ -227,6 +230,9 @@
227230
$headers = [pscustomobject]$headers
228231
$sortedProperties = $headers.PSObject.Properties.Name | Sort-Object
229232
$headers = $headers | Select-Object $sortedProperties
233+
Write-Debug 'Response headers:'
234+
$headers | Out-String -Stream | ForEach-Object { Write-Debug $_ }
235+
Write-Debug '---------------------------'
230236

231237
$errordetails = $failure.ErrorDetails | ConvertFrom-Json -AsHashtable
232238
$errorResult = [ordered]@{
@@ -239,13 +245,13 @@
239245
$APICall.Headers = $APICall.Headers | ConvertTo-Json
240246
$APICall.Method = $APICall.Method.ToString()
241247

242-
Write-Error '----------------------------------'
243-
Write-Error 'Error details:'
244-
$errorResult | Format-Table -AutoSize -HideTableHeaders | Out-String -Stream | ForEach-Object { Write-Error $_ }
245-
Write-Error '----------------------------------'
246-
Write-Debug 'Response headers:'
247-
$headers | Out-String -Stream | ForEach-Object { Write-Debug $_ }
248-
Write-Debug '---------------------------'
248+
$errorResult = @"
249+
----------------------------------
250+
Error details:
251+
$($errorResult | Format-Table -AutoSize -HideTableHeaders | Out-String)
252+
----------------------------------
253+
"@
254+
Write-Error $errorResult
249255
throw $failure.Exception.Message
250256
}
251257
}

0 commit comments

Comments
 (0)