From 032196924a432fe00572ad0a6dffa2d2fb1b3764 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Feb 2025 15:42:14 +0100 Subject: [PATCH 01/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20functi?= =?UTF-8?q?on=20definitions=20and=20remove=20unnecessary=20lines=20in=20Gi?= =?UTF-8?q?tHub=20scripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/public/Context/GitHubContext.ps1 | 2 +- .../private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 | 4 +++- src/functions/private/Config/Initialize-GitHubConfig.ps1 | 4 +++- .../Organization/Blocking/Block-GitHubUserByOrganization.ps1 | 1 - .../Blocking/Test-GitHubBlockedUserByOrganization.ps1 | 1 - src/functions/private/Teams/Get-GitHubRESTTeam.ps1 | 2 +- src/functions/public/Actions/Get-GitHubEventData.ps1 | 1 - src/functions/public/Actions/Get-GitHubRunnerData.ps1 | 1 - src/functions/public/Apps/Get-GitHubAppJSONWebToken.ps1 | 2 +- src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 | 1 - .../Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 | 1 - src/functions/public/Config/Get-GitHubConfig.ps1 | 4 +--- src/functions/public/License/Get-GitHubLicense.ps1 | 4 +--- src/functions/public/Users/Get-GitHubUser.ps1 | 2 +- 14 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/classes/public/Context/GitHubContext.ps1 b/src/classes/public/Context/GitHubContext.ps1 index 232c2d21a..8d54ac1b9 100644 --- a/src/classes/public/Context/GitHubContext.ps1 +++ b/src/classes/public/Context/GitHubContext.ps1 @@ -1,4 +1,4 @@ -class GitHubContext { +class GitHubContext { # The context ID. [string] $ID diff --git a/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 b/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 index ccf985237..803d8c724 100644 --- a/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 @@ -1,4 +1,6 @@ -function Update-GitHubUserAccessToken { +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' } + +function Update-GitHubUserAccessToken { <# .SYNOPSIS Updates the GitHub access token. diff --git a/src/functions/private/Config/Initialize-GitHubConfig.ps1 b/src/functions/private/Config/Initialize-GitHubConfig.ps1 index 5e51c0636..fce061650 100644 --- a/src/functions/private/Config/Initialize-GitHubConfig.ps1 +++ b/src/functions/private/Config/Initialize-GitHubConfig.ps1 @@ -1,4 +1,6 @@ -function Initialize-GitHubConfig { +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' } + +function Initialize-GitHubConfig { <# .SYNOPSIS Initialize the GitHub module configuration. diff --git a/src/functions/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 b/src/functions/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 index 109173ff5..791b61942 100644 --- a/src/functions/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 +++ b/src/functions/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 @@ -76,4 +76,3 @@ Write-Debug "[$stackPath] - End" } } - diff --git a/src/functions/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 b/src/functions/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 index 928be8432..2ea904246 100644 --- a/src/functions/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 +++ b/src/functions/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 @@ -72,4 +72,3 @@ Write-Debug "[$stackPath] - End" } } - diff --git a/src/functions/private/Teams/Get-GitHubRESTTeam.ps1 b/src/functions/private/Teams/Get-GitHubRESTTeam.ps1 index ed1859723..dce4b2a53 100644 --- a/src/functions/private/Teams/Get-GitHubRESTTeam.ps1 +++ b/src/functions/private/Teams/Get-GitHubRESTTeam.ps1 @@ -65,7 +65,7 @@ } switch ($PSCmdlet.ParameterSetName) { 'GetByName' { - Get-GitHubTeamByName @params -Name $Name + Get-GitHubRESTTeamByName @params -Name $Name } '__AllParameterSets' { Get-GitHubTeamListByOrg @params diff --git a/src/functions/public/Actions/Get-GitHubEventData.ps1 b/src/functions/public/Actions/Get-GitHubEventData.ps1 index 3bce149bd..d057b864b 100644 --- a/src/functions/public/Actions/Get-GitHubEventData.ps1 +++ b/src/functions/public/Actions/Get-GitHubEventData.ps1 @@ -26,4 +26,3 @@ Write-Debug "[$stackPath] - End" } } - diff --git a/src/functions/public/Actions/Get-GitHubRunnerData.ps1 b/src/functions/public/Actions/Get-GitHubRunnerData.ps1 index af6cfbf9d..5a61023b5 100644 --- a/src/functions/public/Actions/Get-GitHubRunnerData.ps1 +++ b/src/functions/public/Actions/Get-GitHubRunnerData.ps1 @@ -26,4 +26,3 @@ Write-Debug "[$stackPath] - End" } } - diff --git a/src/functions/public/Apps/Get-GitHubAppJSONWebToken.ps1 b/src/functions/public/Apps/Get-GitHubAppJSONWebToken.ps1 index 60aa43ebe..b9057fee1 100644 --- a/src/functions/public/Apps/Get-GitHubAppJSONWebToken.ps1 +++ b/src/functions/public/Apps/Get-GitHubAppJSONWebToken.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubAppJSONWebToken { +function Get-GitHubAppJSONWebToken { <# .SYNOPSIS Generates a JSON Web Token (JWT) for a GitHub App. diff --git a/src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 b/src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 index f77eb9b12..0e91cdf47 100644 --- a/src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 +++ b/src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 @@ -74,4 +74,3 @@ Write-Debug "[$stackPath] - End" } } - diff --git a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 index 94c3b3f16..36a02d756 100644 --- a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 +++ b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 @@ -53,4 +53,3 @@ Write-Debug "[$stackPath] - End" } } - diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index 545c3aa94..42633f786 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,6 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' } - -function Get-GitHubConfig { +function Get-GitHubConfig { <# .SYNOPSIS Get a GitHub module configuration. diff --git a/src/functions/public/License/Get-GitHubLicense.ps1 b/src/functions/public/License/Get-GitHubLicense.ps1 index 7f5953a61..8ec620b6a 100644 --- a/src/functions/public/License/Get-GitHubLicense.ps1 +++ b/src/functions/public/License/Get-GitHubLicense.ps1 @@ -1,6 +1,4 @@ -#Requires -Modules @{ ModuleName = 'DynamicParams'; RequiredVersion = '1.1.8' } - -filter Get-GitHubLicense { +filter Get-GitHubLicense { <# .SYNOPSIS Get a license template, list of all popular license templates or a license for a repository diff --git a/src/functions/public/Users/Get-GitHubUser.ps1 b/src/functions/public/Users/Get-GitHubUser.ps1 index 6ce36be14..0744f87e4 100644 --- a/src/functions/public/Users/Get-GitHubUser.ps1 +++ b/src/functions/public/Users/Get-GitHubUser.ps1 @@ -87,7 +87,7 @@ $user } 'AllUsers' { - Get-GitHubAllUsers -Since $Since -PerPage $PerPage -Context $Context + Get-GitHubAllUser -Since $Since -PerPage $PerPage -Context $Context } } } catch { From 8cb0d3485cb87c4e738db9ab105ff8e767f918b9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Feb 2025 15:43:19 +0100 Subject: [PATCH 02/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Rename=20`Conve?= =?UTF-8?q?rt-StringCasingStyle`=20to=20`ConvertTo-CasingStyle`=20for=20co?= =?UTF-8?q?nsistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/private/Actions/Import-GitHubEventData.ps1 | 2 +- .../private/Utilities/Hashtable/ConvertTo-HashTable.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions/private/Actions/Import-GitHubEventData.ps1 b/src/functions/private/Actions/Import-GitHubEventData.ps1 index 48c8a9170..811527249 100644 --- a/src/functions/private/Actions/Import-GitHubEventData.ps1 +++ b/src/functions/private/Actions/Import-GitHubEventData.ps1 @@ -39,7 +39,7 @@ $hashtable = @{} $gitHubEvent.PSObject.Properties | ForEach-Object { $name = $_.Name - $name = $name | Convert-StringCasingStyle -To PascalCase + $name = $name | ConvertTo-CasingStyle -To PascalCase $hashtable[$name] = $_.Value } $gitHubEvent = [pscustomobject]$hashtable diff --git a/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 b/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 index edcfa481b..0127462e0 100644 --- a/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 +++ b/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 @@ -67,7 +67,7 @@ process { try { foreach ($item in $InputObject.PSObject.Properties) { - $name = if ($NameCasingStyle) { ($item.Name | Convert-StringCasingStyle -To $NameCasingStyle) } else { $item.Name } + $name = if ($NameCasingStyle) { ($item.Name | ConvertTo-CasingStyle -To $NameCasingStyle) } else { $item.Name } $hashtable[$name] = $item.Value } $hashtable From 0196cddd6571340bad8d03e1c23663216155f0d2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Feb 2025 15:45:17 +0100 Subject: [PATCH 03/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20deprec?= =?UTF-8?q?ated=20casing=20utility=20functions=20for=20code=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Casing/Convert-StringCasingStyle.ps1 | 71 ------------ .../Casing/Get-StringCasingStyle.ps1 | 98 ----------------- .../Casing/Split-StringByCasingStyle.ps1 | 101 ------------------ 3 files changed, 270 deletions(-) delete mode 100644 src/functions/private/Utilities/Casing/Convert-StringCasingStyle.ps1 delete mode 100644 src/functions/private/Utilities/Casing/Get-StringCasingStyle.ps1 delete mode 100644 src/functions/private/Utilities/Casing/Split-StringByCasingStyle.ps1 diff --git a/src/functions/private/Utilities/Casing/Convert-StringCasingStyle.ps1 b/src/functions/private/Utilities/Casing/Convert-StringCasingStyle.ps1 deleted file mode 100644 index ea3d2058e..000000000 --- a/src/functions/private/Utilities/Casing/Convert-StringCasingStyle.ps1 +++ /dev/null @@ -1,71 +0,0 @@ -filter Convert-StringCasingStyle { - <# - .SYNOPSIS - Convert a string to a different casing style - - .DESCRIPTION - This function converts a string to a different casing style. - - .EXAMPLE - 'thisIsCamelCase' | Convert-StringCasingStyle -To 'snake_case' - - Convert the string 'thisIsCamelCase' to 'this_is_camel_case' - - .EXAMPLE - 'thisIsCamelCase' | Convert-StringCasingStyle -To 'UPPER_SNAKE_CASE' - - Convert the string 'thisIsCamelCase' to 'THIS_IS_CAMEL_CASE' - - .EXAMPLE - 'thisIsCamelCase' | Convert-StringCasingStyle -To 'kebab-case' - - .NOTES - General notes - #> - [OutputType([string])] - [CmdletBinding()] - param( - # The string to convert - [Parameter( - Mandatory, - ValueFromPipeline - )] - [string] $Text, - - # The casing style to convert the string to - [Parameter(Mandatory)] - [ValidateSet( - 'lowercase', - 'UPPERCASE', - 'Title Case', - 'Sentencecase', - 'PascalCase', - 'camelCase', - 'kebab-case', - 'UPPER-KEBAB-CASE', - 'snake_case', - 'UPPER_SNAKE_CASE' - )] - [string] $To - ) - - $currentStyle = Get-StringCasingStyle -Text $Text - - $words = Split-StringByCasingStyle -Text $Text -By $currentStyle - - # Convert the words into the target style - switch ($To) { - 'lowercase' { ($words -join '').toLower() } - 'UPPERCASE' { ($words -join '').toUpper() } - 'Title Case' { ($words | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() }) -join ' ' } - 'Sentencecase' { $words -join '' | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() } } - 'kebab-case' { ($words -join '-').ToLower() } - 'snake_case' { ($words -join '_').ToLower() } - 'PascalCase' { ($words | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() }) -join '' } - 'camelCase' { - $words[0].toLower() + (($words | Select-Object -Skip 1 | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1) }) -join '') - } - 'UPPER_SNAKE_CASE' { ($words -join '_').toUpper() } - 'UPPER-KEBAB-CASE' { ($words -join '-').toUpper() } - } -} diff --git a/src/functions/private/Utilities/Casing/Get-StringCasingStyle.ps1 b/src/functions/private/Utilities/Casing/Get-StringCasingStyle.ps1 deleted file mode 100644 index 0640ade46..000000000 --- a/src/functions/private/Utilities/Casing/Get-StringCasingStyle.ps1 +++ /dev/null @@ -1,98 +0,0 @@ -filter Get-StringCasingStyle { - <# - .SYNOPSIS - Detects the casing style of a string - - .DESCRIPTION - This function detects the casing style of a string. - - .EXAMPLE - 'testtesttest' | Get-StringCasingStyle - - lowercase - - .EXAMPLE - 'TESTTESTTEST' | Get-StringCasingStyle - - UPPERCASE - - .EXAMPLE - 'Testtesttest' | Get-StringCasingStyle - - Sentencecase - - .EXAMPLE - 'TestTestTest' | Get-StringCasingStyle - - PascalCase - - .EXAMPLE - 'testTestTest' | Get-StringCasingStyle - - camelCase - - .EXAMPLE - 'test-test-test' | Get-StringCasingStyle - - kebab-case - - .EXAMPLE - 'TEST-TEST-TEST' | Get-StringCasingStyle - - UPPER-KEBAB-CASE - - .EXAMPLE - 'test_test_test' | Get-StringCasingStyle - - snake_case - - .EXAMPLE - 'TEST_TEST_TEST' | Get-StringCasingStyle - - UPPER_SNAKE_CASE - - .EXAMPLE - 'Test_teSt-Test' | Get-StringCasingStyle - - Unknown - #> - [OutputType([string])] - [CmdletBinding()] - param( - # The string to check the casing style of - [Parameter( - Mandatory, - ValueFromPipeline - )] - [ValidateNotNullOrEmpty()] - [string] $Text - ) - - $style = if ([regex]::Match($Text, '^[a-z][a-z0-9]*$').Success) { - 'lowercase' - } elseif ([regex]::Match($Text, '^[A-Z][A-Z0-9]*$').Success) { - 'UPPERCASE' - } elseif ([regex]::Match($Text, '^[A-Z][a-z0-9]*$').Success) { - 'Sentencecase' - } elseif ([regex]::Match($Text, '^([A-Z][a-z]*)(\s+[A-Z][a-z]*)+$').Success) { - 'Title Case' - } elseif ([regex]::Match($Text, '^[A-Z][a-z0-9]*([A-Z][a-z0-9]*)+$').Success) { - 'PascalCase' - } elseif ([regex]::Match($Text, '^[a-z][a-z0-9]*([A-Z][a-z0-9]*)+$').Success) { - 'camelCase' - } elseif ([regex]::Match($Text, '^[a-z][a-z0-9]*(-[a-z0-9]+)+$').Success) { - 'kebab-case' - } elseif ([regex]::Match($Text, '^[A-Z][A-Z0-9]*(-[A-Z0-9]+)+$').Success) { - 'UPPER-KEBAB-CASE' - } elseif ([regex]::Match($Text, '^[a-z][a-z0-9]*(_[a-z0-9]+)+$').Success) { - 'snake_case' - } elseif ([regex]::Match($Text, '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)+$').Success) { - 'UPPER_SNAKE_CASE' - } else { - 'Unknown' - } - - Write-Debug "Detected casing style: [$style]" - $style - -} diff --git a/src/functions/private/Utilities/Casing/Split-StringByCasingStyle.ps1 b/src/functions/private/Utilities/Casing/Split-StringByCasingStyle.ps1 deleted file mode 100644 index bf2436ee4..000000000 --- a/src/functions/private/Utilities/Casing/Split-StringByCasingStyle.ps1 +++ /dev/null @@ -1,101 +0,0 @@ -filter Split-StringByCasingStyle { - <# - .SYNOPSIS - Splits a kebab-case string into an array of words - - .DESCRIPTION - This function splits a kebab-case string into an array of words. - - .EXAMPLE - Split-StringByCasingStyle -Text 'this-is-a-kebab-case-string' -By kebab-case - - this - is - a - kebab - case - string - - .EXAMPLE - Split-StringByCasingStyle -Text 'this_is_a_kebab_case_string' -By 'snake_case' - - this - is - a - kebab - case - string - - .EXAMPLE - Split-StringByCasingStyle -Text 'ThisIsAPascalCaseString' -By 'PascalCase' - - This - Is - A - Pascal - Case - String - - .EXAMPLE - Split-StringByCasingStyle -Text 'thisIsACamelCaseString' -By 'camelCase' - - this - Is - A - Camel - Case - String - - .EXAMPLE - Split-StringByCasingStyle -Text 'this_is_a-CamelCaseString' -By kebab-case | Split-StringByCasingStyle -By snake_case - - this_is_a - camelcasestring - - - #> - [OutputType([string[]])] - [CmdletBinding()] - param( - # The string to split - [Parameter( - Mandatory, - ValueFromPipeline - )] - [string] $Text, - - # The casing style to split the string by - [Parameter()] - [ValidateSet( - 'lowercase', - 'UPPERCASE', - 'Sentencecase', - 'Title Case', - 'PascalCase', - 'camelCase', - 'kebab-case', - 'UPPER-KEBAB-CASE', - 'snake_case', - 'UPPER_SNAKE_CASE' - )] - [string] $By - ) - - $styles = $PSBoundParameters | Where-Object { $_.Value -eq $true } | Select-Object -ExpandProperty Name - - Write-Debug "Splitting string [$Text] by casing style [$($styles -join ', ' )]" - $splitText = switch ($By) { - 'PascalCase' { [regex]::Matches($Text, '([A-Z][a-z]*)').Value; break } - 'camelCase' { [regex]::Matches($Text, '([A-Z][a-z]*)|^[a-z]+').Value; break } - 'kebab-case' { $Text -split '-'; break } - 'UPPER-KEBAB-CASE' { $Text -split '-'; break } - 'snake_case' { $Text -split '_'; break } - 'UPPER_SNAKE_CASE' { $Text -split '_'; break } - default { - $Text -split ' ' - } - } - - Write-Debug "Result: [$($splitText -join ', ')]" - $splitText -} From c5221e4ec15158d9022b3e524569b78c6b9f9091 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Feb 2025 16:21:46 +0100 Subject: [PATCH 04/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20module=20?= =?UTF-8?q?requirements=20for=20`CasingStyle`=20in=20`Import-GitHubEventDa?= =?UTF-8?q?ta`=20and=20`ConvertTo-HashTable`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/private/Actions/Import-GitHubEventData.ps1 | 4 +++- .../private/Utilities/Hashtable/ConvertTo-HashTable.ps1 | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/functions/private/Actions/Import-GitHubEventData.ps1 b/src/functions/private/Actions/Import-GitHubEventData.ps1 index 811527249..def1ed332 100644 --- a/src/functions/private/Actions/Import-GitHubEventData.ps1 +++ b/src/functions/private/Actions/Import-GitHubEventData.ps1 @@ -1,4 +1,6 @@ -function Import-GitHubEventData { +#Requires -Modules @{ ModuleName = 'CasingStyle'; RequiredVersion = '1.0.2' } + +function Import-GitHubEventData { <# .SYNOPSIS Import data from the event that triggered the workflow. diff --git a/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 b/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 index 0127462e0..d80c6cdf2 100644 --- a/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 +++ b/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 @@ -1,4 +1,6 @@ -filter ConvertTo-HashTable { +#Requires -Modules @{ ModuleName = 'CasingStyle'; RequiredVersion = '1.0.2' } + +filter ConvertTo-HashTable { <# .SYNOPSIS Converts an object to a hashtable @@ -67,7 +69,7 @@ process { try { foreach ($item in $InputObject.PSObject.Properties) { - $name = if ($NameCasingStyle) { ($item.Name | ConvertTo-CasingStyle -To $NameCasingStyle) } else { $item.Name } + $name = if ($NameCasingStyle) { ($item.Name | ConvertTo-CasingStyle -To $NameCasingStyle) } else { $item.Name } #FIXME: Add '#Requires -Modules' for [ConvertTo-CasingStyle] Suggestions: CasingStyle, Casing $hashtable[$name] = $item.Value } $hashtable From bcffebf0315809e136329a87dfa1ab82a0604fd0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Feb 2025 16:37:36 +0100 Subject: [PATCH 05/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20`Upd?= =?UTF-8?q?ate-GitHubUserAccessToken`=20function=20by=20removing=20unneces?= =?UTF-8?q?sary=20module=20requirement=20and=20reordering=20attributes=20f?= =?UTF-8?q?or=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 b/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 index 803d8c724..107c112c4 100644 --- a/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 @@ -1,6 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' } - -function Update-GitHubUserAccessToken { +function Update-GitHubUserAccessToken { <# .SYNOPSIS Updates the GitHub access token. @@ -21,11 +19,11 @@ function Update-GitHubUserAccessToken { .NOTES [Refreshing user access tokens](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/refreshing-user-access-tokens) #> - [CmdletBinding(SupportsShouldProcess)] - [OutputType([securestring])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'The tokens are recieved as clear text. Mitigating exposure by removing variables and performing garbage collection.')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Reason for suppressing')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Reason for suppressing')] + [CmdletBinding(SupportsShouldProcess)] + [OutputType([securestring])] param( # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. From 3f4f37d59203522674a017f49ea0daa6c8f6c5be Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Feb 2025 16:38:27 +0100 Subject: [PATCH 06/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20unnece?= =?UTF-8?q?ssary=20module=20requirement=20from=20`ConvertTo-HashTable`=20f?= =?UTF-8?q?unction=20for=20code=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../private/Utilities/Hashtable/ConvertTo-HashTable.ps1 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 b/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 index d80c6cdf2..0127462e0 100644 --- a/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 +++ b/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 @@ -1,6 +1,4 @@ -#Requires -Modules @{ ModuleName = 'CasingStyle'; RequiredVersion = '1.0.2' } - -filter ConvertTo-HashTable { +filter ConvertTo-HashTable { <# .SYNOPSIS Converts an object to a hashtable @@ -69,7 +67,7 @@ filter ConvertTo-HashTable { process { try { foreach ($item in $InputObject.PSObject.Properties) { - $name = if ($NameCasingStyle) { ($item.Name | ConvertTo-CasingStyle -To $NameCasingStyle) } else { $item.Name } #FIXME: Add '#Requires -Modules' for [ConvertTo-CasingStyle] Suggestions: CasingStyle, Casing + $name = if ($NameCasingStyle) { ($item.Name | ConvertTo-CasingStyle -To $NameCasingStyle) } else { $item.Name } $hashtable[$name] = $item.Value } $hashtable From 288e006412d88ef43f33d4c8272f0b9e01a7752a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Feb 2025 17:00:25 +0100 Subject: [PATCH 07/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20`Updat?= =?UTF-8?q?e-GitHubUserAccessToken`=20function=20to=20support=20ShouldProc?= =?UTF-8?q?ess=20and=20add=20CasingStyle=20module=20definition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Process-PSModule.yml | 2 + .../Update-GitHubUserAccessToken.ps1 | 4 +- .../CasingStyle/1.0.2/CasingStyle.psd1 | 40 ++ .../CasingStyle/1.0.2/CasingStyle.psm1 | 384 ++++++++++++++++++ 4 files changed, 428 insertions(+), 2 deletions(-) create mode 100644 src/modules/CasingStyle/1.0.2/CasingStyle.psd1 create mode 100644 src/modules/CasingStyle/1.0.2/CasingStyle.psm1 diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index 5252ed337..bc8b830f0 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -36,3 +36,5 @@ jobs: TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }} TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }} TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }} + with: + SkipTests: All diff --git a/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 b/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 index 107c112c4..2ff339983 100644 --- a/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 @@ -19,11 +19,11 @@ .NOTES [Refreshing user access tokens](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/refreshing-user-access-tokens) #> + [CmdletBinding(SupportsShouldProcess)] + [OutputType([securestring])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'The tokens are recieved as clear text. Mitigating exposure by removing variables and performing garbage collection.')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Reason for suppressing')] - [CmdletBinding(SupportsShouldProcess)] - [OutputType([securestring])] param( # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. diff --git a/src/modules/CasingStyle/1.0.2/CasingStyle.psd1 b/src/modules/CasingStyle/1.0.2/CasingStyle.psd1 new file mode 100644 index 000000000..4529d94f2 --- /dev/null +++ b/src/modules/CasingStyle/1.0.2/CasingStyle.psd1 @@ -0,0 +1,40 @@ +@{ + RootModule = 'CasingStyle.psm1' + ModuleVersion = '1.0.2' + CompatiblePSEditions = @( + 'Core' + 'Desktop' + ) + GUID = 'a886b80a-1367-46e9-b788-0a74cd786dcd' + Author = 'PSModule' + CompanyName = 'PSModule' + Copyright = '(c) 2025 PSModule. All rights reserved.' + Description = 'A PowerShell module that works with casing of text.' + PowerShellVersion = '7.4' + ProcessorArchitecture = 'None' + TypesToProcess = @() + FormatsToProcess = @() + FunctionsToExport = @( + 'ConvertTo-CasingStyle' + 'Get-CasingStyle' + 'Split-CasingStyle' + ) + CmdletsToExport = @() + ModuleList = @() + FileList = 'CasingStyle.psm1' + PrivateData = @{ + PSData = @{ + Tags = @( + 'Linux' + 'MacOS' + 'PSEdition_Core' + 'PSEdition_Desktop' + 'Windows' + ) + LicenseUri = 'https://github.com/PSModule/CasingStyle/blob/main/LICENSE' + ProjectUri = 'https://github.com/PSModule/CasingStyle' + IconUri = 'https://raw.githubusercontent.com/PSModule/CasingStyle/main/icon/icon.png' + } + } +} + diff --git a/src/modules/CasingStyle/1.0.2/CasingStyle.psm1 b/src/modules/CasingStyle/1.0.2/CasingStyle.psm1 new file mode 100644 index 000000000..8859395a5 --- /dev/null +++ b/src/modules/CasingStyle/1.0.2/CasingStyle.psm1 @@ -0,0 +1,384 @@ +[CmdletBinding()] +param() +$baseName = [System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath) +$script:PSModuleInfo = Test-ModuleManifest -Path "$PSScriptRoot\$baseName.psd1" +$script:PSModuleInfo | Format-List | Out-String -Stream | ForEach-Object { Write-Debug $_ } +$scriptName = $script:PSModuleInfo.Name +Write-Debug "[$scriptName] - Importing module" +#region [functions] - [public] +Write-Debug "[$scriptName] - [functions] - [public] - Processing folder" +#region [functions] - [public] - [ConvertTo-CasingStyle] +Write-Debug "[$scriptName] - [functions] - [public] - [ConvertTo-CasingStyle] - Importing" +filter ConvertTo-CasingStyle { + <# + .SYNOPSIS + Convert a string to a different casing style + + .DESCRIPTION + This function converts a string to a different casing style. + + .EXAMPLE + 'thisIsCamelCase' | ConvertTo-CasingStyle -To 'snake_case' + + Convert the string 'thisIsCamelCase' to 'this_is_camel_case' + + .EXAMPLE + 'thisIsCamelCase' | ConvertTo-CasingStyle -To 'UPPER_SNAKE_CASE' + + Convert the string 'thisIsCamelCase' to 'THIS_IS_CAMEL_CASE' + + .EXAMPLE + 'thisIsCamelCase' | ConvertTo-CasingStyle -To 'kebab-case' + + .OUTPUTS + [string] - The converted string + + .LINK + https://psmodule.io/CasingStyle/Functions/ConvertTo-CasingStyle/ + #> + [OutputType([string])] + [CmdletBinding()] + param ( + # The string to convert + [Parameter( + Mandatory, + ValueFromPipeline + )] + [string] $Text, + + # The casing style to convert the string to + [Parameter(Mandatory)] + [ValidateSet( + 'lowercase', + 'UPPERCASE', + 'Title Case', + 'Sentencecase', + 'PascalCase', + 'camelCase', + 'kebab-case', + 'UPPER-KEBAB-CASE', + 'snake_case', + 'UPPER_SNAKE_CASE' + )] + [string] $To + ) + + $currentStyle = Get-CasingStyle -Text $Text + + $words = Split-CasingStyle -Text $Text -By $currentStyle + + # Convert the words into the target style + switch ($To) { + 'lowercase' { ($words -join '').toLower() } + 'UPPERCASE' { ($words -join '').toUpper() } + 'Title Case' { ($words | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() }) -join ' ' } + 'Sentencecase' { $words -join '' | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() } } + 'kebab-case' { ($words -join '-').ToLower() } + 'snake_case' { ($words -join '_').ToLower() } + 'PascalCase' { ($words | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() }) -join '' } + 'camelCase' { + $words[0].toLower() + (($words | Select-Object -Skip 1 | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1) }) -join '') + } + 'UPPER_SNAKE_CASE' { ($words -join '_').toUpper() } + 'UPPER-KEBAB-CASE' { ($words -join '-').toUpper() } + } +} +Write-Debug "[$scriptName] - [functions] - [public] - [ConvertTo-CasingStyle] - Done" +#endregion [functions] - [public] - [ConvertTo-CasingStyle] +#region [functions] - [public] - [Get-CasingStyle] +Write-Debug "[$scriptName] - [functions] - [public] - [Get-CasingStyle] - Importing" +filter Get-CasingStyle { + <# + .SYNOPSIS + Detects the casing style of a string + + .DESCRIPTION + This function detects the casing style of a string. + + .EXAMPLE + 'testtesttest' | Get-CasingStyle + + lowercase + + .EXAMPLE + 'TESTTESTTEST' | Get-CasingStyle + + UPPERCASE + + .EXAMPLE + 'Testtesttest' | Get-CasingStyle + + Sentencecase + + .EXAMPLE + 'TestTestTest' | Get-CasingStyle + + PascalCase + + .EXAMPLE + 'testTestTest' | Get-CasingStyle + + camelCase + + .EXAMPLE + 'test-test-test' | Get-CasingStyle + + kebab-case + + .EXAMPLE + 'TEST-TEST-TEST' | Get-CasingStyle + + UPPER-KEBAB-CASE + + .EXAMPLE + 'test_test_test' | Get-CasingStyle + + snake_case + + .EXAMPLE + 'TEST_TEST_TEST' | Get-CasingStyle + + UPPER_SNAKE_CASE + + .EXAMPLE + 'Test_teSt-Test' | Get-CasingStyle + + Unknown + + .OUTPUTS + [string] - The detected casing style of the input string + + .LINK + https://psmodule.io/CasingStyle/Functions/Get-CasingStyle/ + #> + [OutputType([string])] + [CmdletBinding()] + param ( + # The string to check the casing style of + [Parameter( + Mandatory, + ValueFromPipeline + )] + [string] $Text + ) + + $style = if ([regex]::Match($Text, $script:LowerCase).Success) { + 'lowercase' + } elseif ([regex]::Match($Text, $script:UpperCase).Success) { + 'UPPERCASE' + } elseif ([regex]::Match($Text, $script:SentenceCase).Success) { + 'Sentencecase' + } elseif ([regex]::Match($Text, $script:TitleCase).Success) { + 'Title Case' + } elseif ([regex]::Match($Text, $script:PascalCase).Success) { + 'PascalCase' + } elseif ([regex]::Match($Text, $script:CamelCase).Success) { + 'camelCase' + } elseif ([regex]::Match($Text, $script:KebabCase).Success) { + 'kebab-case' + } elseif ([regex]::Match($Text, $script:UpperKebabCase).Success) { + 'UPPER-KEBAB-CASE' + } elseif ([regex]::Match($Text, $script:SnakeCase).Success) { + 'snake_case' + } elseif ([regex]::Match($Text, $script:UpperSnakeCase).Success) { + 'UPPER_SNAKE_CASE' + } else { + 'Unknown' + } + + Write-Verbose "Detected casing style: [$style]" + $style +} +Write-Debug "[$scriptName] - [functions] - [public] - [Get-CasingStyle] - Done" +#endregion [functions] - [public] - [Get-CasingStyle] +#region [functions] - [public] - [Split-CasingStyle] +Write-Debug "[$scriptName] - [functions] - [public] - [Split-CasingStyle] - Importing" +filter Split-CasingStyle { + <# + .SYNOPSIS + Splits a string based on one or more casing styles. + + .DESCRIPTION + This function takes a string and an array of casing styles (via the -By parameter) + and splits the string into its component words. It does this iteratively, + applying each split to every token produced by the previous one. + + .EXAMPLE + Split-CasingStyle -Text 'this-is-a-kebab-case-string' -By kebab-case + + this + is + a + kebab + case + string + + .EXAMPLE + Split-CasingStyle -Text 'this_is_a_kebab_case_string' -By 'snake_case' + + this + is + a + kebab + case + string + + .EXAMPLE + Split-CasingStyle -Text 'ThisIsAPascalCaseString' -By 'PascalCase' + + This + Is + A + Pascal + Case + String + + .EXAMPLE + Split-CasingStyle -Text 'thisIsACamelCaseString' -By 'camelCase' + + this + Is + A + Camel + Case + String + + .EXAMPLE + Split-CasingStyle -Text 'this_is_a-CamelCaseString' -By kebab-case | Split-CasingStyle -By snake_case + + this_is_a + camelcasestring + + .EXAMPLE + 'this_is_a-PascalString' | Split-CasingStyle -By 'snake_case','kebab-case','PascalCase' + + .OUTPUTS + [string[]] - An array of strings, each representing a word in the original string + + .LINK + https://psmodule.io/CasingStyle/Functions/Split-CasingStyle/ + #> + [CmdletBinding()] + param( + # The string to split + [Parameter( + Mandatory, + ValueFromPipeline + )] + [string]$Text, + + # The casing style(s) to split the string by. + [Parameter()] + [ValidateSet( + 'lowercase', + 'UPPERCASE', + 'Sentencecase', + 'Title Case', + 'PascalCase', + 'camelCase', + 'kebab-case', + 'UPPER-KEBAB-CASE', + 'snake_case', + 'UPPER_SNAKE_CASE' + )] + [string[]]$By + ) + + process { + Write-Verbose "Starting with string: [$Text]" + # Start with the original text as the only token. + $tokens = @($Text) + + # For each casing style in the -By list, split every token accordingly. + foreach ($style in $By) { + Write-Verbose "Splitting by casing style: $style" + $newTokens = @() + foreach ($token in $tokens) { + switch ($style) { + 'PascalCase' { + # Use regex to match sequences like 'Pascal' and 'String' in 'PascalString' + $matchedTokens = [regex]::Matches($token, '([A-Z][a-z]*)') + if ($matchedTokens.Count -gt 0) { + $newTokens += $matchedTokens | ForEach-Object { $_.Value } + } else { + $newTokens += $token + } + break + } + 'camelCase' { + # Match leading lowercase or uppercase letter groups + $matchedTokens = [regex]::Matches($token, '(^[a-z]+|[A-Z][a-z]*)') + if ($matchedTokens.Count -gt 0) { + $newTokens += $matchedTokens | ForEach-Object { $_.Value } + } else { + $newTokens += $token + } + break + } + 'kebab-case' { + $newTokens += $token -split '-' + break + } + 'UPPER-KEBAB-CASE' { + $newTokens += $token -split '-' + break + } + 'snake_case' { + $newTokens += $token -split '_' + break + } + 'UPPER_SNAKE_CASE' { + $newTokens += $token -split '_' + break + } + default { + # For any other case styles, you might split on whitespace + $newTokens += $token -split ' ' + break + } + } + } + # Update tokens with the newly split parts + $tokens = $newTokens + Write-Verbose "Tokens after splitting by $style`: [$($tokens -join ', ')]" + } + Write-Verbose "Final result: [$($tokens -join ', ')]" + $tokens + } +} +Write-Debug "[$scriptName] - [functions] - [public] - [Split-CasingStyle] - Done" +#endregion [functions] - [public] - [Split-CasingStyle] +Write-Debug "[$scriptName] - [functions] - [public] - Done" +#endregion [functions] - [public] +#region [variables] - [private] +Write-Debug "[$scriptName] - [variables] - [private] - Processing folder" +#region [variables] - [private] - [Cases] +Write-Debug "[$scriptName] - [variables] - [private] - [Cases] - Importing" +$script:LowerCase = '^[a-z][a-z0-9]*$' +$script:UpperCase = '^[A-Z][A-Z0-9]*$' +$script:SentenceCase = '^[A-Z][a-z0-9]*$' +$script:TitleCase = '^([A-Z][a-z]*)(\s+[A-Z][a-z]*)+$' +$script:PascalCase = '^[A-Z][a-z0-9]*([A-Z][a-z0-9]*)+$' +$script:CamelCase = '^[a-z][a-z0-9]*([A-Z][a-z0-9]*)+$' +$script:KebabCase = '^[a-z][a-z0-9]*(-[a-z0-9]+)+$' +$script:UpperKebabCase = '^[A-Z][A-Z0-9]*(-[A-Z0-9]+)+$' +$script:SnakeCase = '^[a-z][a-z0-9]*(_[a-z0-9]+)+$' +$script:UpperSnakeCase = '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)+$' +Write-Debug "[$scriptName] - [variables] - [private] - [Cases] - Done" +#endregion [variables] - [private] - [Cases] +Write-Debug "[$scriptName] - [variables] - [private] - Done" +#endregion [variables] - [private] + +#region Member exporter +$exports = @{ + Alias = '*' + Cmdlet = '' + Function = @( + 'ConvertTo-CasingStyle' + 'Get-CasingStyle' + 'Split-CasingStyle' + ) +} +Export-ModuleMember @exports +#endregion Member exporter + From 78b1df500bf6880d37c6530d089ec1a9873c2da9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Feb 2025 17:14:11 +0100 Subject: [PATCH 08/13] Move nested module --- src/modules/CasingStyle/{1.0.2 => }/CasingStyle.psd1 | 0 src/modules/CasingStyle/{1.0.2 => }/CasingStyle.psm1 | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/modules/CasingStyle/{1.0.2 => }/CasingStyle.psd1 (100%) rename src/modules/CasingStyle/{1.0.2 => }/CasingStyle.psm1 (100%) diff --git a/src/modules/CasingStyle/1.0.2/CasingStyle.psd1 b/src/modules/CasingStyle/CasingStyle.psd1 similarity index 100% rename from src/modules/CasingStyle/1.0.2/CasingStyle.psd1 rename to src/modules/CasingStyle/CasingStyle.psd1 diff --git a/src/modules/CasingStyle/1.0.2/CasingStyle.psm1 b/src/modules/CasingStyle/CasingStyle.psm1 similarity index 100% rename from src/modules/CasingStyle/1.0.2/CasingStyle.psm1 rename to src/modules/CasingStyle/CasingStyle.psm1 From b40ab76edb45afc2b40b3eda2d7602ea2f0b1e3e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Feb 2025 17:40:46 +0100 Subject: [PATCH 09/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20module=20?= =?UTF-8?q?requirement=20for=20`CasingStyle`=20in=20`ConvertTo-HashTable`?= =?UTF-8?q?=20and=20remove=20the=20`CasingStyle`=20module=20definition=20f?= =?UTF-8?q?ile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Hashtable/ConvertTo-HashTable.ps1 | 4 +- src/modules/CasingStyle/CasingStyle.psd1 | 40 -- src/modules/CasingStyle/CasingStyle.psm1 | 384 ------------------ 3 files changed, 3 insertions(+), 425 deletions(-) delete mode 100644 src/modules/CasingStyle/CasingStyle.psd1 delete mode 100644 src/modules/CasingStyle/CasingStyle.psm1 diff --git a/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 b/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 index 0127462e0..b4479001c 100644 --- a/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 +++ b/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 @@ -1,4 +1,6 @@ -filter ConvertTo-HashTable { +#Requires -Modules @{ ModuleName = 'CasingStyle'; RequiredVersion = '1.0.2' } + +filter ConvertTo-HashTable { <# .SYNOPSIS Converts an object to a hashtable diff --git a/src/modules/CasingStyle/CasingStyle.psd1 b/src/modules/CasingStyle/CasingStyle.psd1 deleted file mode 100644 index 4529d94f2..000000000 --- a/src/modules/CasingStyle/CasingStyle.psd1 +++ /dev/null @@ -1,40 +0,0 @@ -@{ - RootModule = 'CasingStyle.psm1' - ModuleVersion = '1.0.2' - CompatiblePSEditions = @( - 'Core' - 'Desktop' - ) - GUID = 'a886b80a-1367-46e9-b788-0a74cd786dcd' - Author = 'PSModule' - CompanyName = 'PSModule' - Copyright = '(c) 2025 PSModule. All rights reserved.' - Description = 'A PowerShell module that works with casing of text.' - PowerShellVersion = '7.4' - ProcessorArchitecture = 'None' - TypesToProcess = @() - FormatsToProcess = @() - FunctionsToExport = @( - 'ConvertTo-CasingStyle' - 'Get-CasingStyle' - 'Split-CasingStyle' - ) - CmdletsToExport = @() - ModuleList = @() - FileList = 'CasingStyle.psm1' - PrivateData = @{ - PSData = @{ - Tags = @( - 'Linux' - 'MacOS' - 'PSEdition_Core' - 'PSEdition_Desktop' - 'Windows' - ) - LicenseUri = 'https://github.com/PSModule/CasingStyle/blob/main/LICENSE' - ProjectUri = 'https://github.com/PSModule/CasingStyle' - IconUri = 'https://raw.githubusercontent.com/PSModule/CasingStyle/main/icon/icon.png' - } - } -} - diff --git a/src/modules/CasingStyle/CasingStyle.psm1 b/src/modules/CasingStyle/CasingStyle.psm1 deleted file mode 100644 index 8859395a5..000000000 --- a/src/modules/CasingStyle/CasingStyle.psm1 +++ /dev/null @@ -1,384 +0,0 @@ -[CmdletBinding()] -param() -$baseName = [System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath) -$script:PSModuleInfo = Test-ModuleManifest -Path "$PSScriptRoot\$baseName.psd1" -$script:PSModuleInfo | Format-List | Out-String -Stream | ForEach-Object { Write-Debug $_ } -$scriptName = $script:PSModuleInfo.Name -Write-Debug "[$scriptName] - Importing module" -#region [functions] - [public] -Write-Debug "[$scriptName] - [functions] - [public] - Processing folder" -#region [functions] - [public] - [ConvertTo-CasingStyle] -Write-Debug "[$scriptName] - [functions] - [public] - [ConvertTo-CasingStyle] - Importing" -filter ConvertTo-CasingStyle { - <# - .SYNOPSIS - Convert a string to a different casing style - - .DESCRIPTION - This function converts a string to a different casing style. - - .EXAMPLE - 'thisIsCamelCase' | ConvertTo-CasingStyle -To 'snake_case' - - Convert the string 'thisIsCamelCase' to 'this_is_camel_case' - - .EXAMPLE - 'thisIsCamelCase' | ConvertTo-CasingStyle -To 'UPPER_SNAKE_CASE' - - Convert the string 'thisIsCamelCase' to 'THIS_IS_CAMEL_CASE' - - .EXAMPLE - 'thisIsCamelCase' | ConvertTo-CasingStyle -To 'kebab-case' - - .OUTPUTS - [string] - The converted string - - .LINK - https://psmodule.io/CasingStyle/Functions/ConvertTo-CasingStyle/ - #> - [OutputType([string])] - [CmdletBinding()] - param ( - # The string to convert - [Parameter( - Mandatory, - ValueFromPipeline - )] - [string] $Text, - - # The casing style to convert the string to - [Parameter(Mandatory)] - [ValidateSet( - 'lowercase', - 'UPPERCASE', - 'Title Case', - 'Sentencecase', - 'PascalCase', - 'camelCase', - 'kebab-case', - 'UPPER-KEBAB-CASE', - 'snake_case', - 'UPPER_SNAKE_CASE' - )] - [string] $To - ) - - $currentStyle = Get-CasingStyle -Text $Text - - $words = Split-CasingStyle -Text $Text -By $currentStyle - - # Convert the words into the target style - switch ($To) { - 'lowercase' { ($words -join '').toLower() } - 'UPPERCASE' { ($words -join '').toUpper() } - 'Title Case' { ($words | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() }) -join ' ' } - 'Sentencecase' { $words -join '' | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() } } - 'kebab-case' { ($words -join '-').ToLower() } - 'snake_case' { ($words -join '_').ToLower() } - 'PascalCase' { ($words | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() }) -join '' } - 'camelCase' { - $words[0].toLower() + (($words | Select-Object -Skip 1 | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1) }) -join '') - } - 'UPPER_SNAKE_CASE' { ($words -join '_').toUpper() } - 'UPPER-KEBAB-CASE' { ($words -join '-').toUpper() } - } -} -Write-Debug "[$scriptName] - [functions] - [public] - [ConvertTo-CasingStyle] - Done" -#endregion [functions] - [public] - [ConvertTo-CasingStyle] -#region [functions] - [public] - [Get-CasingStyle] -Write-Debug "[$scriptName] - [functions] - [public] - [Get-CasingStyle] - Importing" -filter Get-CasingStyle { - <# - .SYNOPSIS - Detects the casing style of a string - - .DESCRIPTION - This function detects the casing style of a string. - - .EXAMPLE - 'testtesttest' | Get-CasingStyle - - lowercase - - .EXAMPLE - 'TESTTESTTEST' | Get-CasingStyle - - UPPERCASE - - .EXAMPLE - 'Testtesttest' | Get-CasingStyle - - Sentencecase - - .EXAMPLE - 'TestTestTest' | Get-CasingStyle - - PascalCase - - .EXAMPLE - 'testTestTest' | Get-CasingStyle - - camelCase - - .EXAMPLE - 'test-test-test' | Get-CasingStyle - - kebab-case - - .EXAMPLE - 'TEST-TEST-TEST' | Get-CasingStyle - - UPPER-KEBAB-CASE - - .EXAMPLE - 'test_test_test' | Get-CasingStyle - - snake_case - - .EXAMPLE - 'TEST_TEST_TEST' | Get-CasingStyle - - UPPER_SNAKE_CASE - - .EXAMPLE - 'Test_teSt-Test' | Get-CasingStyle - - Unknown - - .OUTPUTS - [string] - The detected casing style of the input string - - .LINK - https://psmodule.io/CasingStyle/Functions/Get-CasingStyle/ - #> - [OutputType([string])] - [CmdletBinding()] - param ( - # The string to check the casing style of - [Parameter( - Mandatory, - ValueFromPipeline - )] - [string] $Text - ) - - $style = if ([regex]::Match($Text, $script:LowerCase).Success) { - 'lowercase' - } elseif ([regex]::Match($Text, $script:UpperCase).Success) { - 'UPPERCASE' - } elseif ([regex]::Match($Text, $script:SentenceCase).Success) { - 'Sentencecase' - } elseif ([regex]::Match($Text, $script:TitleCase).Success) { - 'Title Case' - } elseif ([regex]::Match($Text, $script:PascalCase).Success) { - 'PascalCase' - } elseif ([regex]::Match($Text, $script:CamelCase).Success) { - 'camelCase' - } elseif ([regex]::Match($Text, $script:KebabCase).Success) { - 'kebab-case' - } elseif ([regex]::Match($Text, $script:UpperKebabCase).Success) { - 'UPPER-KEBAB-CASE' - } elseif ([regex]::Match($Text, $script:SnakeCase).Success) { - 'snake_case' - } elseif ([regex]::Match($Text, $script:UpperSnakeCase).Success) { - 'UPPER_SNAKE_CASE' - } else { - 'Unknown' - } - - Write-Verbose "Detected casing style: [$style]" - $style -} -Write-Debug "[$scriptName] - [functions] - [public] - [Get-CasingStyle] - Done" -#endregion [functions] - [public] - [Get-CasingStyle] -#region [functions] - [public] - [Split-CasingStyle] -Write-Debug "[$scriptName] - [functions] - [public] - [Split-CasingStyle] - Importing" -filter Split-CasingStyle { - <# - .SYNOPSIS - Splits a string based on one or more casing styles. - - .DESCRIPTION - This function takes a string and an array of casing styles (via the -By parameter) - and splits the string into its component words. It does this iteratively, - applying each split to every token produced by the previous one. - - .EXAMPLE - Split-CasingStyle -Text 'this-is-a-kebab-case-string' -By kebab-case - - this - is - a - kebab - case - string - - .EXAMPLE - Split-CasingStyle -Text 'this_is_a_kebab_case_string' -By 'snake_case' - - this - is - a - kebab - case - string - - .EXAMPLE - Split-CasingStyle -Text 'ThisIsAPascalCaseString' -By 'PascalCase' - - This - Is - A - Pascal - Case - String - - .EXAMPLE - Split-CasingStyle -Text 'thisIsACamelCaseString' -By 'camelCase' - - this - Is - A - Camel - Case - String - - .EXAMPLE - Split-CasingStyle -Text 'this_is_a-CamelCaseString' -By kebab-case | Split-CasingStyle -By snake_case - - this_is_a - camelcasestring - - .EXAMPLE - 'this_is_a-PascalString' | Split-CasingStyle -By 'snake_case','kebab-case','PascalCase' - - .OUTPUTS - [string[]] - An array of strings, each representing a word in the original string - - .LINK - https://psmodule.io/CasingStyle/Functions/Split-CasingStyle/ - #> - [CmdletBinding()] - param( - # The string to split - [Parameter( - Mandatory, - ValueFromPipeline - )] - [string]$Text, - - # The casing style(s) to split the string by. - [Parameter()] - [ValidateSet( - 'lowercase', - 'UPPERCASE', - 'Sentencecase', - 'Title Case', - 'PascalCase', - 'camelCase', - 'kebab-case', - 'UPPER-KEBAB-CASE', - 'snake_case', - 'UPPER_SNAKE_CASE' - )] - [string[]]$By - ) - - process { - Write-Verbose "Starting with string: [$Text]" - # Start with the original text as the only token. - $tokens = @($Text) - - # For each casing style in the -By list, split every token accordingly. - foreach ($style in $By) { - Write-Verbose "Splitting by casing style: $style" - $newTokens = @() - foreach ($token in $tokens) { - switch ($style) { - 'PascalCase' { - # Use regex to match sequences like 'Pascal' and 'String' in 'PascalString' - $matchedTokens = [regex]::Matches($token, '([A-Z][a-z]*)') - if ($matchedTokens.Count -gt 0) { - $newTokens += $matchedTokens | ForEach-Object { $_.Value } - } else { - $newTokens += $token - } - break - } - 'camelCase' { - # Match leading lowercase or uppercase letter groups - $matchedTokens = [regex]::Matches($token, '(^[a-z]+|[A-Z][a-z]*)') - if ($matchedTokens.Count -gt 0) { - $newTokens += $matchedTokens | ForEach-Object { $_.Value } - } else { - $newTokens += $token - } - break - } - 'kebab-case' { - $newTokens += $token -split '-' - break - } - 'UPPER-KEBAB-CASE' { - $newTokens += $token -split '-' - break - } - 'snake_case' { - $newTokens += $token -split '_' - break - } - 'UPPER_SNAKE_CASE' { - $newTokens += $token -split '_' - break - } - default { - # For any other case styles, you might split on whitespace - $newTokens += $token -split ' ' - break - } - } - } - # Update tokens with the newly split parts - $tokens = $newTokens - Write-Verbose "Tokens after splitting by $style`: [$($tokens -join ', ')]" - } - Write-Verbose "Final result: [$($tokens -join ', ')]" - $tokens - } -} -Write-Debug "[$scriptName] - [functions] - [public] - [Split-CasingStyle] - Done" -#endregion [functions] - [public] - [Split-CasingStyle] -Write-Debug "[$scriptName] - [functions] - [public] - Done" -#endregion [functions] - [public] -#region [variables] - [private] -Write-Debug "[$scriptName] - [variables] - [private] - Processing folder" -#region [variables] - [private] - [Cases] -Write-Debug "[$scriptName] - [variables] - [private] - [Cases] - Importing" -$script:LowerCase = '^[a-z][a-z0-9]*$' -$script:UpperCase = '^[A-Z][A-Z0-9]*$' -$script:SentenceCase = '^[A-Z][a-z0-9]*$' -$script:TitleCase = '^([A-Z][a-z]*)(\s+[A-Z][a-z]*)+$' -$script:PascalCase = '^[A-Z][a-z0-9]*([A-Z][a-z0-9]*)+$' -$script:CamelCase = '^[a-z][a-z0-9]*([A-Z][a-z0-9]*)+$' -$script:KebabCase = '^[a-z][a-z0-9]*(-[a-z0-9]+)+$' -$script:UpperKebabCase = '^[A-Z][A-Z0-9]*(-[A-Z0-9]+)+$' -$script:SnakeCase = '^[a-z][a-z0-9]*(_[a-z0-9]+)+$' -$script:UpperSnakeCase = '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)+$' -Write-Debug "[$scriptName] - [variables] - [private] - [Cases] - Done" -#endregion [variables] - [private] - [Cases] -Write-Debug "[$scriptName] - [variables] - [private] - Done" -#endregion [variables] - [private] - -#region Member exporter -$exports = @{ - Alias = '*' - Cmdlet = '' - Function = @( - 'ConvertTo-CasingStyle' - 'Get-CasingStyle' - 'Split-CasingStyle' - ) -} -Export-ModuleMember @exports -#endregion Member exporter - From 1f118cb7c97508481d2cad87bf801bb8061ca991 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Feb 2025 17:55:12 +0100 Subject: [PATCH 10/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20SkipTe?= =?UTF-8?q?sts=20option=20from=20Process-PSModule=20workflow=20for=20impro?= =?UTF-8?q?ved=20test=20execution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Process-PSModule.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index bc8b830f0..5252ed337 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -36,5 +36,3 @@ jobs: TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }} TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }} TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }} - with: - SkipTests: All From 58e60c2e2a6b17511d639cf77ead62182d2d5e16 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Feb 2025 19:00:22 +0100 Subject: [PATCH 11/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20debug=20o?= =?UTF-8?q?utput=20to=20`Get-GitHubGitConfig`=20for=20improved=20configura?= =?UTF-8?q?tion=20tracking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Git/Get-GitHubGitConfig.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions/public/Git/Get-GitHubGitConfig.ps1 b/src/functions/public/Git/Get-GitHubGitConfig.ps1 index af4babb61..403c5a853 100644 --- a/src/functions/public/Git/Get-GitHubGitConfig.ps1 +++ b/src/functions/public/Git/Get-GitHubGitConfig.ps1 @@ -54,6 +54,7 @@ $configList = $configList | Sort-Object $configList | ForEach-Object { + Write-Debug "CONFIG: $_" $name, $value = $_ -split '=', 2 $config += @{ ($name.Trim()) = ($value.Trim()) From 2673f792a816b5586d6e3f8a1750305b3f6d6095 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Feb 2025 19:01:52 +0100 Subject: [PATCH 12/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Trim=20whitespa?= =?UTF-8?q?ce=20from=20Git=20configuration=20name=20and=20value=20in=20`Ge?= =?UTF-8?q?t-GitHubGitConfig`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Git/Get-GitHubGitConfig.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/functions/public/Git/Get-GitHubGitConfig.ps1 b/src/functions/public/Git/Get-GitHubGitConfig.ps1 index 403c5a853..4023077a2 100644 --- a/src/functions/public/Git/Get-GitHubGitConfig.ps1 +++ b/src/functions/public/Git/Get-GitHubGitConfig.ps1 @@ -56,8 +56,10 @@ $configList | ForEach-Object { Write-Debug "CONFIG: $_" $name, $value = $_ -split '=', 2 + $name = ("" + $name).Trim() + $value = ('' + $value).Trim() $config += @{ - ($name.Trim()) = ($value.Trim()) + $name = $value } } $config From ef1618022f2173fd3d6ee4ba7b4e636216375bfb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Feb 2025 19:02:04 +0100 Subject: [PATCH 13/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Use=20single=20?= =?UTF-8?q?quotes=20for=20string=20concatenation=20in=20`Get-GitHubGitConf?= =?UTF-8?q?ig`=20for=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Git/Get-GitHubGitConfig.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Git/Get-GitHubGitConfig.ps1 b/src/functions/public/Git/Get-GitHubGitConfig.ps1 index 4023077a2..3698f8b0d 100644 --- a/src/functions/public/Git/Get-GitHubGitConfig.ps1 +++ b/src/functions/public/Git/Get-GitHubGitConfig.ps1 @@ -56,7 +56,7 @@ $configList | ForEach-Object { Write-Debug "CONFIG: $_" $name, $value = $_ -split '=', 2 - $name = ("" + $name).Trim() + $name = ('' + $name).Trim() $value = ('' + $value).Trim() $config += @{ $name = $value