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
113 changes: 76 additions & 37 deletions include/MyWrite.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,20 @@
[Parameter()][string]$ForegroundColor = $OUTPUT_COLOR,
[Parameter()][switch]$NoNewLine
)

Write-MyDebug -Section "MyHost" -Message $Message

# Write-Host $message -ForegroundColor $OUTPUT_COLOR
Write-ToConsole $message -Color $ForegroundColor -NoNewLine:$NoNewLine
}

function Clear-MyHost {
[CmdletBinding()]
param()

Clear-Host
}

function Write-MyDebug {
[CmdletBinding()]
[Alias("Write-Debug")]
Expand All @@ -77,7 +87,7 @@
$timestamp = Get-Date -Format 'HH:mm:ss.fff'

# Write on host
$logMessage ="[$timestamp][D][$section] $message"
$logMessage ="[$timestamp][$MODULE_NAME][D][$section] $message"

$logMessage | Write-ToConsole -Color $DEBUG_COLOR
$logMessage | Write-MyDebugLogging
Expand All @@ -92,8 +102,7 @@

process{

$moduleDebugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH"
$loggingFilePath = [System.Environment]::GetEnvironmentVariable($moduleDebugLoggingVarName)
$loggingFilePath = get-DebugLogFile

# Check if logging is enabled
if ([string]::IsNullOrWhiteSpace( $loggingFilePath )) {
Expand Down Expand Up @@ -134,8 +143,7 @@
[Parameter(Position = 0)][string]$section
)

$moduleDebugVarName = $MODULE_NAME + "_VERBOSE"
$flag = [System.Environment]::GetEnvironmentVariable($moduleDebugVarName)
$flag = get-VerboseSections

if ([string]::IsNullOrWhiteSpace( $flag )) {
return $false
Expand All @@ -156,17 +164,15 @@
$flag = $section
}

$moduleDebugVarName = $MODULE_NAME + "_VERBOSE"
[System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $flag)
set-VerboseSections $flag
}
Copy-Item -path Function:Enable-ModuleNameVerbose -Destination Function:"Enable-$($MODULE_NAME)Verbose"
Export-ModuleMember -Function "Enable-$($MODULE_NAME)Verbose"

function Disable-ModuleNameVerbose{
param()

$moduleDebugVarName = $MODULE_NAME + "_VERBOSE"
[System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $null)
set-VerboseSections $null
}
Copy-Item -path Function:Disable-ModuleNameVerbose -Destination Function:"Disable-$($MODULE_NAME)Verbose"
Export-ModuleMember -Function "Disable-$($MODULE_NAME)Verbose"
Expand All @@ -184,19 +190,19 @@
$flags = $flags.ToLower()
$section = $section.ToLower()

return ($flags.Contains("all")) -or ( $flags.Contains($section))
return ($flags.Contains("all")) -or ( $flags -eq $section)
}

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

$sectionsString = get-DebugSections

# No configuration means no debug
if([string]::IsNullOrWhiteSpace( $flagsString )) {
if([string]::IsNullOrWhiteSpace( $sectionsString )) {
return $false
}

# Get flags from flagdsString
$flags = getFlagsFromSectionsString $flagsString
# Get flags from sectionsString
$flags = getSectionsFromSectionsString $sectionsString

# Add all if allow is empty.
# This mean stat flagsString only contains filters.
Expand Down Expand Up @@ -228,57 +234,54 @@
}
}

$flagsString = $sections -join " "
$sectionsString = $sections -join " "
$addedFlagsString = $AddSections -join " "

