From acc3422d486eb72a13d5761a4f2c7fe9f2e98f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 10 Oct 2025 06:55:45 +0200 Subject: [PATCH 01/10] feat(project_item): implement Show-ProjectItem function for enhanced item display --- public/project_item.ps1 | 133 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/public/project_item.ps1 b/public/project_item.ps1 index 45a8eea..2b6f8a7 100644 --- a/public/project_item.ps1 +++ b/public/project_item.ps1 @@ -168,6 +168,139 @@ function Format-ProjectItem{ } } Export-ModuleMember -Function Format-ProjectItem +function Show-ProjectItem{ + [CmdletBinding()] + [Alias("shpi")] + param( + [Parameter(ValueFromPipeline)][string]$ItemId, + [Parameter()][array[]]$FieldsToShow + ) + + process { + + $item = Get-ProjectItem -ItemId $ItemId + + if($null -eq $item){ + "Item not found" | Write-MyError + return $null + } + + if(-not $FieldsToShow){ + $statusColor = getStatusColor($item.Status) + $FieldsToShow = @( + @(@{Name="Status"; Color = $statusColor}) + ) + } + + # Before all + addJumpLine + + # title bar + # ($item.RepositoryOwner + "/") | write -Color Cyan + # ($item.RepositoryName) | write -Color Cyan + $item.number | write -Color Cyan -PreFix "#" + addSpace + $item.Title | write -Color Yellow -BetweenQuotes + + addJumpLine + + # URL + $item.url | write -Color White + + # Fields by line + if($FieldsToShow){ + addJumpLine + foreach($line in $FieldsToShow){ + addJumpLine + ShowAttribLine -AttributesToShow $line -Item $item + } + } + + addJumpLine + + # Body + addJumpLine ; "--- Body ---" | write Cyan ; addJumpLine + $item.body | write -Color Gray + + # End of item + addJumpLine ; "------------" | write Cyan ; addJumpLine + + # ID at the end + $item.id | write -Color DarkGray + } +} Export-ModuleMember -Function Show-ProjectItem -Alias("shpi") + +function getStatusColor{ + param( + [string]$status + ) + + switch ($status.ToLower()) { + "Todo" { return "Green" } + "Done" { return "DarkMagenta" } + "In Progress" { return "Yellow" } + default { return "Gray" } + } +} + +function write{ + param( + [Parameter(Position = 1)][string]$color, + [Parameter(Position = 2,ValueFromPipeline)][string]$text, + [Parameter()][switch]$BetweenQuotes, + [Parameter()][string]$PreFix, + [Parameter()][string]$DefaultValue = "(empty)" + + ) + process{ + + if([string]::IsNullOrWhiteSpace($text)){ + $text = $DefaultValue + } + + if($BetweenQuotes){ + $text = """$text""" + } + + if($PreFix){ + $text = $PreFix + $text + } + + + $text | Write-ToConsole -Color $color -NoNewLine + } +} +function addJumpLine{ + Write-ToConsole -Color White +} +function addSpace{ + " " | Write-ToConsole -Color Cyan -NoNewline +} +function ShowAttribLine{ + param( + [array]$AttributesToShow, + [object]$item + ) + + $isfirst = $true + + $AttributesToShow | ForEach-Object { + $name = $_.Name + $color = $_.Color + $prefix = $_.Prefix + $BetweenQuotes = $_.BetweenQuotes + + $value = $item.$name + + if(!$isfirst){ + " | " | write Gray + } else { + $isfirst = $false + } + + $value | write $color -PreFix $prefix -BetweenQuotes:$BetweenQuotes -DefaultValue "<$name>" + } +} function Get-ProjectItems { [CmdletBinding()] From 5be78bbecdfd70df2c3b533ba0b973dbda620176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 10 Oct 2025 09:17:58 +0200 Subject: [PATCH 02/10] refactor(all): Refactor filders and files location --- public/{ => driver}/driver_gh.ps1 | 0 public/{ => environment}/environmentCache.ps1 | 0 public/{ => fields}/project_fields_list.ps1 | 0 public/invokedummyfunction.ps1 | 15 --------- public/{ => items}/item_framework.ps1 | 0 public/{ => items}/project_item.ps1 | 0 public/{ => items}/project_item_List.ps1 | 0 public/{ => items}/project_item_staged.ps1 | 0 public/items/use_order.ps1 | 32 +++++++++++++++++++ public/{ => prompt}/getPrompt.ps1 | 0 10 files changed, 32 insertions(+), 15 deletions(-) rename public/{ => driver}/driver_gh.ps1 (100%) rename public/{ => environment}/environmentCache.ps1 (100%) rename public/{ => fields}/project_fields_list.ps1 (100%) delete mode 100644 public/invokedummyfunction.ps1 rename public/{ => items}/item_framework.ps1 (100%) rename public/{ => items}/project_item.ps1 (100%) rename public/{ => items}/project_item_List.ps1 (100%) rename public/{ => items}/project_item_staged.ps1 (100%) create mode 100644 public/items/use_order.ps1 rename public/{ => prompt}/getPrompt.ps1 (100%) diff --git a/public/driver_gh.ps1 b/public/driver/driver_gh.ps1 similarity index 100% rename from public/driver_gh.ps1 rename to public/driver/driver_gh.ps1 diff --git a/public/environmentCache.ps1 b/public/environment/environmentCache.ps1 similarity index 100% rename from public/environmentCache.ps1 rename to public/environment/environmentCache.ps1 diff --git a/public/project_fields_list.ps1 b/public/fields/project_fields_list.ps1 similarity index 100% rename from public/project_fields_list.ps1 rename to public/fields/project_fields_list.ps1 diff --git a/public/invokedummyfunction.ps1 b/public/invokedummyfunction.ps1 deleted file mode 100644 index 3f80cf3..0000000 --- a/public/invokedummyfunction.ps1 +++ /dev/null @@ -1,15 +0,0 @@ -# Set-MyInvokeCommandAlias -Alias HELLO_WORLD -Command 'echo "Hello World"' - -# <# -# .SYNOPSIS -# Get Hello World message -# #> -# function Get-HelloWorld{ -# [CmdletBinding()] -# param( -# ) - -# $result = Invoke-MyCommand -Command HELLO_WORLD -# return $result - -# } Export-ModuleMember -Function Get-HelloWorld diff --git a/public/item_framework.ps1 b/public/items/item_framework.ps1 similarity index 100% rename from public/item_framework.ps1 rename to public/items/item_framework.ps1 diff --git a/public/project_item.ps1 b/public/items/project_item.ps1 similarity index 100% rename from public/project_item.ps1 rename to public/items/project_item.ps1 diff --git a/public/project_item_List.ps1 b/public/items/project_item_List.ps1 similarity index 100% rename from public/project_item_List.ps1 rename to public/items/project_item_List.ps1 diff --git a/public/project_item_staged.ps1 b/public/items/project_item_staged.ps1 similarity index 100% rename from public/project_item_staged.ps1 rename to public/items/project_item_staged.ps1 diff --git a/public/items/use_order.ps1 b/public/items/use_order.ps1 new file mode 100644 index 0000000..2840d77 --- /dev/null +++ b/public/items/use_order.ps1 @@ -0,0 +1,32 @@ +function Use-Order { + [cmdletbinding()] + [Alias("uo")] + param( + [Parameter(Position = 0)][int]$Ordinal = -1, + [Parameter(ValueFromPipeline)][array]$List + ) + + begin { + $finallist = @() + } + process { + + foreach ($item in $List) { + if ($null -eq $i) { $i = 0 } + $item | Add-Member -NotePropertyName "#" -NotePropertyValue $i -Force + $i++ + } + + $finalList += $List + } + + end { + if ($Ordinal -gt -1) { + $itemId = $finallist[$Ordinal].id + Show-SalesProjectItem -Item $itemId + } + else { + return $finalList + } + } +} Export-ModuleMember -Function Use-Order -Alias "uo" \ No newline at end of file diff --git a/public/getPrompt.ps1 b/public/prompt/getPrompt.ps1 similarity index 100% rename from public/getPrompt.ps1 rename to public/prompt/getPrompt.ps1 From 35ffbc3d7d5b77777026fdc58f222c1bef6eb302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 10 Oct 2025 18:21:28 +0200 Subject: [PATCH 03/10] refactor(issue): streamline GraphQL query retrieval in issue functions --- public/driver/driver_gh.ps1 | 98 +++++++------------ public/driver/issue/Invoke-AddComment.ps1 | 4 +- public/driver/issue/Invoke-FindProject.ps1 | 4 +- public/driver/issue/Invoke-GetItem.ps1 | 6 +- .../driver/issue/Invoke-UpdateDraftIssue.ps1 | 4 +- public/driver/issue/Invoke-UpdateIssue.ps1 | 4 +- .../driver/issue/Invoke-UpdatePullRequest.ps1 | 4 +- 7 files changed, 42 insertions(+), 82 deletions(-) diff --git a/public/driver/driver_gh.ps1 b/public/driver/driver_gh.ps1 index 7cd4d09..7c37678 100644 --- a/public/driver/driver_gh.ps1 +++ b/public/driver/driver_gh.ps1 @@ -29,8 +29,7 @@ function Invoke-GitHubOrgProjectWithFields { } # Define the GraphQL query with variables - $qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "orgprojectwithfieldsAndItems.query" - $query = get-content -path $qlPath | Out-String + $query = Get-GraphQLString "orgprojectwithfieldsAndItems.query" # Define the headers for the request $headers = @{ @@ -102,8 +101,9 @@ function InvokeGitHubOrgProject { } # Define the GraphQL query with variables - $qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath $QueryFileName - $query = get-content -path $qlPath | Out-String + $query = Get-GraphQLString $QueryFileName + + # Define the headers for the request $headers = @{ @@ -168,8 +168,9 @@ function Invoke-GitHubUpdateItemValues{ } # Define the GraphQL query with variables - $qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "updateItemValues.mutant" - $mutation = get-content -path $qlPath | Out-String + $mutation = Get-GraphQLString "updateItemValues.mutant" + + # Define the headers for the request $headers = @{ @@ -241,8 +242,7 @@ function Invoke-GitHubClearItemValues{ } # Define the GraphQL query with variables - $qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "clearItemValues.mutant" - $mutation = get-content -path $qlPath | Out-String + $mutation = Get-GraphQLString "clearItemValues.mutant" # Define the headers for the request $headers = @{ @@ -306,8 +306,7 @@ function Invoke-GetIssueOrPullRequest{ } # Define the GraphQL query with variables - $qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "getIssueOrPullRequest.query" - $query = get-content -path $qlPath | Out-String + $query = Get-GraphQLString "getIssueOrPullRequest.query" # Define the headers for the request $headers = @{ @@ -339,56 +338,6 @@ function Invoke-GetIssueOrPullRequest{ return $response } Export-ModuleMember -Function Invoke-GetIssueOrPullRequest -# function Invoke-GetIContentId { -# param( -# [Parameter(Mandatory)] [string] $Url -# ) - -# # Use the environmentraviable -# $token = Get-GithubToken -# if(-not $token){ -# throw "GH Cli Auth Token not available. Run 'gh auth login' in your terminal." -# } - -# # Define the GraphQL query with variables -# $qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "getContentId.query" -# $query = get-content -path $qlPath | Out-String - -# # Define the headers for the request -# $headers = @{ -# "Authorization" = "Bearer $token" -# "Content-Type" = "application/json" -# } - -# # get owner, reponame and issue number from the URL -# $repoOwner, $repoName, [int] $issueNumber = Get-RepoOwnerNameNumberFromUrl -Url $Url - -# # Define the variables for the request -# $variables = @{ -# owner = $repoOwner -# name = $repoName -# number = $issueNumber -# } - -# # Define the body for the request -# $body = @{ -# query = $query -# variables = $variables -# } | ConvertTo-Json - -# # Send the request -# $response = Invoke-RestMethod -Uri 'https://api.github.com/graphql' -Method Post -Body $body -Headers $headers - -# # Check if here are errors -# if($response.errors){ -# "[$($response.errors[0].type)] $($response.errors[0].message)" | Write-MyError -# return -# } - -# # Return the field names -# return $response -# } Export-ModuleMember -Function Invoke-GetIContentId - <# .SYNOPSIS Adds an item to a GitHub project @@ -410,8 +359,9 @@ function Invoke-AddItemToProject{ } # Define the GraphQL query with variables - $qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "addItemToProject.mutant" - $mutation = get-content -path $qlPath | Out-String + $mutation = Get-GraphQLString "addItemToProject.mutant" + + # Define the headers for the request $headers = @{ @@ -469,8 +419,7 @@ function Invoke-RemoveItemFromProject{ } # Define the GraphQL query with variables - $qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "removeItemFromProject.mutant" - $mutation = get-content -path $qlPath | Out-String + $mutation = Get-GraphQLString "removeItemFromProject.mutant" # Define the headers for the request $headers = @{ @@ -527,3 +476,24 @@ function Get-GithubToken{ return $token } + +function Get-GraphQLString{ + param( + [Parameter(Mandatory, Position = 0)] [string]$FileName + ) + + Write-MyDebug -section "driver_gh" -message "Getting GraphQL string from file: $FileName" + + $local = $PSScriptRoot + $public = $local | Split-Path -Parent + + $path = $public | Join-Path -ChildPath "graphql" -AdditionalChildPath $FileName + + if(! (Test-Path -Path $path)){ + throw "GraphQL file not found at path: $path" + } + + $content = get-content -path $path | Out-String + + return $content +} \ No newline at end of file diff --git a/public/driver/issue/Invoke-AddComment.ps1 b/public/driver/issue/Invoke-AddComment.ps1 index b12b28b..158a8fc 100644 --- a/public/driver/issue/Invoke-AddComment.ps1 +++ b/public/driver/issue/Invoke-AddComment.ps1 @@ -12,9 +12,7 @@ function Invoke-AddComment { } # Define the GraphQL query with variables - $moduleroot = $PSScriptRoot | Split-Path -Parent | Split-Path -Parent - $qlPath = $moduleroot | Join-Path -ChildPath "graphql" -AdditionalChildPath "commentCreate.mutant" - $query = get-content -path $qlPath | Out-String + $query = Get-GraphQLString "commentCreate.mutant" # Define the headers for the request $headers = @{ diff --git a/public/driver/issue/Invoke-FindProject.ps1 b/public/driver/issue/Invoke-FindProject.ps1 index 48ab3f3..f55eabf 100644 --- a/public/driver/issue/Invoke-FindProject.ps1 +++ b/public/driver/issue/Invoke-FindProject.ps1 @@ -60,9 +60,7 @@ function Invoke-FindProject{ } # Define the GraphQL query with variables - $public = $PSScriptRoot | Split-Path -Parent | Split-Path -Parent - $qlPath = $public | Join-Path -ChildPath "graphql" -AdditionalChildPath "findProject.query" - $mutation = get-content -path $qlPath | Out-String + $mutation = Get-GraphQLString "findProject.query" # Define the headers for the request $headers = @{ diff --git a/public/driver/issue/Invoke-GetItem.ps1 b/public/driver/issue/Invoke-GetItem.ps1 index cdaf74f..a16127d 100644 --- a/public/driver/issue/Invoke-GetItem.ps1 +++ b/public/driver/issue/Invoke-GetItem.ps1 @@ -11,9 +11,9 @@ function Invoke-GetItem { } # Define the GraphQL query with variables - $moduleroot = $PSScriptRoot | Split-Path -Parent | Split-Path -Parent - $qlPath = $moduleroot | Join-Path -ChildPath "graphql" -AdditionalChildPath "getProjectV2Item.query" - $query = get-content -path $qlPath | Out-String + + $query = Get-GraphQLString "getProjectV2Item.query" + # Define the headers for the request $headers = @{ diff --git a/public/driver/issue/Invoke-UpdateDraftIssue.ps1 b/public/driver/issue/Invoke-UpdateDraftIssue.ps1 index 002d03d..9b0c77e 100644 --- a/public/driver/issue/Invoke-UpdateDraftIssue.ps1 +++ b/public/driver/issue/Invoke-UpdateDraftIssue.ps1 @@ -14,9 +14,7 @@ function Invoke-UpdateDraftIssue{ } # Define the GraphQL query with variables - $public = $PSScriptRoot | Split-Path -Parent | Split-Path -Parent - $qlPath = $public | Join-Path -ChildPath "graphql" -AdditionalChildPath "updateDraftIssue.mutant" - $mutation = get-content -path $qlPath | Out-String + $mutation = Get-GraphQLString "updateDraftIssue.mutant" # Define the headers for the request $headers = @{ diff --git a/public/driver/issue/Invoke-UpdateIssue.ps1 b/public/driver/issue/Invoke-UpdateIssue.ps1 index dffc2ef..86dda09 100644 --- a/public/driver/issue/Invoke-UpdateIssue.ps1 +++ b/public/driver/issue/Invoke-UpdateIssue.ps1 @@ -29,9 +29,7 @@ function Invoke-UpdateIssue{ } # Define the GraphQL query with variables - $public = $PSScriptRoot | Split-Path -Parent | Split-Path -Parent - $qlPath = $public | Join-Path -ChildPath "graphql" -AdditionalChildPath "updateIssue.mutant" - $mutation = get-content -path $qlPath | Out-String + $mutation = Get-GraphQLString "updateIssue.mutant" # Define the headers for the request $headers = @{ diff --git a/public/driver/issue/Invoke-UpdatePullRequest.ps1 b/public/driver/issue/Invoke-UpdatePullRequest.ps1 index 98cf31d..0f37318 100644 --- a/public/driver/issue/Invoke-UpdatePullRequest.ps1 +++ b/public/driver/issue/Invoke-UpdatePullRequest.ps1 @@ -14,9 +14,7 @@ function Invoke-UpdatePullRequest{ } # Define the GraphQL query with variables - $public = $PSScriptRoot | Split-Path -Parent | Split-Path -Parent - $qlPath = $public | Join-Path -ChildPath "graphql" -AdditionalChildPath "updatePullRequest.mutant" - $mutation = get-content -path $qlPath | Out-String + $mutation = Get-GraphQLString "updatePullRequest.mutant" # Define the headers for the request $headers = @{ From 19935cc49cdcb798ee5f95b32944f3b75d8a6d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Sun, 12 Oct 2025 09:13:04 +0200 Subject: [PATCH 04/10] fix(mock): update totalCount calculation to use nodes.count --- Test/private/MockCall_Project.ps1 | 2 +- Test/private/MockCall_Project700.ps1 | 2 +- Test/public/items/project_item_show.test.ps1 | 62 +++++++++ public/items/project_item_show.ps1 | 137 +++++++++++++++++++ 4 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 Test/public/items/project_item_show.test.ps1 create mode 100644 public/items/project_item_show.ps1 diff --git a/Test/private/MockCall_Project.ps1 b/Test/private/MockCall_Project.ps1 index 467a6e5..9ce4b6c 100644 --- a/Test/private/MockCall_Project.ps1 +++ b/Test/private/MockCall_Project.ps1 @@ -228,7 +228,7 @@ function Add-ItemsToMock { # Items $project.items = @{} - $project.items.totalCount = $pActual.items.totalcount + $project.items.totalCount = $pActual.items.nodes.count $project.items.doneCount = 6 # too complicated to read from structure # Issues to find diff --git a/Test/private/MockCall_Project700.ps1 b/Test/private/MockCall_Project700.ps1 index f37e07e..5699c4a 100644 --- a/Test/private/MockCall_Project700.ps1 +++ b/Test/private/MockCall_Project700.ps1 @@ -44,7 +44,7 @@ function Get-Mock_Project_700 { # Items $project.items = @{} - $project.items.totalCount = $pActual.items.totalcount + $project.items.totalCount = $pActual.items.nodes.count $project.items.doneCount = 6 # too complicated to read from structure # Issues to find diff --git a/Test/public/items/project_item_show.test.ps1 b/Test/public/items/project_item_show.test.ps1 new file mode 100644 index 0000000..3780ab1 --- /dev/null +++ b/Test/public/items/project_item_show.test.ps1 @@ -0,0 +1,62 @@ +function Test_Write_Sucess { + + Invoke-PrivateContext { + Start-Transcript -Path test.log + + #Factors to test + $factors = @( + @{ Text = "Test with no other parameters"; ExpectedText = "Test with no other parameters" } + @{ Color = "Red"; Text = "Red Text"; BetweenQuotes = $false; PreFix = ""; DefaultValue = "(defaultValue)" ; ExpectedText = "Red Text" } + @{ Color = "Gray"; Text = "Gray Text"; BetweenQuotes = $false; DefaultValue = "(defaultValue)" ; ExpectedText = "Gray Text" } + @{ Color = "Green"; Text = "Green Text"; BetweenQuotes = $true; PreFix = "Prefix: "; DefaultValue = "(defaultValue)" ; ExpectedText = 'Prefix: "Green Text"' } + @{ Color = "Blue"; Text = ""; BetweenQuotes = $false; PreFix = "NoText: "; DefaultValue = "(defaultValue)" ; ExpectedText = "NoText: (defaultValue)" } + @{ Color = "Yellow"; BetweenQuotes = $true; PreFix = "NullText: "; DefaultValue = "(defaultValue)" ; ExpectedText = 'NullText: "(defaultValue)"' } + @{ Color = "Cyan"; Text = " "; BetweenQuotes = $false; PreFix = "WhiteSpace: "; ; ExpectedText = "WhiteSpace: (empty)" } + @{ Color = "Cyan"; Text = " "; BetweenQuotes = $true; PreFix = "WhiteSpace2: "; ; ExpectedText = 'WhiteSpace2: "(empty)"' } + ) + + foreach ($factor in $factors) { + $color = $factor.Color + $text = $factor.Text + $BetweenQuotes = $factor.BetweenQuotes + $PreFix = $factor.PreFix + $DefaultValue = $factor.DefaultValue + + # Act + + # Capture the output + # Call the write function with parameters + write -color $color -text $text -BetweenQuotes:$BetweenQuotes -PreFix $PreFix -DefaultValue $DefaultValue + + } + + # Can not use MyTranscript as we are on a private context that does not hase access to Test private functions + # Code loggic here to extract from transcript + Stop-Transcript ; + $transcriptContent = Get-Content -Path test.log + $i = 0..($transcriptContent.Count - 1) | Where-Object { $transcriptContent[$_] -eq "**********************" } + $firstLine = $i[1] + 1 ; $lastLine = $i[2] - 1 + $result = $transcriptContent[$firstLine..$lastLine] + + # Assert. + $assertLine = 0 + foreach ($factor in $factors) { + Assert-AreEqual -Expected $factor.ExpectedText -Presented $result[$assertLine] + $assertLine++ + } + } +} + +function Get-Test_Write_Sucess_Factors { + + return = @( + @{ Text = "Test with no other parameters"; ExpectedText = "Test with no other parameters" } + @{ Color = "Red"; Text = "Red Text"; BetweenQuotes = $false; PreFix = ""; DefaultValue = "(defaultValue)" ; ExpectedText = "Red Text" } + @{ Color = "Gray"; Text = "Gray Text"; BetweenQuotes = $false; DefaultValue = "(defaultValue)" ; ExpectedText = "Gray Text" } + @{ Color = "Green"; Text = "Green Text"; BetweenQuotes = $true; PreFix = "Prefix: "; DefaultValue = "(defaultValue)" ; ExpectedText = 'Prefix: "Green Text"' } + @{ Color = "Blue"; Text = ""; BetweenQuotes = $false; PreFix = "NoText: "; DefaultValue = "(defaultValue)" ; ExpectedText = "NoText: (defaultValue)" } + @{ Color = "Yellow"; BetweenQuotes = $true; PreFix = "NullText: "; DefaultValue = "(defaultValue)" ; ExpectedText = 'NullText: "(defaultValue)"' } + @{ Color = "Cyan"; Text = " "; BetweenQuotes = $false; PreFix = "WhiteSpace: "; ; ExpectedText = "WhiteSpace: (empty)" } + @{ Color = "Cyan"; Text = " "; BetweenQuotes = $true; PreFix = "WhiteSpace2: "; ; ExpectedText = 'WhiteSpace2: "(empty)"' } + ) +} Export-ModuleMember -Function Get-Test_Write_Sucess_Factors, Test_Write_Sucess \ No newline at end of file diff --git a/public/items/project_item_show.ps1 b/public/items/project_item_show.ps1 new file mode 100644 index 0000000..7f417e2 --- /dev/null +++ b/public/items/project_item_show.ps1 @@ -0,0 +1,137 @@ +function Show-ProjectItem{ + [CmdletBinding()] + [Alias("shpi")] + param( + [Parameter(ValueFromPipeline)][string]$ItemId, + [Parameter()][array[]]$FieldsToShow + ) + + process { + + $item = Get-ProjectItem -ItemId $ItemId + + if($null -eq $item){ + "Item not found" | Write-MyError + return $null + } + + if(-not $FieldsToShow){ + $statusColor = getStatusColor($item.Status) + $FieldsToShow = @( + @(@{Name="Status"; Color = $statusColor}) + ) + } + + # Before all + addJumpLine + + # title bar + # ($item.RepositoryOwner + "/") | write -Color Cyan + # ($item.RepositoryName) | write -Color Cyan + $item.number | write -Color Cyan -PreFix "#" + addSpace + $item.Title | write -Color Yellow -BetweenQuotes + + addJumpLine + + # URL + $item.url | write -Color White + + # Fields by line + if($FieldsToShow){ + addJumpLine + foreach($line in $FieldsToShow){ + addJumpLine + ShowAttribLine -AttributesToShow $line -Item $item + } + } + + addJumpLine + + # Body + addJumpLine ; "--- Body ---" | write Cyan ; addJumpLine + $item.body | write -Color Gray + + # End of item + addJumpLine ; "------------" | write Cyan ; addJumpLine + + # ID at the end + $item.id | write -Color DarkGray + } +} Export-ModuleMember -Function Show-ProjectItem -Alias("shpi") + +function getStatusColor{ + param( + [string]$status + ) + + switch ($status.ToLower()) { + "Todo" { return "Green" } + "Done" { return "DarkMagenta" } + "In Progress" { return "Yellow" } + default { return "Gray" } + } +} + +function write{ + param( + [Parameter(Position = 1)][string]$color, + [Parameter(Position = 2,ValueFromPipeline)][string]$text, + [Parameter()][switch]$BetweenQuotes, + [Parameter()][string]$PreFix, + [Parameter()][string]$DefaultValue + + ) + process{ + + if([string]::IsNullOrWhiteSpace($text)){ + + if([string]::IsNullOrWhiteSpace($DefaultValue)){ + $DefaultValue = "(empty)" + } + $text = $DefaultValue + } + + if($BetweenQuotes){ + $text = """$text""" + } + + if($PreFix){ + $text = $PreFix + $text + } + + + $text | Write-ToConsole -Color:$color -NoNewLine + } +} +function addJumpLine{ + Write-ToConsole -Color White +} +function addSpace{ + " " | Write-ToConsole -Color Cyan -NoNewline +} +function ShowAttribLine{ + param( + [array]$AttributesToShow, + [object]$item + ) + + $isfirst = $true + + $AttributesToShow | ForEach-Object { + $name = $_.Name + $color = $_.Color + $prefix = $_.Prefix + $BetweenQuotes = $_.BetweenQuotes + + $value = $item.$name + + if(!$isfirst){ + " | " | write Gray + } else { + $isfirst = $false + } + + $value | write $color -PreFix $prefix -BetweenQuotes:$BetweenQuotes -DefaultValue "<$name>" + } +} \ No newline at end of file From 138615dbe7f0f2ebb183ef0c1c406d76b1481ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Sun, 12 Oct 2025 09:15:10 +0200 Subject: [PATCH 05/10] fix(project_item): typo on file name Search-ProjectItem function --- ...roject_item_search.test.pd1 => project_item_search.test.ps1} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Test/public/{project_item_search.test.pd1 => project_item_search.test.ps1} (95%) diff --git a/Test/public/project_item_search.test.pd1 b/Test/public/project_item_search.test.ps1 similarity index 95% rename from Test/public/project_item_search.test.pd1 rename to Test/public/project_item_search.test.ps1 index 1d3989e..d56a181 100644 --- a/Test/public/project_item_search.test.pd1 +++ b/Test/public/project_item_search.test.ps1 @@ -13,7 +13,7 @@ function Test_SearchProjectItem_SUCCESS_Title{ # Act $result = Search-ProjectItem -Owner $owner -ProjectNumber $projectNumber -Filter $title - Assert-Count -Expected $p.searchInTitle.totalCount -Presented $result + Assert-Count -Expected $p.searchInTitle.Titles.Count -Presented $result $p.searchInTitle.Titles | ForEach-Object { Assert-Contains -Expected $_ -Presented $result.Title From e96cf9d51363357ce4d79a8c59cdebdbc3b1c9ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Sun, 12 Oct 2025 09:15:58 +0200 Subject: [PATCH 06/10] refactor(project_item): remove Show-ProjectItem function and related utilities --- public/items/project_item.ps1 | 134 ---------------------------------- 1 file changed, 134 deletions(-) diff --git a/public/items/project_item.ps1 b/public/items/project_item.ps1 index 2b6f8a7..4aef279 100644 --- a/public/items/project_item.ps1 +++ b/public/items/project_item.ps1 @@ -168,140 +168,6 @@ function Format-ProjectItem{ } } Export-ModuleMember -Function Format-ProjectItem -function Show-ProjectItem{ - [CmdletBinding()] - [Alias("shpi")] - param( - [Parameter(ValueFromPipeline)][string]$ItemId, - [Parameter()][array[]]$FieldsToShow - ) - - process { - - $item = Get-ProjectItem -ItemId $ItemId - - if($null -eq $item){ - "Item not found" | Write-MyError - return $null - } - - if(-not $FieldsToShow){ - $statusColor = getStatusColor($item.Status) - $FieldsToShow = @( - @(@{Name="Status"; Color = $statusColor}) - ) - } - - # Before all - addJumpLine - - # title bar - # ($item.RepositoryOwner + "/") | write -Color Cyan - # ($item.RepositoryName) | write -Color Cyan - $item.number | write -Color Cyan -PreFix "#" - addSpace - $item.Title | write -Color Yellow -BetweenQuotes - - addJumpLine - - # URL - $item.url | write -Color White - - # Fields by line - if($FieldsToShow){ - addJumpLine - foreach($line in $FieldsToShow){ - addJumpLine - ShowAttribLine -AttributesToShow $line -Item $item - } - } - - addJumpLine - - # Body - addJumpLine ; "--- Body ---" | write Cyan ; addJumpLine - $item.body | write -Color Gray - - # End of item - addJumpLine ; "------------" | write Cyan ; addJumpLine - - # ID at the end - $item.id | write -Color DarkGray - } -} Export-ModuleMember -Function Show-ProjectItem -Alias("shpi") - -function getStatusColor{ - param( - [string]$status - ) - - switch ($status.ToLower()) { - "Todo" { return "Green" } - "Done" { return "DarkMagenta" } - "In Progress" { return "Yellow" } - default { return "Gray" } - } -} - -function write{ - param( - [Parameter(Position = 1)][string]$color, - [Parameter(Position = 2,ValueFromPipeline)][string]$text, - [Parameter()][switch]$BetweenQuotes, - [Parameter()][string]$PreFix, - [Parameter()][string]$DefaultValue = "(empty)" - - ) - process{ - - if([string]::IsNullOrWhiteSpace($text)){ - $text = $DefaultValue - } - - if($BetweenQuotes){ - $text = """$text""" - } - - if($PreFix){ - $text = $PreFix + $text - } - - - $text | Write-ToConsole -Color $color -NoNewLine - } -} -function addJumpLine{ - Write-ToConsole -Color White -} -function addSpace{ - " " | Write-ToConsole -Color Cyan -NoNewline -} -function ShowAttribLine{ - param( - [array]$AttributesToShow, - [object]$item - ) - - $isfirst = $true - - $AttributesToShow | ForEach-Object { - $name = $_.Name - $color = $_.Color - $prefix = $_.Prefix - $BetweenQuotes = $_.BetweenQuotes - - $value = $item.$name - - if(!$isfirst){ - " | " | write Gray - } else { - $isfirst = $false - } - - $value | write $color -PreFix $prefix -BetweenQuotes:$BetweenQuotes -DefaultValue "<$name>" - } -} - function Get-ProjectItems { [CmdletBinding()] param( From eccf02096d94420958a45647e67d24fc6180fa06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Sun, 12 Oct 2025 10:14:11 +0200 Subject: [PATCH 07/10] fix(Write-ToConsole): handle empty color parameter in Write-ToConsole function --- include/MyWrite.ps1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 index 08b2b6b..f249230 100644 --- a/include/MyWrite.ps1 +++ b/include/MyWrite.ps1 @@ -77,7 +77,12 @@ function Write-ToConsole { [Parameter()][switch]$NoNewLine ) - Microsoft.PowerShell.Utility\Write-Host $message -ForegroundColor $Color -NoNewLine:$NoNewLine + if([string]::IsNullOrWhiteSpace($Color)){ + Microsoft.PowerShell.Utility\Write-Host $message -NoNewLine:$NoNewLine + } else { + Microsoft.PowerShell.Utility\Write-Host $message -ForegroundColor:$Color -NoNewLine:$NoNewLine + } + } From 81531260668a037d144bee93e543497b5c64abc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Sun, 12 Oct 2025 10:14:24 +0200 Subject: [PATCH 08/10] fix(Write-HostPrompt): specify Write-Host from Microsoft.PowerShell.Utility --- public/prompt/getPrompt.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/prompt/getPrompt.ps1 b/public/prompt/getPrompt.ps1 index cd8adc6..b889fec 100644 --- a/public/prompt/getPrompt.ps1 +++ b/public/prompt/getPrompt.ps1 @@ -131,7 +131,7 @@ function Write-HostPrompt { } # Default color to White if not specified - Write-Host @params + Microsoft.PowerShell.Utility\Write-Host @params } } Export-ModuleMember -Function Write-HostPrompt From 68dc1fe874f8e162b69eb195df03d1d5e348001a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Sun, 12 Oct 2025 10:14:54 +0200 Subject: [PATCH 09/10] fix(transcript): ensure Stop-MyTranscript returns transcript content correctly --- Test/include/transcriptHelp.ps1 | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Test/include/transcriptHelp.ps1 b/Test/include/transcriptHelp.ps1 index 2dd2dc5..d835116 100644 --- a/Test/include/transcriptHelp.ps1 +++ b/Test/include/transcriptHelp.ps1 @@ -17,8 +17,31 @@ function Start-MyTranscript { } function Stop-MyTranscript { - Stop-Transcript + + $null = Stop-Transcript + $transcriptContent = Get-Content -Path $TEST_TRANSCRIPT_FILE Remove-Item -Path $TEST_TRANSCRIPT_FILE - return $transcriptContent -} \ No newline at end of file + + $ret = Export-MyTranscript -transcriptContent $transcriptContent + + return $ret +} + +function Export-MyTranscript { + [CmdletBinding()] + param ( + [Parameter(Mandatory, Position = 0)] + [string[]]$transcriptContent + ) + + $i = 0..($transcriptContent.Count - 1) | Where-Object { $transcriptContent[$_] -eq "**********************" } + + $firstLine = $i[1] + 1 + $lastLine = $i[2] - 1 + + $retlist = $transcriptContent[$firstLine..$lastLine] + + return $retlist +} + From 6d300e20e9e75145f9b3f05dbb9b392fa84fea1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Sun, 12 Oct 2025 10:15:05 +0200 Subject: [PATCH 10/10] fix(test): replace Stop-MyTranscript with Stop-MyTranscript2 to resolve transcript export issue --- Test/public/project_items_staged.test.ps1 | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Test/public/project_items_staged.test.ps1 b/Test/public/project_items_staged.test.ps1 index 61601ac..f030702 100644 --- a/Test/public/project_items_staged.test.ps1 +++ b/Test/public/project_items_staged.test.ps1 @@ -979,7 +979,7 @@ function Test_Sync_ProjectDatabaseAsync_ClearValues{ Start-MyTranscript $result = Sync-ProjectItemStagedAsync -Owner $Owner -ProjectNumber $ProjectNumber - $transcript = Stop-MyTranscript + $transcript = Stop-MyTranscript2 # Return true Assert-IsTrue -Condition $result @@ -1070,4 +1070,23 @@ function Test_Sync_ProjectDatabase_ClearValues{ $item1 = Get-ProjectItem -Owner $Owner -ProjectNumber $ProjectNumber -ItemId $itemId1 Assert-StringIsNullOrEmpty -Presented $item1.$fieldComment1 Assert-StringIsNullOrEmpty -Presented $item1.$fieldPriority1 +} + +# For some reason Stop-MyTranscript is failing calling Export-MyTranscript for one test. +# Merging both functions here to avoid the issue for this test. +function Stop-MyTranscript2 { + + $null = Stop-Transcript + + $transcriptContent = Get-Content -Path $TEST_TRANSCRIPT_FILE + Remove-Item -Path $TEST_TRANSCRIPT_FILE + + $i = 0..($transcriptContent.Count - 1) | Where-Object { $transcriptContent[$_] -eq "**********************" } + + $firstLine = $i[1] + 1 + $lastLine = $i[2] - 1 + + $ret = $transcriptContent[$firstLine..$lastLine] + + return $ret } \ No newline at end of file