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
4 changes: 2 additions & 2 deletions Test/public/addIncludeToWorkspace.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ function Test_AddIncludeToWorkspace_IfExists{
Assert-Count -Expected 1 -Presented $filesDest1
$contentFile1 = Get-Content -Path $filesDest1.FullName | Out-String
$sourceFile1 = Get-Content -Path $include1.Path | Out-String
Assert-AreEqual -Expected $sourceFile1 -Presented $contentFile1
Assert-AreEqual -Expected $sourceFile1.Trim() -Presented $contentFile1.Trim()

$filesDest2 = Get-ChildItem -Path $destFolder2
Assert-Count -Expected 1 -Presented $filesDest2
$contentFile2 = Get-Content -Path $filesDest2.FullName | Out-String
$sourceFile2 = Get-Content -Path $include2.Path | Out-String
Assert-AreEqual -Expected $sourceFile2 -Presented $contentFile2
Assert-AreEqual -Expected $sourceFile2.Trim() -Presented $contentFile2.Trim()
}

function Test_AddIncludeToWorkspace_PipeParameters{
Expand Down
5 changes: 3 additions & 2 deletions helper/invokeCommand.helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Invoke-MyCommand{
[Parameter(Position=1)][hashtable]$Parameters
)

Write-MyDebug "[invoke] $Command" $Parameters
Write-MyDebug "invoke" $Command $Parameters

return InvokeHelper\Invoke-MyCommand -Command $Command -Parameters $Parameters
}
Expand All @@ -46,4 +46,5 @@ function Reset-MyInvokeCommandAlias{
}

# Reset all aliases for this module on each refresh
Reset-MyInvokeCommandAlias
Reset-MyInvokeCommandAlias

28 changes: 17 additions & 11 deletions include/MyWrite.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function Test-MyVerbose {
return $trace
}