# if no section get value from env and is still mepty set to all
if([string]::IsNullOrWhiteSpace( $flagsString )) {
$flagsString = get-Sections
if( [string]::IsNullOrWhiteSpace( $flagsString )) {
$flagsString = "all"
if([string]::IsNullOrWhiteSpace( $sectionsString )) {
$sectionsString = get-DebugSections
if( [string]::IsNullOrWhiteSpace( $sectionsString )) {
$sectionsString = "all"
}
}

# Add added to flagsString if provided
# Add added to sectionsString if provided
if(-Not [string]::IsNullOrWhiteSpace( $addedFlagsString )) {
$flagsString += " " + $addedFlagsString
$sectionsString += " " + $addedFlagsString
}

set-Sections $flagsString
set-DebugSections $sectionsString

}
Copy-Item -path Function:Enable-ModuleNameDebug -Destination Function:"Enable-$($MODULE_NAME)Debug"
Export-ModuleMember -Function "Enable-$($MODULE_NAME)Debug"

function getFlagsFromSectionsString($sectionsString){
$flags = @{
function getSectionsFromSectionsString($sectionsString){
$sections = @{
allow = $null
filter = $null
}

if([string]::IsNullOrWhiteSpace($sectionsString) ){
$flags.allow = @("all")
return $flags
$sections.allow = @("all")
return $sections
}

$list = $sectionsString.Split(" ", [StringSplitOptions]::RemoveEmptyEntries)

$split = @($list).Where({ $_ -like '-*' }, 'Split')

$flags.filter = $split[0] | ForEach-Object { $_ -replace '^-', '' } # -> API, Auth
$flags.allow = $split[1] # -> Sync, Cache
$sections.filter = $split[0] | ForEach-Object { $_ -replace '^-', '' } # -> API, Auth
$sections.allow = $split[1] # -> Sync, Cache

return $flags
return $sections
}

function Disable-ModuleNameDebug {
param()

$moduleDebugVarName = $MODULE_NAME + "_DEBUG"
[System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $null)

$moduleDEbugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH"
[System.Environment]::SetEnvironmentVariable($moduleDEbugLoggingVarName, $null)
set-DebugSections $null
set-LogFile $null
}
Copy-Item -path Function:Disable-ModuleNameDebug -Destination Function:"Disable-$($MODULE_NAME)Debug"
Export-ModuleMember -Function "Disable-$($MODULE_NAME)Debug"
Expand All @@ -288,8 +291,8 @@
param()

return @{
Sections = get-Sections
LoggingFilePath = get-LogFile
Sections = get-DebugSections
LoggingFilePath = get-DebugLogFile
}
}
Copy-Item -path Function:Get-ModuleNameDebug -Destination Function:"Get-$($MODULE_NAME)Debug"
Expand Down Expand Up @@ -337,3 +340,39 @@
$moduleDEbugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH"
[System.Environment]::SetEnvironmentVariable($moduleDEbugLoggingVarName, $logFilePath)
}

function get-DebugSections(){

Check warning

Code scanning / PSScriptAnalyzer

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

The cmdlet 'get-DebugSections' uses a plural noun. A singular noun should be used instead.
$moduleDebugVarName = $MODULE_NAME + "_DEBUG"
$sections = [System.Environment]::GetEnvironmentVariable($moduleDebugVarName)

return $sections
}

function set-DebugSections($sections){

Check warning

Code scanning / PSScriptAnalyzer

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

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

Check warning

Code scanning / PSScriptAnalyzer

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

The cmdlet 'set-DebugSections' uses a plural noun. A singular noun should be used instead.
$moduleDebugVarName = $MODULE_NAME + "_DEBUG"
[System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $sections)
}

function get-DebugLogFile(){
$moduleDEbugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH"
$logfile = [System.Environment]::GetEnvironmentVariable($moduleDEbugLoggingVarName)

return $logfile
}

function set-LogFile($logFilePath){

Check warning

Code scanning / PSScriptAnalyzer

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

Function 'set-LogFile' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
$moduleDEbugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH"
[System.Environment]::SetEnvironmentVariable($moduleDEbugLoggingVarName, $logFilePath)
}

function get-VerboseSections{

Check warning

Code scanning / PSScriptAnalyzer

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

The cmdlet 'get-VerboseSections' uses a plural noun. A singular noun should be used instead.
$moduleVerboseVarName = $MODULE_NAME + "_VERBOSE"
$sections = [System.Environment]::GetEnvironmentVariable($moduleVerboseVarName)

return $sections
}

function set-VerboseSections($sections){

Check warning

Code scanning / PSScriptAnalyzer

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

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

Check warning

Code scanning / PSScriptAnalyzer

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

The cmdlet 'set-VerboseSections' uses a plural noun. A singular noun should be used instead.
$moduleVerboseVarName = $MODULE_NAME + "_VERBOSE"
[System.Environment]::SetEnvironmentVariable($moduleVerboseVarName, $sections)
}
18 changes: 16 additions & 2 deletions private/projectDatabase/project_database.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ function Test-ProjectDatabase{
[Parameter(Position = 1)][int]$ProjectNumber
)

"Testing project database for $Owner/$ProjectNumber >>>" | Write-MyDebug -Section "ProjectDatabase"

$key,$keyLock = Get-ProjectDatabaseKey -Owner $Owner -ProjectNumber $ProjectNumber

$ret = Test-Database -Key $key

"Testing project database for $Owner/$ProjectNumber <<< $ret" | Write-MyDebug -Section "ProjectDatabase"

return $ret
}

