Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions Test/include/transcriptHelp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,31 @@
}

function Stop-MyTranscript {
Stop-Transcript

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$null = Stop-Transcript

$transcriptContent = Get-Content -Path $TEST_TRANSCRIPT_FILE
Remove-Item -Path $TEST_TRANSCRIPT_FILE
return $transcriptContent
}

$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]

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
return $retlist
}

2 changes: 1 addition & 1 deletion Test/private/MockCall_Project.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Test/private/MockCall_Project700.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions Test/public/items/project_item_show.test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function Test_Write_Sucess {

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Test_Write_Sucess' does not have a help comment. Note

The cmdlet 'Test_Write_Sucess' does not have a help comment.

Invoke-PrivateContext {
Start-Transcript -Path test.log

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
#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)"' }
)

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
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

}

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# 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]

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# Assert.
$assertLine = 0
foreach ($factor in $factors) {
Assert-AreEqual -Expected $factor.ExpectedText -Presented $result[$assertLine]

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$assertLine++
}
}
}

function Get-Test_Write_Sucess_Factors {

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Get-Test_Write_Sucess_Factors' does not have a help comment. Note

The cmdlet 'Get-Test_Write_Sucess_Factors' does not have a help comment.

Check warning

Code scanning / PSScriptAnalyzer

The cmdlet 'Get-Test_Write_Sucess_Factors' uses a plural noun. A singular noun should be used instead. Warning

The cmdlet 'Get-Test_Write_Sucess_Factors' uses a plural noun. A singular noun should be used instead.

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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion Test/public/project_items_staged.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@

Start-MyTranscript
$result = Sync-ProjectItemStagedAsync -Owner $Owner -ProjectNumber $ProjectNumber
$transcript = Stop-MyTranscript
$transcript = Stop-MyTranscript2

# Return true
Assert-IsTrue -Condition $result
Expand Down Expand Up @@ -1070,4 +1070,23 @@
$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 {

Check warning

Code scanning / PSScriptAnalyzer

Function 'Stop-MyTranscript2' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning

Function 'Stop-MyTranscript2' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.

$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
}
7 changes: 6 additions & 1 deletion include/MyWrite.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}


Expand Down
98 changes: 34 additions & 64 deletions public/driver_gh.ps1 → public/driver/driver_gh.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
}

# 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 = @{
Expand Down Expand Up @@ -102,8 +101,9 @@
}

# 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 = @{
Expand Down Expand Up @@ -168,8 +168,9 @@
}

# 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 = @{
Expand Down Expand Up @@ -241,8 +242,7 @@
}

# 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 = @{
Expand Down Expand Up @@ -306,8 +306,7 @@
}

# 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 = @{
Expand Down Expand Up @@ -339,56 +338,6 @@
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
Expand All @@ -410,8 +359,9 @@
}

# 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 = @{
Expand Down Expand Up @@ -469,8 +419,7 @@
}

# 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 = @{
Expand Down Expand Up @@ -527,3 +476,24 @@

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
}

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
4 changes: 1 addition & 3 deletions public/driver/issue/Invoke-AddComment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @{
Expand Down
4 changes: 1 addition & 3 deletions public/driver/issue/Invoke-FindProject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @{
Expand Down
6 changes: 3 additions & 3 deletions public/driver/issue/Invoke-GetItem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @{
Expand Down
4 changes: 1 addition & 3 deletions public/driver/issue/Invoke-UpdateDraftIssue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @{
Expand Down
4 changes: 1 addition & 3 deletions public/driver/issue/Invoke-UpdateIssue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @{
Expand Down
Loading