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
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
24 changes: 16 additions & 8 deletions Test/public/project_item.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,21 @@

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

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
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{
Expand All @@ -279,16 +287,16 @@
$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++) {
Expand Down
2 changes: 0 additions & 2 deletions helper/invokeCommand.helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
96 changes: 77 additions & 19 deletions include/MyWrite.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# 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"
$VERBOSE_COLOR = "DarkYellow"
$OUTPUT_COLOR = "DarkCyan"
$DEBUG_COLOR = "DarkGray"

Expand All @@ -24,7 +33,10 @@
param(
[Parameter(ValueFromPipeline)][string]$Message
)
Write-Verbose -Message $message

if (Test-Verbose) {
Write-ToConsole $message -Color $VERBOSE_COLOR
}
}

function Write-MyHost {
Expand All @@ -37,33 +49,25 @@
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,
[Parameter(Position = 2)][object]$Object
)

$flag = $env:ProjectHelper_DEBUG
process{

# Enable debug
if ([string]::IsNullOrWhiteSpace( $flag )) {
return
}
if (Test-Debug -section $section) {

$trace = ($flag -like '*all*') -or ( $section -like "*$flag*")

# Write-Host $message -ForegroundColor $DEBUG_COLOR
if ($trace) {

if ($Object) {
$objJson = $Object | ConvertTo-Json -Depth 10 -ErrorAction SilentlyContinue
$message = $message + " - " + $objJson
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
}

$message = "[DEBUG][$section] " + $message
Write-ToConsole $message -Color $DEBUG_COLOR
}
}
}

function Write-ToConsole {
Expand All @@ -74,4 +78,58 @@

)
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
)

$moduleDebugVarName = $MODULE_NAME + "_DEBUG"
$flag = [System.Environment]::GetEnvironmentVariable($moduleDebugVarName)

# 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"
}

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
if ($Object -is [string]) {
return $Object
}

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
return $Object | ConvertTo-Json -Depth 10 -ErrorAction SilentlyContinue
}
}
3 changes: 3 additions & 0 deletions private/invokeRestMethord.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
$params.OutFile = $OutFile
}

">> $Method $Uri" | Write-MyDebug -section "invokeRestMethod"

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$result = Microsoft.PowerShell.Utility\Invoke-RestMethod @params
"<< $Method $Uri" | Write-MyDebug -section "invokeRestMethod"

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace


return $result
}
5 changes: 4 additions & 1 deletion private/projectDatabase/project_database_Async.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,17 @@ 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
FieldId = $fieldId
FieldName = $field.name
FieldType = $field.type
FieldDataType = $field.dataType
Value = $value
Value = $valueToSend
}


Expand Down
4 changes: 2 additions & 2 deletions private/projectDatabase/project_database_Sync.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion private/projectDatabase/project_database_call.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions public/driver_gh.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ function Invoke-GitHubUpdateItemValues{
[string]$Type
)

"ProjectId: $ProjectId, ItemId: $ItemId, FieldId: $FieldId, Value: $Value, Type: $Type" | Write-MyDebug -section "driver_gh"

# Use the environmentraviable
$token = Get-GithubToken
if(-not $token){
Expand Down
6 changes: 3 additions & 3 deletions public/environmentCache.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
function Set-ProjectHelperEnvironment{
[CmdletBinding()]
param(
[Parameter()][string]$Owner,
[Parameter()][string]$ProjectNumber,
[Parameter()][string[]]$DisplayFields
[Parameter(ValueFromPipelineByPropertyName)][string]$Owner,

Check warning

Code scanning / PSScriptAnalyzer

Command accepts pipeline input but has not defined a process block. Warning

Command accepts pipeline input but has not defined a process block.
[Parameter(ValueFromPipelineByPropertyName)][string]$ProjectNumber,

Check warning

Code scanning / PSScriptAnalyzer

Command accepts pipeline input but has not defined a process block. Warning

Command accepts pipeline input but has not defined a process block.
[Parameter(ValueFromPipelineByPropertyName)][string[]]$DisplayFields

Check warning

Code scanning / PSScriptAnalyzer

Command accepts pipeline input but has not defined a process block. Warning

Command accepts pipeline input but has not defined a process block.
)

if(! [string]::IsNullOrWhiteSpace($Owner)) {
Expand Down
10 changes: 9 additions & 1 deletion public/graphql/findProject.query
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions public/project/findproject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading