Skip to content

Commit ee32b9a

Browse files
authored
Merge pull request #153 from rulasg/Show-ProjectItem
feat(project_item): implement Show-ProjectItem function for enhanced item display
2 parents 4da2362 + 6d300e2 commit ee32b9a

24 files changed

Lines changed: 329 additions & 107 deletions

Test/include/transcriptHelp.ps1

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,31 @@ function Start-MyTranscript {
1717
}
1818

1919
function Stop-MyTranscript {
20-
Stop-Transcript
20+
21+
$null = Stop-Transcript
22+
2123
$transcriptContent = Get-Content -Path $TEST_TRANSCRIPT_FILE
2224
Remove-Item -Path $TEST_TRANSCRIPT_FILE
23-
return $transcriptContent
24-
}
25+
26+
$ret = Export-MyTranscript -transcriptContent $transcriptContent
27+
28+
return $ret
29+
}
30+
31+
function Export-MyTranscript {
32+
[CmdletBinding()]
33+
param (
34+
[Parameter(Mandatory, Position = 0)]
35+
[string[]]$transcriptContent
36+
)
37+
38+
$i = 0..($transcriptContent.Count - 1) | Where-Object { $transcriptContent[$_] -eq "**********************" }
39+
40+
$firstLine = $i[1] + 1
41+
$lastLine = $i[2] - 1
42+
43+
$retlist = $transcriptContent[$firstLine..$lastLine]
44+
45+
return $retlist
46+
}
47+

