From c0b5268944df67f59b313e842581258c42f13a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Wed, 1 Oct 2025 12:48:17 +0200 Subject: [PATCH 01/14] refactor(tests): update Show-ProjectItem function and related tests --- Test/public/project_item.test.ps1 | 24 ++++++---- public/project_item.ps1 | 76 +++++++++++++++---------------- 2 files changed, 54 insertions(+), 46 deletions(-) diff --git a/Test/public/project_item.test.ps1 b/Test/public/project_item.test.ps1 index b1d5054..7b8da7c 100644 --- a/Test/public/project_item.test.ps1 +++ b/Test/public/project_item.test.ps1 @@ -261,13 +261,21 @@ function Test_ShowProjectItem_SUCCESS{ $item = Get-ProjectItem -Owner $owner -ProjectNumber $projectNumber -ItemId $id - $result = $item | Show-ProjectItem -AdditionalFields "Status" + # Act 0 + $result0 = $item | Show-ProjectItem - Assert-Count -Expected 1 -Presented $result + Assert-Count -Expected 1 -Presented $result0 - Assert-AreEqual -Expected $id -Presented $result[0].id - Assert-AreEqual -Expected $title -Presented $result[0].Title - Assert-AreEqual -Expected $status -Presented $result[0].Status + Assert-AreEqual -Expected $id -Presented $result0[0].id + Assert-AreEqual -Expected $title -Presented $result0[0].Title + + $result1 = $item | Show-ProjectItem -Attributes "id","Title","Status" + + Assert-Count -Expected 1 -Presented $result1 + + Assert-AreEqual -Expected $id -Presented $result1[0].id + Assert-AreEqual -Expected $title -Presented $result1[0].Title + Assert-AreEqual -Expected $status -Presented $result1[0].Status } function Test_ShowProjectItem_SUCCESS_Multiple{ @@ -279,16 +287,16 @@ function Test_ShowProjectItem_SUCCESS_Multiple{ $p = Get-Mock_Project_700; $Owner = $p.owner; $ProjectNumber = $p.number # Arrange - get a few items using search-projectitem - $items = Search-ProjectItem -Owner $owner -ProjectNumber $projectNumber -Filter $p.searchInTitle.titleFilter + $items = Search-ProjectItem -Owner $owner -ProjectNumber $projectNumber -Filter $p.searchInTitle.titleFilter -PassThru $itemsCount = $items.Count Assert-Count -Expected $p.searchInTitle.totalCount -Presented $items - $result = $items | Show-ProjectItem -AdditionalFields "Status" + $result = $items | Show-ProjectItem -Attributes "id","url","Status" Assert-Count -Expected $itemsCount -Presented $result # Get properties of the first item to verify - $expectedProperties = @("id", "Title", "Status") + $expectedProperties = @("id","url","Status") # Verify all items have the same structure for ($i = 1; $i -lt $result.Count; $i++) { diff --git a/public/project_item.ps1 b/public/project_item.ps1 index 493c9ca..dd289e8 100644 --- a/public/project_item.ps1 +++ b/public/project_item.ps1 @@ -126,42 +126,42 @@ function Search-ProjectItem { if($PassThru){ $ret = $found } else { - - $ret = @($found | ForEach-Object { - $i = [pscustomobject]::new() - # return the issue with additional attributes - Add-Attributes -SourceObject $_ -DestinationObject $i -Attributes $Attributes - }) - + $ret = $found | Show-ProjectItem -Attributes $Attributes } return $ret } Export-ModuleMember -Function Search-ProjectItem -Alias "spi" -function Add-Attributes{ + +function Show-ProjectItem{ [CmdletBinding()] param( - [Parameter(Position = 0)][object]$SourceObject, - [Parameter(Position = 1)][object]$DestinationObject, - [Parameter(Position = 2)][string[]]$Attributes + [Parameter(ValueFromPipeline)][object]$Item, + [Parameter(Position = 1)][string[]]$Attributes ) - # return if empty attributes - if([string]::IsNullOrWhiteSpace($Attributes)){ - return $DestinationObject + begin { + if([string]::IsNullOrWhiteSpace($Attributes)){ + $Attributes = @("id", "Title") + } } - foreach($a in $Attributes){ - if( ! $SourceObject.$a){ - continue + process{ + + $ret = [pscustomobject]::new() + + foreach($a in $Attributes){ + if( ! $Item.$a){ + continue + } + + $ret | Add-Member -MemberType NoteProperty -Name $a -Value $Item.$a -force } - $DestinationObject | Add-Member -MemberType NoteProperty -Name $a -Value $SourceObject.$a -force + return $ret } - - return $DestinationObject -} +} Export-ModuleMember -Function Show-ProjectItem function Get-ProjectItems { @@ -442,27 +442,27 @@ function Get-ProjectItemDirect { return $item } Export-ModuleMember -Function Get-ProjectItemDirect -function Show-ProjectItem { - [CmdletBinding()] - param( - [Parameter(Position = 0)][string]$Owner, - [Parameter(Position = 1)][string]$ProjectNumber, - [Parameter(ValueFromPipeline)][object]$Item, - [Parameter()][string[]]$AdditionalFields - ) +# function Show-ProjectItem { +# [CmdletBinding()] +# param( +# [Parameter(Position = 0)][string]$Owner, +# [Parameter(Position = 1)][string]$ProjectNumber, +# [Parameter(ValueFromPipeline)][object]$Item, +# [Parameter()][string[]]$AdditionalFields +# ) - begin { - $fields = Get-EnvironmentDisplayFields -Fields $AdditionalFields +# begin { +# $fields = Get-EnvironmentDisplayFields -Fields $AdditionalFields - $fields | Write-Verbose - } +# $fields | Write-Verbose +# } - process { - $ret = $item | Select-Object -Property $Fields +# process { +# $ret = $item | Select-Object -Property $Fields - return $ret - } -} Export-ModuleMember -Function Show-ProjectItem +# return $ret +# } +# } Export-ModuleMember -Function Show-ProjectItem function Test-ProjectItemIsLikeAnyField { From fdca2909ca3722b51b191ac79401af6ca3bcf0e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 3 Oct 2025 07:20:09 +0200 Subject: [PATCH 02/14] refactor(graphql): enhance FindProject query structure with more fields --- public/graphql/findProject.query | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/public/graphql/findProject.query b/public/graphql/findProject.query index c81f4c7..73a82fa 100644 --- a/public/graphql/findProject.query +++ b/public/graphql/findProject.query @@ -4,12 +4,20 @@ query FindProject($afterProject:String $firstProject:Int! $login:String! $patter nodes { id title + shortDescription + readme number url + template createdAt updatedAt closedAt - + repositories(first: 100) { + nodes { + name + url + } + } } } } From 5f32fb746ee0c5d45ca4109a2ea129c8e9757ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 3 Oct 2025 07:20:30 +0200 Subject: [PATCH 03/14] fix(findproject): change output from Write-MyHost to Write-MyVerbose --- public/project/findproject.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/public/project/findproject.ps1 b/public/project/findproject.ps1 index 602ce87..3223a80 100644 --- a/public/project/findproject.ps1 +++ b/public/project/findproject.ps1 @@ -40,8 +40,7 @@ function Find-Project{ return $null } - "[$($projects.Count)] projects found" | Write-MyHost - + "[$($projects.Count)] projects found" | Write-MyVerbose return $projects } Export-ModuleMember -Function Find-Project \ No newline at end of file From 9d8400c3ed25a579a9573884b9f27f9346184e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 3 Oct 2025 07:21:00 +0200 Subject: [PATCH 04/14] fix(environment): enable ValueFromPipelineByPropertyName for parameters to allow piping parameters --- public/environmentCache.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/environmentCache.ps1 b/public/environmentCache.ps1 index f546f64..4560aa5 100644 --- a/public/environmentCache.ps1 +++ b/public/environmentCache.ps1 @@ -33,9 +33,9 @@ function Reset-ProjectHelperEnvironment{ function Set-ProjectHelperEnvironment{ [CmdletBinding()] param( - [Parameter()][string]$Owner, - [Parameter()][string]$ProjectNumber, - [Parameter()][string[]]$DisplayFields + [Parameter(ValueFromPipelineByPropertyName)][string]$Owner, + [Parameter(ValueFromPipelineByPropertyName)][string]$ProjectNumber, + [Parameter(ValueFromPipelineByPropertyName)][string[]]$DisplayFields ) if(! [string]::IsNullOrWhiteSpace($Owner)) { From 9ca76da40f1288df42f7dc154c94235bf83f8e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 3 Oct 2025 07:21:29 +0200 Subject: [PATCH 05/14] feat(transcript): add helper functions for managing test transcripts --- .../TranscriptHelp.ps1 => include/transcriptHelp.ps1} | 5 +++++ 1 file changed, 5 insertions(+) rename Test/{private/TranscriptHelp.ps1 => include/transcriptHelp.ps1} (76%) diff --git a/Test/private/TranscriptHelp.ps1 b/Test/include/transcriptHelp.ps1 similarity index 76% rename from Test/private/TranscriptHelp.ps1 rename to Test/include/transcriptHelp.ps1 index 1947819..2dd2dc5 100644 --- a/Test/private/TranscriptHelp.ps1 +++ b/Test/include/transcriptHelp.ps1 @@ -1,3 +1,8 @@ +# Test Transcript helper functions +# These functions help manage the transcript file during tests +# and ensure it is cleaned up after use. + + $TEST_TRANSCRIPT_FILE = "test_transcript.log" function Start-MyTranscript { From c5b4292e7bf116a96e8bad1bd51545dcdd81a128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 3 Oct 2025 07:22:23 +0200 Subject: [PATCH 06/14] fix(Get-ProjectItem): enable ValueFromPipelineByPropertyName for ItemId parameter --- public/project_item.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/project_item.ps1 b/public/project_item.ps1 index dd289e8..0c95c20 100644 --- a/public/project_item.ps1 +++ b/public/project_item.ps1 @@ -14,7 +14,7 @@ function Get-ProjectItem { [CmdletBinding()] [Alias ("gpi")] param( - [Parameter(Mandatory, ValueFromPipeline, Position = 0)][string]$ItemId, + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0)][Alias("id")][string]$ItemId, [Parameter()][string]$Owner, [Parameter()][string]$ProjectNumber, [Parameter()][switch]$Force From 4787ee0c9aa21937c372e03ce1699dc77113bb4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 3 Oct 2025 07:22:29 +0200 Subject: [PATCH 07/14] fix(Remove-ProjectItemDirect): add SupportsShouldProcess to enable confirmation before removal --- public/project_item.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/public/project_item.ps1 b/public/project_item.ps1 index 0c95c20..e26d635 100644 --- a/public/project_item.ps1 +++ b/public/project_item.ps1 @@ -361,7 +361,7 @@ function Add-ProjectItemDirect { } Export-ModuleMember -Function Add-ProjectItemDirect -Alias "Add-ProjectItem", "api" function Remove-ProjectItemDirect { - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param( [Parameter()][string]$Owner, [Parameter()][string]$ProjectNumber, @@ -391,7 +391,11 @@ function Remove-ProjectItemDirect { } # Remove item from project - $response = Invoke-MyCommand -Command RemoveItemFromProject -Parameters @{ projectid = $projectId ; itemid = $ItemId } + if ($PSCmdlet.ShouldProcess($ItemId, "RRemove from project $Owner/$ProjectNumber")) { + $response = Invoke-MyCommand -Command RemoveItemFromProject -Parameters @{ projectid = $projectId ; itemid = $ItemId } + } else { + return $ItemId + } # check if the response is null if ($response.errors) { From 6172759a1e3b6e69c3ac3333c9151aa2a04c4305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 3 Oct 2025 08:17:45 +0200 Subject: [PATCH 08/14] fix(invokeCommand): remove write-debug from Invoke-Mycommand. --- helper/invokeCommand.helper.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/helper/invokeCommand.helper.ps1 b/helper/invokeCommand.helper.ps1 index 1e83a86..9c08581 100644 --- a/helper/invokeCommand.helper.ps1 +++ b/helper/invokeCommand.helper.ps1 @@ -35,7 +35,5 @@ function Invoke-MyCommand{ [Parameter(Position=1)][hashtable]$Parameters ) - Write-Debug "[invoke] $Command" $Parameters - return InvokeHelper\Invoke-MyCommand -Command $Command -Parameters $Parameters } \ No newline at end of file From 5448ee8274ba8655e53003e89327c72c0ce7d003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 3 Oct 2025 08:27:18 +0200 Subject: [PATCH 09/14] refactor(Write-MyVerbose): replace Write-Verbose with Write-ToConsole for consistency --- include/MyWrite.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 index 2aa9004..4a589d9 100644 --- a/include/MyWrite.ps1 +++ b/include/MyWrite.ps1 @@ -24,7 +24,8 @@ function Write-MyVerbose { param( [Parameter(ValueFromPipeline)][string]$Message ) - Write-Verbose -Message $message + + Write-ToConsole $message -Color $VERBOSE_COLOR } function Write-MyHost { From 926a9a8eb5fe4f2ce2bb93bbdf38f0ee2e05011d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 3 Oct 2025 08:30:16 +0200 Subject: [PATCH 10/14] refactor(Write-MyDebug): improve debug message formatting and object string handling --- include/MyWrite.ps1 | 56 +++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 index 4a589d9..a551940 100644 --- a/include/MyWrite.ps1 +++ b/include/MyWrite.ps1 @@ -1,6 +1,7 @@ $ERROR_COLOR = "Red" $WARNING_COLOR = "Yellow" +$VERBOSE_COLOR = "DarkYellow" $OUTPUT_COLOR = "DarkCyan" $DEBUG_COLOR = "DarkGray" @@ -45,25 +46,15 @@ function Write-Debug { [Parameter(Position = 2)][object]$Object ) - $flag = $env:ProjectHelper_DEBUG - - # Enable debug - if ([string]::IsNullOrWhiteSpace( $flag )) { - return - } - - $trace = ($flag -like '*all*') -or ( $section -like "*$flag*") + if (Test-Debug -section $section) { - # Write-Host $message -ForegroundColor $DEBUG_COLOR - if ($trace) { if ($Object) { - $objJson = $Object | ConvertTo-Json -Depth 10 -ErrorAction SilentlyContinue - $message = $message + " - " + $objJson + $objString = $Object | Get-ObjetString + $message = $message + " - " + $objString } - - $message = "[DEBUG][$section] " + $message - Write-ToConsole $message -Color $DEBUG_COLOR + $timestamp = Get-Date -Format 'HH:mm:ss.fff' + "[$timestamp][D][$section] $message" | Write-ToConsole -Color $DEBUG_COLOR } } @@ -75,4 +66,39 @@ function Write-ToConsole { ) Microsoft.PowerShell.Utility\Write-Host $message -ForegroundColor $Color -NoNewLine:$NoNewLine +} + +function Test-Debug { + param( + [Parameter(Position = 0)][string]$section + ) + + $flag = $env:ProjectHelper_DEBUG + + # Enable debug + if ([string]::IsNullOrWhiteSpace( $flag )) { + return $false + } + + $trace = ($flag -like '*all*') -or ( $section -like "*$flag*") + return $trace +} + +function Get-ObjetString { + param( + [Parameter(ValueFromPipeline, Position = 0)][object]$Object + ) + + process{ + + if ($null -eq $Object) { + return "null" + } + + if ($Object -is [string]) { + return $Object + } + + return $Object | ConvertTo-Json -Depth 10 -ErrorAction SilentlyContinue + } } \ No newline at end of file From cecbf9f4b2df2c07b948556f14bf9a57bc903bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 3 Oct 2025 08:31:47 +0200 Subject: [PATCH 11/14] refactor(driver_gh): enhance debug output for Invoke-GitHubUpdateItemValues --- private/invokeRestMethord.ps1 | 3 +++ public/driver_gh.ps1 | 2 ++ 2 files changed, 5 insertions(+) diff --git a/private/invokeRestMethord.ps1 b/private/invokeRestMethord.ps1 index 669ede6..e1eed8e 100644 --- a/private/invokeRestMethord.ps1 +++ b/private/invokeRestMethord.ps1 @@ -20,7 +20,10 @@ function Invoke-RestMethod{ $params.OutFile = $OutFile } + ">> $Method $Uri" | Write-Debug -section "invokeRestMethod" $result = Microsoft.PowerShell.Utility\Invoke-RestMethod @params + "<< $Method $Uri" | Write-Debug -section "invokeRestMethod" + return $result } \ No newline at end of file diff --git a/public/driver_gh.ps1 b/public/driver_gh.ps1 index bc8f704..469822a 100644 --- a/public/driver_gh.ps1 +++ b/public/driver_gh.ps1 @@ -159,6 +159,8 @@ function Invoke-GitHubUpdateItemValues{ [string]$Type ) + "ProjectId: $ProjectId, ItemId: $ItemId, FieldId: $FieldId, Value: $Value, Type: $Type" | Write-Debug -section "driver_gh" + # Use the environmentraviable $token = Get-GithubToken if(-not $token){ From a09492c81b5353a18f83d6292499e530461b33d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 3 Oct 2025 08:32:15 +0200 Subject: [PATCH 12/14] fix(Sync-Project): convert display value to update value for staged items --- private/projectDatabase/project_database_Async.ps1 | 5 ++++- private/projectDatabase/project_database_Sync.ps1 | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/private/projectDatabase/project_database_Async.ps1 b/private/projectDatabase/project_database_Async.ps1 index 246db2e..c947598 100644 --- a/private/projectDatabase/project_database_Async.ps1 +++ b/private/projectDatabase/project_database_Async.ps1 @@ -57,6 +57,9 @@ function Sync-ProjectAsync { $value = $itemStaged.$fieldId.Value $field = $itemStaged.$fieldId.Field + # Staged has the display value. Convert to the update value + $valueToSend = ConvertTo-FieldValue -Field $field -Value $value + $params = @{ Database = $db ItemId = $itemId @@ -64,7 +67,7 @@ function Sync-ProjectAsync { FieldName = $field.name FieldType = $field.type FieldDataType = $field.dataType - Value = $value + Value = $valueToSend } diff --git a/private/projectDatabase/project_database_Sync.ps1 b/private/projectDatabase/project_database_Sync.ps1 index 8c2cdef..38dba80 100644 --- a/private/projectDatabase/project_database_Sync.ps1 +++ b/private/projectDatabase/project_database_Sync.ps1 @@ -50,8 +50,8 @@ function Sync-Project{ # Staged has the display value. # Convert to the update value $value = $itemStaged.$fieldId.Value - $valueToSend = ConvertTo-FieldValue -Field $itemStaged.$fieldId.Field -Value $value $field = $itemStaged.$fieldId.Field + $valueToSend = ConvertTo-FieldValue -Field $field -Value $value $params = @{ Database = $db From c1712ff9de901ec039db04601e4ae05b27647f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 3 Oct 2025 08:32:43 +0200 Subject: [PATCH 13/14] refactor(debug): replace Write-Debug with Write-MyDebug for consistency --- include/MyWrite.ps1 | 2 +- private/invokeRestMethord.ps1 | 4 ++-- private/projectDatabase/project_database_Sync.ps1 | 2 +- private/projectDatabase/project_database_call.ps1 | 2 +- public/driver_gh.ps1 | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 index a551940..506fc3c 100644 --- a/include/MyWrite.ps1 +++ b/include/MyWrite.ps1 @@ -39,7 +39,7 @@ function Write-MyHost { Write-ToConsole $message -Color $OUTPUT_COLOR -NoNewLine:$NoNewLine } -function Write-Debug { +function Write-MyDebug { param( [Parameter(Position = 0)][string]$section, [Parameter(Position = 1, ValueFromPipeline)][string]$Message, diff --git a/private/invokeRestMethord.ps1 b/private/invokeRestMethord.ps1 index e1eed8e..d6ee4bb 100644 --- a/private/invokeRestMethord.ps1 +++ b/private/invokeRestMethord.ps1 @@ -20,9 +20,9 @@ function Invoke-RestMethod{ $params.OutFile = $OutFile } - ">> $Method $Uri" | Write-Debug -section "invokeRestMethod" + ">> $Method $Uri" | Write-MyDebug -section "invokeRestMethod" $result = Microsoft.PowerShell.Utility\Invoke-RestMethod @params - "<< $Method $Uri" | Write-Debug -section "invokeRestMethod" + "<< $Method $Uri" | Write-MyDebug -section "invokeRestMethod" return $result diff --git a/private/projectDatabase/project_database_Sync.ps1 b/private/projectDatabase/project_database_Sync.ps1 index 38dba80..4ee983f 100644 --- a/private/projectDatabase/project_database_Sync.ps1 +++ b/private/projectDatabase/project_database_Sync.ps1 @@ -69,7 +69,7 @@ function Sync-Project{ if ( ! (Test-UpdateProjectItemCall $call) ) { "FAILED !!" | Write-MyHost - Write-Debug -section "Sync-Project" -Message "Update-ProjectItem call failed" -Object $call + Write-MyDebug -section "Sync-Project" -Message "Update-ProjectItem call failed" -Object $call continue } diff --git a/private/projectDatabase/project_database_call.ps1 b/private/projectDatabase/project_database_call.ps1 index 711aa43..af2ebda 100644 --- a/private/projectDatabase/project_database_call.ps1 +++ b/private/projectDatabase/project_database_call.ps1 @@ -367,7 +367,7 @@ function Test-UpdateProjectItemCall { $ret = $null -ne $call.Result.data.$($call.ResultDataType) if (! $ret) { - "Update Project Item call Failed: $($call.Result.errors.message -join ', ')" | Write-Debug + "Update Project Item call Failed: $($call.Result.errors.message -join ', ')" | Write-MyDebug } return $ret diff --git a/public/driver_gh.ps1 b/public/driver_gh.ps1 index 469822a..7cd4d09 100644 --- a/public/driver_gh.ps1 +++ b/public/driver_gh.ps1 @@ -159,7 +159,7 @@ function Invoke-GitHubUpdateItemValues{ [string]$Type ) - "ProjectId: $ProjectId, ItemId: $ItemId, FieldId: $FieldId, Value: $Value, Type: $Type" | Write-Debug -section "driver_gh" + "ProjectId: $ProjectId, ItemId: $ItemId, FieldId: $FieldId, Value: $Value, Type: $Type" | Write-MyDebug -section "driver_gh" # Use the environmentraviable $token = Get-GithubToken From 88c1c2ebcb58ed5b9b6345ee6c15158bb1714af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 3 Oct 2025 08:54:56 +0200 Subject: [PATCH 14/14] feat(MyWrite): enhance Write-MyVerbose and Write-MyDebug for improved logging --- include/MyWrite.ps1 | 49 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 index 506fc3c..08b2b6b 100644 --- a/include/MyWrite.ps1 +++ b/include/MyWrite.ps1 @@ -1,3 +1,11 @@ +# Include MyWrite.ps1 +# Provides Write-MyError, Write-MyWarning, Write-MyVerbose, Write-MyHost, Write-MyDebug +# and Test-Verbose, Test-Debug functions for consistent logging and debugging output. +# Use env variables ModuleHelper_VERBOSE and ModuleHelper_DEBUG to control verbosity and debug output. +# Example: $env:ModuleHelper_DEBUG="all" or $env:ModuleHelper_DEBUG="Sync-Project" + +$ModuleRootPath = Get-ModuleRootPath -ModuleRootPath $ModuleRootPath +$MODULE_NAME = (Get-ChildItem -Path $ModuleRootPath -Filter *.psd1 | Select-Object -First 1).BaseName $ERROR_COLOR = "Red" $WARNING_COLOR = "Yellow" @@ -26,7 +34,9 @@ function Write-MyVerbose { [Parameter(ValueFromPipeline)][string]$Message ) - Write-ToConsole $message -Color $VERBOSE_COLOR + if (Test-Verbose) { + Write-ToConsole $message -Color $VERBOSE_COLOR + } } function Write-MyHost { @@ -46,16 +56,18 @@ function Write-MyDebug { [Parameter(Position = 2)][object]$Object ) - if (Test-Debug -section $section) { + process{ + if (Test-Debug -section $section) { - if ($Object) { - $objString = $Object | Get-ObjetString - $message = $message + " - " + $objString + if ($Object) { + $objString = $Object | Get-ObjetString + $message = $message + " - " + $objString + } + $timestamp = Get-Date -Format 'HH:mm:ss.fff' + "[$timestamp][D][$section] $message" | Write-ToConsole -Color $DEBUG_COLOR } - $timestamp = Get-Date -Format 'HH:mm:ss.fff' - "[$timestamp][D][$section] $message" | Write-ToConsole -Color $DEBUG_COLOR - } + } } function Write-ToConsole { @@ -68,12 +80,31 @@ function Write-ToConsole { Microsoft.PowerShell.Utility\Write-Host $message -ForegroundColor $Color -NoNewLine:$NoNewLine } + +function Test-Verbose { + param( + [Parameter(Position = 0)][string]$section + ) + + $moduleDebugVarName = $MODULE_NAME + "_VERBOSE" + $flag = [System.Environment]::GetEnvironmentVariable($moduleDebugVarName) + + # Enable debug + if ([string]::IsNullOrWhiteSpace( $flag )) { + return $false + } + + $trace = ($flag -like '*all*') -or ( $section -like "*$flag*") + return $trace +} + function Test-Debug { param( [Parameter(Position = 0)][string]$section ) - $flag = $env:ProjectHelper_DEBUG + $moduleDebugVarName = $MODULE_NAME + "_DEBUG" + $flag = [System.Environment]::GetEnvironmentVariable($moduleDebugVarName) # Enable debug if ([string]::IsNullOrWhiteSpace( $flag )) {