Expand Down Expand Up @@ -46,12 +50,16 @@ function Get-ProjectFromDatabase{
)

$key,$keyLock = Get-ProjectDatabaseKey -Owner $Owner -ProjectNumber $ProjectNumber

"Getting project for $Owner/$ProjectNumber" | Write-MyDebug -Section "ProjectDatabase"

$prj = getProjectDatabaseCache -KeyLock $keyLock

if($null -ne $prj){
"Project cache hit for $Owner/$ProjectNumber" | Write-MyDebug -Section "ProjectDatabase"
"🟩 Get Project Database from MEMORY $Owner/$ProjectNumber" | Write-MyDebug -Section "ProjectDatabase"
return $prj
} else {
"🟧 Get Project Database from FILE $Owner/$ProjectNumber" | Write-MyDebug -Section "ProjectDatabase"
}

# No cache or cache mismatch, read from database
Expand All @@ -65,6 +73,9 @@ function Get-ProjectFromDatabase{
$prj.items = $prj.items | Copy-MyHashTable
$prj.Staged = $prj.Staged | Copy-MyHashTable

# Savige to cache for future calls
setProjectDatabaseCache -KeyLock $keyLock -SafeId $prj.safeId -Database $prj

return $prj
}

Expand Down Expand Up @@ -161,6 +172,9 @@ function Save-ProjectDatabase{
# Add safe mark
$Database.safeId = [guid]::NewGuid().ToString()

# Trace
"🟥 Save Project Database from FILE $Owner/$ProjectNumber safeId [$($Database.safeId)]" | Write-MyDebug -Section "ProjectDatabase"

# Save database
Save-Database -Key $dbkey -Database $Database
setProjectDatabaseCache -KeyLock $dbkeyLock -SafeId $Database.safeId -Database $Database
Expand Down Expand Up @@ -231,7 +245,7 @@ function resetProjectDatabaseCache{

"Resetting project cache for $KeyLock" | Write-MyDebug -Section "ProjectDatabase"

Reset.Database -Key $KeyLock
Reset-Database -Key $KeyLock

$script:ProjectDatabaseCache.Remove($KeyLock)
}
3 changes: 2 additions & 1 deletion public/issues/Add-ProjectSubIssue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
[CmdletBinding()]
[Alias("New-Issue")]
param (
[Parameter(Mandatory, Position = 0)][string]$ItemId,
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName, Position = 0)][Alias("Id")][string]$ItemId,

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.

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(Position = 1)][string]$RepoOwner,
[Parameter(Position = 2)][string]$RepoName,
[Parameter(Mandatory, Position = 3)][string]$Title,
Expand Down
4 changes: 2 additions & 2 deletions public/items/project_item.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ function Search-ProjectItem {
$Attributes = @("id") + $Attributes
}