Test/private/MockCall_Project.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function Add-ItemsToMock {
228228

229229
# Items
230230
$project.items = @{}
231-
$project.items.totalCount = $pActual.items.totalcount
231+
$project.items.totalCount = $pActual.items.nodes.count
232232
$project.items.doneCount = 6 # too complicated to read from structure
233233

234234
# Issues to find

Test/private/MockCall_Project700.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function Get-Mock_Project_700 {
4444

4545
# Items
4646
$project.items = @{}
47-
$project.items.totalCount = $pActual.items.totalcount
47+
$project.items.totalCount = $pActual.items.nodes.count
4848
$project.items.doneCount = 6 # too complicated to read from structure
4949

5050
# Issues to find
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
function Test_Write_Sucess {
2+
3+
Invoke-PrivateContext {
4+
Start-Transcript -Path test.log
5+
6+
#Factors to test
7+
$factors = @(
8+
@{ Text = "Test with no other parameters"; ExpectedText = "Test with no other parameters" }
9+
@{ Color = "Red"; Text = "Red Text"; BetweenQuotes = $false; PreFix = ""; DefaultValue = "(defaultValue)" ; ExpectedText = "Red Text" }
10+
@{ Color = "Gray"; Text = "Gray Text"; BetweenQuotes = $false; DefaultValue = "(defaultValue)" ; ExpectedText = "Gray Text" }
11+
@{ Color = "Green"; Text = "Green Text"; BetweenQuotes = $true; PreFix = "Prefix: "; DefaultValue = "(defaultValue)" ; ExpectedText = 'Prefix: "Green Text"' }
12+
@{ Color = "Blue"; Text = ""; BetweenQuotes = $false; PreFix = "NoText: "; DefaultValue = "(defaultValue)" ; ExpectedText = "NoText: (defaultValue)" }
13+
@{ Color = "Yellow"; BetweenQuotes = $true; PreFix = "NullText: "; DefaultValue = "(defaultValue)" ; ExpectedText = 'NullText: "(defaultValue)"' }
14+
@{ Color = "Cyan"; Text = " "; BetweenQuotes = $false; PreFix = "WhiteSpace: "; ; ExpectedText = "WhiteSpace: (empty)" }
15+
@{ Color = "Cyan"; Text = " "; BetweenQuotes = $true; PreFix = "WhiteSpace2: "; ; ExpectedText = 'WhiteSpace2: "(empty)"' }
16+
)
17+
18+
foreach ($factor in $factors) {
19+
$color = $factor.Color
20+
$text = $factor.Text
21+
$BetweenQuotes = $factor.BetweenQuotes
22+
$PreFix = $factor.PreFix
23+
$DefaultValue = $factor.DefaultValue
24+
25+
# Act
26+
27+
# Capture the output
28+
# Call the write function with parameters
29+
write -color $color -text $text -BetweenQuotes:$BetweenQuotes -PreFix $PreFix -DefaultValue $DefaultValue
30+
31+
}
32+
33+
# Can not use MyTranscript as we are on a private context that does not hase access to Test private functions
34+
# Code loggic here to extract from transcript
35+
Stop-Transcript ;
36+
$transcriptContent = Get-Content -Path test.log
37+
$i = 0..($transcriptContent.Count - 1) | Where-Object { $transcriptContent[$_] -eq "**********************" }
38+
$firstLine = $i[1] + 1 ; $lastLine = $i[2] - 1
39+
$result = $transcriptContent[$firstLine..$lastLine]
40+
41+
# Assert.
42+
$assertLine = 0
43+
foreach ($factor in $factors) {
44+
Assert-AreEqual -Expected $factor.ExpectedText -Presented $result[$assertLine]
45+
$assertLine++
46+
}
47+
}
48+
}
49+
50+
function Get-Test_Write_Sucess_Factors {
51+
52+
return = @(
53+
@{ Text = "Test with no other parameters"; ExpectedText = "Test with no other parameters" }
54+
@{ Color = "Red"; Text = "Red Text"; BetweenQuotes = $false; PreFix = ""; DefaultValue = "(defaultValue)" ; ExpectedText = "Red Text" }
55+
@{ Color = "Gray"; Text = "Gray Text"; BetweenQuotes = $false; DefaultValue = "(defaultValue)" ; ExpectedText = "Gray Text" }
56+
@{ Color = "Green"; Text = "Green Text"; BetweenQuotes = $true; PreFix = "Prefix: "; DefaultValue = "(defaultValue)" ; ExpectedText = 'Prefix: "Green Text"' }
57+
@{ Color = "Blue"; Text = ""; BetweenQuotes = $false; PreFix = "NoText: "; DefaultValue = "(defaultValue)" ; ExpectedText = "NoText: (defaultValue)" }
58+
@{ Color = "Yellow"; BetweenQuotes = $true; PreFix = "NullText: "; DefaultValue = "(defaultValue)" ; ExpectedText = 'NullText: "(defaultValue)"' }
59+
@{ Color = "Cyan"; Text = " "; BetweenQuotes = $false; PreFix = "WhiteSpace: "; ; ExpectedText = "WhiteSpace: (empty)" }
60+
@{ Color = "Cyan"; Text = " "; BetweenQuotes = $true; PreFix = "WhiteSpace2: "; ; ExpectedText = 'WhiteSpace2: "(empty)"' }
61+
)
62+
} Export-ModuleMember -Function Get-Test_Write_Sucess_Factors, Test_Write_Sucess
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function Test_SearchProjectItem_SUCCESS_Title{
1313
# Act
1414
$result = Search-ProjectItem -Owner $owner -ProjectNumber $projectNumber -Filter $title
1515

16-
Assert-Count -Expected $p.searchInTitle.totalCount -Presented $result
16+
Assert-Count -Expected $p.searchInTitle.Titles.Count -Presented $result
1717

1818
$p.searchInTitle.Titles | ForEach-Object {
1919
Assert-Contains -Expected $_ -Presented $result.Title

Test/public/project_items_staged.test.ps1

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ function Test_Sync_ProjectDatabaseAsync_ClearValues{
979979

980980
Start-MyTranscript
981981
$result = Sync-ProjectItemStagedAsync -Owner $Owner -ProjectNumber $ProjectNumber
982-
$transcript = Stop-MyTranscript
982+
$transcript = Stop-MyTranscript2
983983

984984
# Return true
985985
Assert-IsTrue -Condition $result
@@ -1070,4 +1070,23 @@ function Test_Sync_ProjectDatabase_ClearValues{
10701070
$item1 = Get-ProjectItem -Owner $Owner -ProjectNumber $ProjectNumber -ItemId $itemId1
10711071
Assert-StringIsNullOrEmpty -Presented $item1.$fieldComment1
10721072
Assert-StringIsNullOrEmpty -Presented $item1.$fieldPriority1
1073+
}
1074+
1075+
# For some reason Stop-MyTranscript is failing calling Export-MyTranscript for one test.
1076+
# Merging both functions here to avoid the issue for this test.
1077+
function Stop-MyTranscript2 {
1078+
1079+
$null = Stop-Transcript
1080+
1081+
$transcriptContent = Get-Content -Path $TEST_TRANSCRIPT_FILE
1082+
Remove-Item -Path $TEST_TRANSCRIPT_FILE
1083+
1084+
$i = 0..($transcriptContent.Count - 1) | Where-Object { $transcriptContent[$_] -eq "**********************" }
1085+
1086+
$firstLine = $i[1] + 1
1087+
$lastLine = $i[2] - 1
1088+
1089+
$ret = $transcriptContent[$firstLine..$lastLine]
1090+
1091+
return $ret
10731092
}

include/MyWrite.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ function Write-ToConsole {
7777
[Parameter()][switch]$NoNewLine
7878

7979
)
80-
Microsoft.PowerShell.Utility\Write-Host $message -ForegroundColor $Color -NoNewLine:$NoNewLine
80+
if([string]::IsNullOrWhiteSpace($Color)){
81+
Microsoft.PowerShell.Utility\Write-Host $message -NoNewLine:$NoNewLine
82+
} else {
83+
Microsoft.PowerShell.Utility\Write-Host $message -ForegroundColor:$Color -NoNewLine:$NoNewLine
84+
}
85+
8186
}
8287

8388

Lines changed: 34 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ function Invoke-GitHubOrgProjectWithFields {
2929
}
3030

3131
# Define the GraphQL query with variables
32-
$qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "orgprojectwithfieldsAndItems.query"
33-
$query = get-content -path $qlPath | Out-String
32+
$query = Get-GraphQLString "orgprojectwithfieldsAndItems.query"
3433

3534
# Define the headers for the request
3635
$headers = @{
@@ -102,8 +101,9 @@ function InvokeGitHubOrgProject {
102101
}
103102

104103
# Define the GraphQL query with variables
105-
$qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath $QueryFileName
106-
$query = get-content -path $qlPath | Out-String
104+
$query = Get-GraphQLString $QueryFileName
105+
106+
107107

108108
# Define the headers for the request
109109
$headers = @{
@@ -168,8 +168,9 @@ function Invoke-GitHubUpdateItemValues{
168168
}
169169

170170
# Define the GraphQL query with variables
171-
$qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "updateItemValues.mutant"
172-
$mutation = get-content -path $qlPath | Out-String
171+
$mutation = Get-GraphQLString "updateItemValues.mutant"
172+
173+
173174

174175
# Define the headers for the request
175176
$headers = @{
@@ -241,8 +242,7 @@ function Invoke-GitHubClearItemValues{
241242
}
242243

243244
# Define the GraphQL query with variables
244-
$qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "clearItemValues.mutant"
245-
$mutation = get-content -path $qlPath | Out-String
245+
$mutation = Get-GraphQLString "clearItemValues.mutant"
246246

247247
# Define the headers for the request
248248
$headers = @{
@@ -306,8 +306,7 @@ function Invoke-GetIssueOrPullRequest{
306306
}
307307

308308
# Define the GraphQL query with variables
309-
$qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "getIssueOrPullRequest.query"
310-
$query = get-content -path $qlPath | Out-String
309+
$query = Get-GraphQLString "getIssueOrPullRequest.query"
311310

312311
# Define the headers for the request
313312
$headers = @{
@@ -339,56 +338,6 @@ function Invoke-GetIssueOrPullRequest{
339338
return $response
340339
} Export-ModuleMember -Function Invoke-GetIssueOrPullRequest
341340

342-
# function Invoke-GetIContentId {
343-
# param(
344-
# [Parameter(Mandatory)] [string] $Url
345-
# )
346-
347-
# # Use the environmentraviable
348-
# $token = Get-GithubToken
349-
# if(-not $token){
350-
# throw "GH Cli Auth Token not available. Run 'gh auth login' in your terminal."
351-
# }
352-
353-
# # Define the GraphQL query with variables
354-
# $qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "getContentId.query"
355-
# $query = get-content -path $qlPath | Out-String
356-
357-
# # Define the headers for the request
358-
# $headers = @{
359-
# "Authorization" = "Bearer $token"
360-
# "Content-Type" = "application/json"
361-
# }
362-
363-
# # get owner, reponame and issue number from the URL
364-
# $repoOwner, $repoName, [int] $issueNumber = Get-RepoOwnerNameNumberFromUrl -Url $Url
365-
366-
# # Define the variables for the request
367-
# $variables = @{
368-
# owner = $repoOwner
369-
# name = $repoName
370-
# number = $issueNumber
371-
# }
372-
373-
# # Define the body for the request
374-
# $body = @{
375-
# query = $query
376-
# variables = $variables
377-
# } | ConvertTo-Json
378-
379-
# # Send the request
380-
# $response = Invoke-RestMethod -Uri 'https://api.github.com/graphql' -Method Post -Body $body -Headers $headers
381-
382-
# # Check if here are errors
383-
# if($response.errors){
384-
# "[$($response.errors[0].type)] $($response.errors[0].message)" | Write-MyError
385-
# return
386-
# }
387-
388-
# # Return the field names
389-
# return $response
390-
# } Export-ModuleMember -Function Invoke-GetIContentId
391-
392341
<#
393342
.SYNOPSIS
394343
Adds an item to a GitHub project
@@ -410,8 +359,9 @@ function Invoke-AddItemToProject{
410359
}
411360

412361
# Define the GraphQL query with variables
413-
$qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "addItemToProject.mutant"
414-
$mutation = get-content -path $qlPath | Out-String
362+
$mutation = Get-GraphQLString "addItemToProject.mutant"
363+
364+
415365

416366
# Define the headers for the request
417367
$headers = @{
@@ -469,8 +419,7 @@ function Invoke-RemoveItemFromProject{
469419
}
470420

471421
# Define the GraphQL query with variables
472-
$qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "removeItemFromProject.mutant"
473-
$mutation = get-content -path $qlPath | Out-String
422+
$mutation = Get-GraphQLString "removeItemFromProject.mutant"
474423

475424
# Define the headers for the request
476425
$headers = @{
@@ -527,3 +476,24 @@ function Get-GithubToken{
527476

528477
return $token
529478
}
479+
480+
function Get-GraphQLString{
481+
param(
482+
[Parameter(Mandatory, Position = 0)] [string]$FileName
483+
)
484+
485+
Write-MyDebug -section "driver_gh" -message "Getting GraphQL string from file: $FileName"
486+
487+
$local = $PSScriptRoot
488+
$public = $local | Split-Path -Parent
489+
490+
$path = $public | Join-Path -ChildPath "graphql" -AdditionalChildPath $FileName
491+
492+
if(! (Test-Path -Path $path)){
493+
throw "GraphQL file not found at path: $path"
494+
}
495+
496+
$content = get-content -path $path | Out-String
497+
498+
return $content
499+
}

public/driver/issue/Invoke-AddComment.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ function Invoke-AddComment {
1212
}
1313

1414
# Define the GraphQL query with variables
15-
$moduleroot = $PSScriptRoot | Split-Path -Parent | Split-Path -Parent
16-
$qlPath = $moduleroot | Join-Path -ChildPath "graphql" -AdditionalChildPath "commentCreate.mutant"
17-
$query = get-content -path $qlPath | Out-String
15+
$query = Get-GraphQLString "commentCreate.mutant"
1816

1917
# Define the headers for the request
2018
$headers = @{

public/driver/issue/Invoke-FindProject.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ function Invoke-FindProject{
6060
}
6161

6262
# Define the GraphQL query with variables
63-
$public = $PSScriptRoot | Split-Path -Parent | Split-Path -Parent
64-
$qlPath = $public | Join-Path -ChildPath "graphql" -AdditionalChildPath "findProject.query"
65-
$mutation = get-content -path $qlPath | Out-String
63+
$mutation = Get-GraphQLString "findProject.query"
6664

6765
# Define the headers for the request
6866
$headers = @{

0 commit comments

Comments
 (0)