-
-
Notifications
You must be signed in to change notification settings - Fork 0
Implement Build-Tree and Get-Hubber functions #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| function Test_Build-Tree{ | ||
|
|
||
Check noticeCode 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 | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| function Build-Tree { | ||
Check noticeCode 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 warningCode scanning / PSScriptAnalyzer Found global variable 'global:hubbers'. Warning
Found global variable 'global:hubbers'.
|
||
| $global:tree = $tree | ||
Check warningCode scanning / PSScriptAnalyzer Found global variable 'global:tree'. Warning
Found global variable 'global:tree'.
|
||
|
|
||
| return $hubbers, $tree | ||
Check noticeCode 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 warningCode 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 noticeCode 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 noticeCode 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 | ||
| } | ||
Check warning
Code scanning / PSScriptAnalyzer
The cmdlet 'Test_Build-Tree' uses an unapproved verb. Warning