($owner,$ProjectNumber) = Resolve-ProjectParameters -Owner $Owner -ProjectNumber $ProjectNumber
# Resolve project parameters
($owner,$ProjectNumber) = Resolve-ProjectParameters -Owner $Owner -ProjectNumber $ProjectNumber

# Get items as hashtable for later queries
$items = Get-ProjectItems -Owner $Owner -ProjectNumber $ProjectNumber -Force:$Force -IncludeDone:$IncludeDone -AsHashtable
Expand Down
29 changes: 16 additions & 13 deletions public/items/use_order.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[Parameter()][Alias("w")][switch]$OpenInBrowser,
[Parameter()][Alias("p")][switch]$PassThru,
[Parameter()][Alias("c")][switch]$ClearScreen,
[Parameter()][Alias("d")][switch]$DontShow,
[Parameter()][scriptblock]$ShowProjectItemScriptBlock
)

Expand Down Expand Up @@ -54,24 +55,26 @@
throw "ProjectEnvironment is required. Run Set-ProjectHelperEnvironment"
}

#return item
if( -not $DontShow){
# Get function to show item
$ShowProjectItemScriptBlock = $ShowProjectItemScriptBlock ?? { param($parameters) Show-ProjectItem @parameters }

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# Show item in console or editor
$params = @{
Item = $itemId
OpenInEditor = $OpenInEditor
OpenInBrowser = $OpenInBrowser
ClearScreen = $ClearScreen
}
$ShowProjectItemScriptBlock.Invoke($params)
}

#return item
if($PassThru) {
$i = Get-ProjectItem -ItemId $itemId
return [PsCustomObject]$i
}

# Get function to show item
$ShowProjectItemScriptBlock = $ShowProjectItemScriptBlock ?? { param($parameters) Show-ProjectItem @parameters }

# Show item in console or editor
$params = @{
Item = $itemId
OpenInEditor = $OpenInEditor
OpenInBrowser = $OpenInBrowser
ClearScreen = $ClearScreen
}
$ShowProjectItemScriptBlock.Invoke($params)
return

}
} Export-ModuleMember -Function Use-Order -Alias "uo"
8 changes: 6 additions & 2 deletions public/project/getproject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ function Get-Project {

($Owner, $ProjectNumber) = Resolve-ProjectParameters -Owner $Owner -ProjectNumber $ProjectNumber

"Getting project for $Owner/$ProjectNumber with SkipItems=$SkipItems and Force=$Force >>>" | Write-MyDebug -Section "Get-Project"

if ($Force -or -Not (Test-ProjectDatabase -Owner $Owner -ProjectNumber $ProjectNumber)) {
"Project not found in database or force specified. Updating project for $Owner/$ProjectNumber." | Write-MyDebug -Section Get-Project

$result = Update-Project -Owner $Owner -ProjectNumber $ProjectNumber -SkipItems:$SkipItems -Force:$Force

if ( ! $result) {
"Failed to update project for $Owner/$ProjectNumber. Project may not exist or there was an error during update." | Write-MyError
return
return
}
} else {
"Project found in database for $Owner/$ProjectNumber. Loading project." | Write-MyDebug -Section Get-Project
"Project found in database for $Owner/$ProjectNumber. Calling to retreive." | Write-MyDebug -Section Get-Project
}

$prj = Get-ProjectFromDatabase -Owner $Owner -ProjectNumber $ProjectNumber

"Getting project for $Owner/$ProjectNumber with SkipItems=$SkipItems and Force=$Force <<< $($prj.safeId)" | Write-MyDebug -Section "Get-Project"

return $prj
} Export-ModuleMember -Function Get-Project

Expand Down
Loading