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
11 changes: 11 additions & 0 deletions Test/public/buildTree.test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function Test_Build-Tree{

Check warning

Code scanning / PSScriptAnalyzer

The cmdlet 'Test_Build-Tree' uses an unapproved verb. Warning

The cmdlet 'Test_Build-Tree' uses an unapproved verb.

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$hubbers,$tree = Build-Tree

Assert-AreEqual -Expected ashtom -Presented $hubbers.rulasg.manager.manager.manager.manager.github_login

# total employeed
Assert-Count -Expected 4410 -Presented $hubbers
Assert-AreEqual -Expected 4410 -Presented $tree.totalEmployees

}
103 changes: 103 additions & 0 deletions public/buildTree.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
function Build-Tree {

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Build-Tree' does not have a help comment. Note

The cmdlet 'Build-Tree' does not have a help comment.
[cmdletbinding()]
param (

)

$hubbers = Get-Hubber -AsHashtable

$ceo = $hubbers.Values | Where-Object { $_.manager -eq $_.github_login }

$tree = Build-Node $hubbers $ceo

$global:hubbers = $hubbers

Check warning

Code scanning / PSScriptAnalyzer

Found global variable 'global:hubbers'. Warning

Found global variable 'global:hubbers'.
$global:tree = $tree

Check warning

Code scanning / PSScriptAnalyzer

Found global variable 'global:tree'. Warning

Found global variable 'global:tree'.

return $hubbers, $tree

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Build-Tree' returns an object of type 'System.Object[]' but this type is not declared in the OutputType attribute. Note

The cmdlet 'Build-Tree' returns an object of type 'System.Object[]' but this type is not declared in the OutputType attribute.

} Export-ModuleMember -Function Build-Tree


function Build-Node {
param(
[Parameter(Mandatory, Position = 1)][object]$hubbers,
[Parameter(Mandatory, Position = 2)][object]$Node
)

try {

Write-Host "." -NoNewline

Check warning

Code scanning / PSScriptAnalyzer

File 'buildTree.ps1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information. Warning

File 'buildTree.ps1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information.

# Stop after X nodes
if (! (Test-Continue)) {
$Node.count = -1
return $Node
}

$nlogin = $Node.github_login

## Manager
# Set to null the manager for the CEO where manager == him self
$node.manager = ($node.manager -ne $nlogin) ? $hubbers.$($node.manager) : $null

## Employees

$employeesList = $hubbers.Values | Where-Object { ($_.manager -eq $nlogin) -and ($_.github_login -ne $nlogin) }

$Node.totalEmployees = 0

# Recurse employ
if ($employeesList.count -ne 0) {

$Node.employees = @{}

# recurse call
foreach ($employee in $employeesList) {

$elogin = $employee.github_login

if( $null -eq $elogin -or [string]::IsNullOrWhiteSpace($elogin) ){
Write-Warning -Message "Skipping employee name [$($employee.name)] with empty github_login under manager $nlogin"
Write-Verbose -message "$($employee | convertto-Json -Depth 10) "
continue
}

$Node.employees.$elogin = Build-Node $hubbers $employee
}

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# Count the number of employees under this node
foreach ($employee in $Node.employees.Values) {
if ($null -ne $employee.totalEmployees) {
$Node.totalEmployees += $employee.totalEmployees
}
$Node.totalEmployees++
}
}

$Node.sequenceNumber = $script:count

return $Node
} catch {
Write-Error -Message "Error building node for $($Node.github_login): $_"
}
}

function Test-Continue() {

$max = 5000

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
if ($null -eq $script:count) {
$script:count = 0
}
else {
$script:count++
}

if ($script:count -gt $max) {
return $false
}

# Write-Host "$script:count ." -NoNewline

return $true
}
9 changes: 7 additions & 2 deletions public/getByContry.ps1 → public/getHubber.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function Get-Hubber{
[CmdletBinding()]
param (
[Parameter(Position=0)][string]$Handle
[Parameter(Position=0)][string]$Handle,
[Parameter()][switch]$AsHashtable
)

$hubbers = Get-Content -Path "~/hubbers.json" | ConvertFrom-Json -Depth 10 -AsHashtable
Expand All @@ -10,7 +11,11 @@ function Get-Hubber{
return [pscustomobject] $hubbers.$Handle
}

return $hubbers.Values
if($AsHashtable){
return $hubbers
} else {
return $hubbers.Values
}
} Export-ModuleMember -Function Get-Hubber

function Get-HubberByCountry {
Expand Down
Loading