From ae1947ba73093ba3f70944d8e69024b430151236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 12 Mar 2026 10:15:45 +0100 Subject: [PATCH 1/6] fix(MyWrite): streamline debug and verbose section handling --- include/MyWrite.ps1 | 113 +++++++++++++++++++++++++++++--------------- 1 file changed, 76 insertions(+), 37 deletions(-) diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 index ca3269f..1ecc794 100644 --- a/include/MyWrite.ps1 +++ b/include/MyWrite.ps1 @@ -53,10 +53,20 @@ function Write-MyHost { [Parameter()][string]$ForegroundColor = $OUTPUT_COLOR, [Parameter()][switch]$NoNewLine ) + + Write-MyDebug -Section "MyHost" -Message $Message + # Write-Host $message -ForegroundColor $OUTPUT_COLOR Write-ToConsole $message -Color $ForegroundColor -NoNewLine:$NoNewLine } +function Clear-MyHost { + [CmdletBinding()] + param() + + Clear-Host +} + function Write-MyDebug { [CmdletBinding()] [Alias("Write-Debug")] @@ -77,7 +87,7 @@ function Write-MyDebug { $timestamp = Get-Date -Format 'HH:mm:ss.fff' # Write on host - $logMessage ="[$timestamp][D][$section] $message" + $logMessage ="[$timestamp][$MODULE_NAME][D][$section] $message" $logMessage | Write-ToConsole -Color $DEBUG_COLOR $logMessage | Write-MyDebugLogging @@ -92,8 +102,7 @@ function Write-MyDebugLogging { process{ - $moduleDebugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH" - $loggingFilePath = [System.Environment]::GetEnvironmentVariable($moduleDebugLoggingVarName) + $loggingFilePath = get-DebugLogFile # Check if logging is enabled if ([string]::IsNullOrWhiteSpace( $loggingFilePath )) { @@ -134,8 +143,7 @@ function Test-MyVerbose { [Parameter(Position = 0)][string]$section ) - $moduleDebugVarName = $MODULE_NAME + "_VERBOSE" - $flag = [System.Environment]::GetEnvironmentVariable($moduleDebugVarName) + $flag = get-VerboseSections if ([string]::IsNullOrWhiteSpace( $flag )) { return $false @@ -156,8 +164,7 @@ function Enable-ModuleNameVerbose{ $flag = $section } - $moduleDebugVarName = $MODULE_NAME + "_VERBOSE" - [System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $flag) + set-VerboseSections $flag } Copy-Item -path Function:Enable-ModuleNameVerbose -Destination Function:"Enable-$($MODULE_NAME)Verbose" Export-ModuleMember -Function "Enable-$($MODULE_NAME)Verbose" @@ -165,8 +172,7 @@ Export-ModuleMember -Function "Enable-$($MODULE_NAME)Verbose" function Disable-ModuleNameVerbose{ param() - $moduleDebugVarName = $MODULE_NAME + "_VERBOSE" - [System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $null) + set-VerboseSections $null } Copy-Item -path Function:Disable-ModuleNameVerbose -Destination Function:"Disable-$($MODULE_NAME)Verbose" Export-ModuleMember -Function "Disable-$($MODULE_NAME)Verbose" @@ -184,19 +190,19 @@ function Test-MyDebug { $flags = $flags.ToLower() $section = $section.ToLower() - return ($flags.Contains("all")) -or ( $flags.Contains($section)) + return ($flags.Contains("all")) -or ( $flags -eq $section) } - $moduleDebugVarName = $MODULE_NAME + "_DEBUG" - $flagsString = [System.Environment]::GetEnvironmentVariable($moduleDebugVarName) + + $sectionsString = get-DebugSections # No configuration means no debug - if([string]::IsNullOrWhiteSpace( $flagsString )) { + if([string]::IsNullOrWhiteSpace( $sectionsString )) { return $false } - # Get flags from flagdsString - $flags = getFlagsFromSectionsString $flagsString + # Get flags from sectionsString + $flags = getSectionsFromSectionsString $sectionsString # Add all if allow is empty. # This mean stat flagsString only contains filters. @@ -228,57 +234,54 @@ function Enable-ModuleNameDebug{ } } - $flagsString = $sections -join " " + $sectionsString = $sections -join " " $addedFlagsString = $AddSections -join " " # if no section get value from env and is still mepty set to all - if([string]::IsNullOrWhiteSpace( $flagsString )) { - $flagsString = get-Sections - if( [string]::IsNullOrWhiteSpace( $flagsString )) { - $flagsString = "all" + if([string]::IsNullOrWhiteSpace( $sectionsString )) { + $sectionsString = get-DebugSections + if( [string]::IsNullOrWhiteSpace( $sectionsString )) { + $sectionsString = "all" } } - # Add added to flagsString if provided + # Add added to sectionsString if provided if(-Not [string]::IsNullOrWhiteSpace( $addedFlagsString )) { - $flagsString += " " + $addedFlagsString + $sectionsString += " " + $addedFlagsString } - set-Sections $flagsString + set-DebugSections $sectionsString } Copy-Item -path Function:Enable-ModuleNameDebug -Destination Function:"Enable-$($MODULE_NAME)Debug" Export-ModuleMember -Function "Enable-$($MODULE_NAME)Debug" -function getFlagsFromSectionsString($sectionsString){ - $flags = @{ +function getSectionsFromSectionsString($sectionsString){ + $sections = @{ allow = $null filter = $null } if([string]::IsNullOrWhiteSpace($sectionsString) ){ - $flags.allow = @("all") - return $flags + $sections.allow = @("all") + return $sections } $list = $sectionsString.Split(" ", [StringSplitOptions]::RemoveEmptyEntries) $split = @($list).Where({ $_ -like '-*' }, 'Split') - $flags.filter = $split[0] | ForEach-Object { $_ -replace '^-', '' } # -> API, Auth - $flags.allow = $split[1] # -> Sync, Cache + $sections.filter = $split[0] | ForEach-Object { $_ -replace '^-', '' } # -> API, Auth + $sections.allow = $split[1] # -> Sync, Cache - return $flags + return $sections } function Disable-ModuleNameDebug { param() - $moduleDebugVarName = $MODULE_NAME + "_DEBUG" - [System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $null) - - $moduleDEbugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH" - [System.Environment]::SetEnvironmentVariable($moduleDEbugLoggingVarName, $null) + set-DebugSections $null + set-LogFile $null } Copy-Item -path Function:Disable-ModuleNameDebug -Destination Function:"Disable-$($MODULE_NAME)Debug" Export-ModuleMember -Function "Disable-$($MODULE_NAME)Debug" @@ -288,8 +291,8 @@ function Get-ModuleNameDebug { param() return @{ - Sections = get-Sections - LoggingFilePath = get-LogFile + Sections = get-DebugSections + LoggingFilePath = get-DebugLogFile } } Copy-Item -path Function:Get-ModuleNameDebug -Destination Function:"Get-$($MODULE_NAME)Debug" @@ -337,3 +340,39 @@ function set-LogFile($logFilePath){ $moduleDEbugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH" [System.Environment]::SetEnvironmentVariable($moduleDEbugLoggingVarName, $logFilePath) } + +function get-DebugSections(){ + $moduleDebugVarName = $MODULE_NAME + "_DEBUG" + $sections = [System.Environment]::GetEnvironmentVariable($moduleDebugVarName) + + return $sections +} + +function set-DebugSections($sections){ + $moduleDebugVarName = $MODULE_NAME + "_DEBUG" + [System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $sections) +} + +function get-DebugLogFile(){ + $moduleDEbugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH" + $logfile = [System.Environment]::GetEnvironmentVariable($moduleDEbugLoggingVarName) + + return $logfile +} + +function set-LogFile($logFilePath){ + $moduleDEbugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH" + [System.Environment]::SetEnvironmentVariable($moduleDEbugLoggingVarName, $logFilePath) +} + +function get-VerboseSections{ + $moduleVerboseVarName = $MODULE_NAME + "_VERBOSE" + $sections = [System.Environment]::GetEnvironmentVariable($moduleVerboseVarName) + + return $sections +} + +function set-VerboseSections($sections){ + $moduleVerboseVarName = $MODULE_NAME + "_VERBOSE" + [System.Environment]::SetEnvironmentVariable($moduleVerboseVarName, $sections) +} \ No newline at end of file From db5f98b4ca0bbe8fee117f5dd4512cd0c0c79de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 12 Mar 2026 10:15:55 +0100 Subject: [PATCH 2/6] refactor(ProjectDatabase): enhance debug logging and cache handling --- private/projectDatabase/project_database.ps1 | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/private/projectDatabase/project_database.ps1 b/private/projectDatabase/project_database.ps1 index 0793c9f..2e58785 100644 --- a/private/projectDatabase/project_database.ps1 +++ b/private/projectDatabase/project_database.ps1 @@ -7,10 +7,14 @@ function Test-ProjectDatabase{ [Parameter(Position = 1)][int]$ProjectNumber ) + "Testing project database for $Owner/$ProjectNumber >>>" | Write-MyDebug -Section "ProjectDatabase" + $key,$keyLock = Get-ProjectDatabaseKey -Owner $Owner -ProjectNumber $ProjectNumber $ret = Test-Database -Key $key + "Testing project database for $Owner/$ProjectNumber <<< $ret" | Write-MyDebug -Section "ProjectDatabase" + return $ret } @@ -46,12 +50,16 @@ function Get-ProjectFromDatabase{ ) $key,$keyLock = Get-ProjectDatabaseKey -Owner $Owner -ProjectNumber $ProjectNumber + + "Getting project for $Owner/$ProjectNumber" | Write-MyDebug -Section "ProjectDatabase" $prj = getProjectDatabaseCache -KeyLock $keyLock if($null -ne $prj){ - "Project cache hit for $Owner/$ProjectNumber" | Write-MyDebug -Section "ProjectDatabase" + "🟩 Get Project Database from MEMORY $Owner/$ProjectNumber" | Write-MyDebug -Section "ProjectDatabase" return $prj + } else { + "🟧 Get Project Database from FILE $Owner/$ProjectNumber" | Write-MyDebug -Section "ProjectDatabase" } # No cache or cache mismatch, read from database @@ -65,6 +73,9 @@ function Get-ProjectFromDatabase{ $prj.items = $prj.items | Copy-MyHashTable $prj.Staged = $prj.Staged | Copy-MyHashTable + # Savige to cache for future calls + setProjectDatabaseCache -KeyLock $keyLock -SafeId $prj.safeId -Database $prj + return $prj } @@ -161,6 +172,9 @@ function Save-ProjectDatabase{ # Add safe mark $Database.safeId = [guid]::NewGuid().ToString() + # Trace + "🟥 Save Project Database from FILE $Owner/$ProjectNumber safeId [$($Database.safeId)]" | Write-MyDebug -Section "ProjectDatabase" + # Save database Save-Database -Key $dbkey -Database $Database setProjectDatabaseCache -KeyLock $dbkeyLock -SafeId $Database.safeId -Database $Database @@ -231,7 +245,7 @@ function resetProjectDatabaseCache{ "Resetting project cache for $KeyLock" | Write-MyDebug -Section "ProjectDatabase" - Reset.Database -Key $KeyLock + Reset-Database -Key $KeyLock $script:ProjectDatabaseCache.Remove($KeyLock) } \ No newline at end of file From 5e51436a44dc0e98416f6f16d7fd7e8efdd17045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 12 Mar 2026 10:16:04 +0100 Subject: [PATCH 3/6] refactor(Add-ProjectSubissueCreate): enhance parameter handling for ItemId --- public/issues/Add-ProjectSubIssue.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/issues/Add-ProjectSubIssue.ps1 b/public/issues/Add-ProjectSubIssue.ps1 index 1744cb5..7d6cc85 100644 --- a/public/issues/Add-ProjectSubIssue.ps1 +++ b/public/issues/Add-ProjectSubIssue.ps1 @@ -64,7 +64,8 @@ function Add-ProjectSubissueCreate { [CmdletBinding()] [Alias("New-Issue")] param ( - [Parameter(Mandatory, Position = 0)][string]$ItemId, + [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName, Position = 0)][Alias("Id")][string]$ItemId, + [Parameter(Position = 1)][string]$RepoOwner, [Parameter(Position = 2)][string]$RepoName, [Parameter(Mandatory, Position = 3)][string]$Title, From 4f41ba86dd9225bc937cfd23ada3681c4e9dbf57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 12 Mar 2026 10:16:26 +0100 Subject: [PATCH 4/6] refactor(Search-ProjectItem): add comment for parameter resolution --- public/items/project_item.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/items/project_item.ps1 b/public/items/project_item.ps1 index cd11a01..04ffae4 100644 --- a/public/items/project_item.ps1 +++ b/public/items/project_item.ps1 @@ -195,8 +195,8 @@ function Search-ProjectItem { $Attributes = @("id") + $Attributes } - -($owner,$ProjectNumber) = Resolve-ProjectParameters -Owner $Owner -ProjectNumber $ProjectNumber + # Resolve project parameters + ($owner,$ProjectNumber) = Resolve-ProjectParameters -Owner $Owner -ProjectNumber $ProjectNumber # Get items as hashtable for later queries $items = Get-ProjectItems -Owner $Owner -ProjectNumber $ProjectNumber -Force:$Force -IncludeDone:$IncludeDone -AsHashtable From 17bab2eb2278530dad18114e22585c226636ad64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 12 Mar 2026 10:17:19 +0100 Subject: [PATCH 5/6] feat(Use-Order): add DontShow parameter --- public/items/use_order.ps1 | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/public/items/use_order.ps1 b/public/items/use_order.ps1 index 45cb4f9..8c0b6be 100644 --- a/public/items/use_order.ps1 +++ b/public/items/use_order.ps1 @@ -8,6 +8,7 @@ function Use-Order { [Parameter()][Alias("w")][switch]$OpenInBrowser, [Parameter()][Alias("p")][switch]$PassThru, [Parameter()][Alias("c")][switch]$ClearScreen, + [Parameter()][Alias("d")][switch]$DontShow, [Parameter()][scriptblock]$ShowProjectItemScriptBlock ) @@ -54,24 +55,26 @@ function Use-Order { throw "ProjectEnvironment is required. Run Set-ProjectHelperEnvironment" } - #return item + if( -not $DontShow){ + # Get function to show item + $ShowProjectItemScriptBlock = $ShowProjectItemScriptBlock ?? { param($parameters) Show-ProjectItem @parameters } + + # Show item in console or editor + $params = @{ + Item = $itemId + OpenInEditor = $OpenInEditor + OpenInBrowser = $OpenInBrowser + ClearScreen = $ClearScreen + } + $ShowProjectItemScriptBlock.Invoke($params) + } + + #return item if($PassThru) { $i = Get-ProjectItem -ItemId $itemId return [PsCustomObject]$i } - # Get function to show item - $ShowProjectItemScriptBlock = $ShowProjectItemScriptBlock ?? { param($parameters) Show-ProjectItem @parameters } - - # Show item in console or editor - $params = @{ - Item = $itemId - OpenInEditor = $OpenInEditor - OpenInBrowser = $OpenInBrowser - ClearScreen = $ClearScreen - } - $ShowProjectItemScriptBlock.Invoke($params) - return } } Export-ModuleMember -Function Use-Order -Alias "uo" \ No newline at end of file From 82f000ab91d2073dc9433cd1d899af6bcff8e89d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 12 Mar 2026 10:17:37 +0100 Subject: [PATCH 6/6] refactor(Get-Project): enhance debug logging for project retrieval --- public/project/getproject.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/public/project/getproject.ps1 b/public/project/getproject.ps1 index 89e2c4a..ef4dc25 100644 --- a/public/project/getproject.ps1 +++ b/public/project/getproject.ps1 @@ -9,6 +9,8 @@ function Get-Project { ($Owner, $ProjectNumber) = Resolve-ProjectParameters -Owner $Owner -ProjectNumber $ProjectNumber + "Getting project for $Owner/$ProjectNumber with SkipItems=$SkipItems and Force=$Force >>>" | Write-MyDebug -Section "Get-Project" + if ($Force -or -Not (Test-ProjectDatabase -Owner $Owner -ProjectNumber $ProjectNumber)) { "Project not found in database or force specified. Updating project for $Owner/$ProjectNumber." | Write-MyDebug -Section Get-Project @@ -16,14 +18,16 @@ function Get-Project { if ( ! $result) { "Failed to update project for $Owner/$ProjectNumber. Project may not exist or there was an error during update." | Write-MyError - return + return } } else { - "Project found in database for $Owner/$ProjectNumber. Loading project." | Write-MyDebug -Section Get-Project + "Project found in database for $Owner/$ProjectNumber. Calling to retreive." | Write-MyDebug -Section Get-Project } $prj = Get-ProjectFromDatabase -Owner $Owner -ProjectNumber $ProjectNumber + "Getting project for $Owner/$ProjectNumber with SkipItems=$SkipItems and Force=$Force <<< $($prj.safeId)" | Write-MyDebug -Section "Get-Project" + return $prj } Export-ModuleMember -Function Get-Project