function Set-ModuleNameVerbose{
function Enable-ModuleNameVerbose{
param(
[Parameter(Position = 0)][string]$section
)
Expand All @@ -126,36 +126,40 @@ function Set-ModuleNameVerbose{
$moduleDebugVarName = $MODULE_NAME + "_VERBOSE"
[System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $flag)
}
Rename-Item -path Function:Set-ModuleNameVerbose -NewName "Set-$($MODULE_NAME)Verbose"
Rename-Item -path Function:Enable-ModuleNameVerbose -NewName "Set-$($MODULE_NAME)Verbose"
Export-ModuleMember -Function "Set-$($MODULE_NAME)Verbose"

function Clear-ModuleNameVerbose{
function Disable-ModuleNameVerbose{
param()

$moduleDebugVarName = $MODULE_NAME + "_VERBOSE"
[System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $null)
}
Rename-Item -path Function:Clear-ModuleNameVerbose -NewName "Clear-$($MODULE_NAME)Verbose"
Rename-Item -path Function:Disable-ModuleNameVerbose -NewName "Clear-$($MODULE_NAME)Verbose"
Export-ModuleMember -Function "Clear-$($MODULE_NAME)Verbose"

function Test-MyDebug {
param(
[Parameter(Position = 0)][string]$section
)

# Get the module debug environment variable
$moduleDebugVarName = $MODULE_NAME + "_DEBUG"
$flag = [System.Environment]::GetEnvironmentVariable($moduleDebugVarName)

# Enable debug
# check if debugging is enabled
if ([string]::IsNullOrWhiteSpace( $flag )) {
return $false
}

$flag = $flag.ToLower()
$section = $section.ToLower()

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

function Set-ModuleNameDebug{
function Enable-ModuleNameDebug{
param(
[Parameter(Position = 0)][string]$section
)
Expand All @@ -169,17 +173,17 @@ function Set-ModuleNameDebug{
$moduleDebugVarName = $MODULE_NAME + "_DEBUG"
[System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $flag)
}
Rename-Item -path Function:Set-ModuleNameDebug -NewName "Set-$($MODULE_NAME)Debug"
Export-ModuleMember -Function "Set-$($MODULE_NAME)Debug"
Rename-Item -path Function:Enable-ModuleNameDebug -NewName "Enable-$($MODULE_NAME)Debug"
Export-ModuleMember -Function "Enable-$($MODULE_NAME)Debug"

function Clear-ModuleNameDebug{
function Disable-ModuleNameDebug {
param()

$moduleDebugVarName = $MODULE_NAME + "_DEBUG"
[System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $null)
}
Rename-Item -path Function:Clear-ModuleNameDebug -NewName "Clear-$($MODULE_NAME)Debug"
Export-ModuleMember -Function "Clear-$($MODULE_NAME)Debug"
Rename-Item -path Function:Disable-ModuleNameDebug -NewName "Disable-$($MODULE_NAME)Debug"
Export-ModuleMember -Function "Disable-$($MODULE_NAME)Debug"

function Get-ObjetString {
param(
Expand All @@ -201,3 +205,5 @@ function Get-ObjetString {
}




80 changes: 51 additions & 29 deletions include/callAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Invoke-GraphQL {
[Parameter()] [string]$OutFile
)

">>>" | Write-MyVerbose
">>>" | writedebug

$ApiHost = Get-ApiHost -ApiHost:$ApiHost
$token = Get-ApiToken -Token:$Token -ApiHost:$ApiHost
Expand All @@ -35,21 +35,21 @@ function Invoke-GraphQL {
} | ConvertTo-Json -Depth 100

# Trace request
"[[QUERY]]" | Write-MyVerbose
$Query | Write-MyVerbose
"[[QUERY]]" | writedebug
$Query | writedebug

"[[VARIABLES]]" | Write-MyVerbose
$Variables | ConvertTo-Json -Depth 100 | Write-MyVerbose
"[[VARIABLES]]" | writedebug
$Variables | ConvertTo-Json -Depth 100 | writedebug

# Send the request
$start = Get-Date
">>> Invoke-RestMethod - $apiUri" | Write-MyVerbose
">>> Invoke-RestMethod - $apiUri" | writedebug
$response = Invoke-RestMethod -Uri $apiUri -Method Post -Body $body -Headers $headers -OutFile $OutFile
"<<< Invoke-RestMethod - $apiUri [ $(((Get-Date) - $start).TotalSeconds) seconds]" | Write-MyVerbose
"<<< Invoke-RestMethod - $apiUri [ $(((Get-Date) - $start).TotalSeconds) seconds]" | writedebug

# Trace response
"[[RESPONSE]]" | Write-MyVerbose
$response | ConvertTo-Json -Depth 100 | Write-MyVerbose
"[[RESPONSE]]" | writedebug
$response | ConvertTo-Json -Depth 100 | writedebug

if($response.errors){
throw "GraphQL query return errors - Error: $($response.errors.message)"
Expand All @@ -71,7 +71,7 @@ function Invoke-RestAPI {
[Parameter()] [string]$PageSize = 30
)

">>>" | Write-MyVerbose
">>>" | writedebug

$ApiHost = Get-ApiHost -ApiHost "$ApiHost"
$token = Get-ApiToken -ApiHost "$ApiHost"
Expand All @@ -95,10 +95,10 @@ function Invoke-RestAPI {

# Send the request
$start = Get-Date
">>> Invoke-RestMethod - $url" | Write-MyVerbose
">>> Invoke-RestMethod - $url" | writedebug
$response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers -ResponseHeadersVariable responseHeaders

$responseHeaders | Write-MyVerbose
$responseHeaders | writedebug

# Process paging
if($responseHeaders.link){$paging=$true}
Expand All @@ -111,7 +111,7 @@ function Invoke-RestAPI {

if($nextUrl){
$nextUrl = $matches[1]
">>> Invoke-RestMethod - $nextUrl" | Write-MyVerbose
">>> Invoke-RestMethod - $nextUrl" | writedebug
$nextResponse = Invoke-RestMethod -Uri $nextUrl -Method Get -Headers $headers -ResponseHeadersVariable responseHeaders
$response += $nextResponse
$paging = $null -ne $responseHeaders.link
Expand All @@ -120,11 +120,11 @@ function Invoke-RestAPI {
}
}

"<<< Invoke-RestMethod - $url [ $(((Get-Date) - $start).TotalSeconds) seconds]" | Write-MyVerbose
"<<< Invoke-RestMethod - $url [ $(((Get-Date) - $start).TotalSeconds) seconds]" | writedebug

# Trace response
"[[RESPONSE]]" | Write-MyVerbose
$response | ConvertTo-Json -Depth 100 | Write-MyVerbose
"[[RESPONSE]]" | writedebug
$response | ConvertTo-Json -Depth 100 | writedebug


return $response
Expand All @@ -146,23 +146,20 @@ function Get-ApiHost {
)

if(![string]::IsNullOrWhiteSpace($ApiHost)){
"ApiHost provided" | Write-MyVerbose
"ApiHost provided" | writedebug
return $ApiHost
}

$envValue = Get-ApiHostFromEnv
$envValue = Get-EnvVariable -Name $ENV_VAR_HOST_NAME
if(![string]::IsNullOrWhiteSpace($envValue)){
"Host from env $envValue" | Write-MyVerbose
"Host from env $envValue" | writedebug
return $envValue
}

"Default host $DEFAULT_GH_HOST" | Write-MyVerbose
"Default host $DEFAULT_GH_HOST" | writedebug
return $DEFAULT_GH_HOST
} Export-ModuleMember -Function Get-ApiHost

function Get-ApiHostFromEnv{
(Get-Item -path "Env:$ENV_VAR_HOST_NAME" -ErrorAction SilentlyContinue).Value
}

####################################################################################################

Expand All @@ -183,17 +180,17 @@ function Get-ApiToken {
return $Token
}

$envValue = Get-TokenFromEnv
$envValue = Get-EnvVariable -Name $ENV_VAR_TOKEN_NAME
if(![string]::IsNullOrWhiteSpace($envValue)){
"Token from env" | Write-MyVerbose
"Token from env" | writedebug
return $envValue
}

$params = @{
host = $ApiHost
}

"Token from GetToken for host [$ApiHost]" | Write-MyVerbose
"Token from GetToken for host [$ApiHost]" | writedebug
$result = Invoke-MyCommand -Command "GetToken" -Parameters $params

if(-Not $result){
Expand All @@ -203,6 +200,31 @@ function Get-ApiToken {
return $result
} Export-ModuleMember -Function Get-ApiToken

function Get-TokenFromEnv{
(Get-Item -path "Env:$ENV_VAR_TOKEN_NAME" -ErrorAction SilentlyContinue).Value
}
####################################################################################################

function Get-EnvVariable{
param(
[Parameter(Mandatory)][string]$Name
)

if(! (Test-Path -Path "Env:$Name") ){
return $null
}

$ret = "Env:$Name"

return $ret
}

####################################################################################################

function writedebug{
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)][string]$Message
)

process{
Write-MyDebug $Message -Section "api"
}
}
Loading