Skip to content

Commit 925b021

Browse files
Declare inventory helper contracts
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 544e240 commit 925b021

1 file changed

Lines changed: 95 additions & 10 deletions

File tree

.github/scripts/Get-ProcessPSModuleWorkflowInventory.ps1

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ Set-StrictMode -Version Latest
6464
$ErrorActionPreference = 'Stop'
6565

6666
function Invoke-GhCommand {
67+
<#
68+
.SYNOPSIS
69+
Invokes GitHub CLI arguments and returns their combined output.
70+
#>
6771
[CmdletBinding()]
72+
[OutputType([string])]
6873
param(
6974
[Parameter(Mandatory)]
7075
[string[]] $ArgumentList
@@ -79,22 +84,32 @@ function Invoke-GhCommand {
7984
}
8085

8186
function ConvertFrom-JsonResponse {
87+
<#
88+
.SYNOPSIS
89+
Converts a possibly empty JSON response into a stable object array.
90+
#>
8291
[CmdletBinding()]
92+
[OutputType([object[]])]
8393
param(
8494
[Parameter(Mandatory)]
8595
[AllowEmptyString()]
8696
[string] $Content
8797
)
8898

8999
if ([string]::IsNullOrWhiteSpace($Content)) {
90-
return @()
100+
return [object[]] @()
91101
}
92102

93-
@($Content | ConvertFrom-Json -Depth 100)
103+
[object[]] @($Content | ConvertFrom-Json -Depth 100)
94104
}
95105

96106
function Get-GitHubRepository {
107+
<#
108+
.SYNOPSIS
109+
Gets the repositories included in GitHub inventory discovery.
110+
#>
97111
[CmdletBinding()]
112+
[OutputType([object[]])]
98113
param(
99114
[Parameter(Mandatory)]
100115
[string] $Owner,
@@ -124,13 +139,18 @@ function Get-GitHubRepository {
124139
$repositories = ConvertFrom-JsonResponse -Content $response
125140
}
126141

127-
@($repositories |
142+
[object[]] @($repositories |
128143
Where-Object { $IncludeArchivedRepository -or -not $_.isArchived } |
129144
Sort-Object nameWithOwner)
130145
}
131146

132147
function Get-GitHubMatchingWorkflowFile {
148+
<#
149+
.SYNOPSIS
150+
Finds and reads default-branch workflow files matching the expected reference.
151+
#>
133152
[CmdletBinding()]
153+
[OutputType([object[]])]
134154
param(
135155
[Parameter(Mandatory)]
136156
[psobject[]] $RepositoryInfo,
@@ -175,7 +195,7 @@ function Get-GitHubMatchingWorkflowFile {
175195
$repositoryByName[$item.nameWithOwner] = $item
176196
}
177197

178-
@($searchResults |
198+
[object[]] @($searchResults |
179199
Where-Object { $repositoryByName.ContainsKey($_.repository.full_name) } |
180200
Sort-Object { $_.repository.full_name }, path -Unique |
181201
ForEach-Object {
@@ -201,7 +221,12 @@ function Get-GitHubMatchingWorkflowFile {
201221
}
202222

203223
function Get-LocalRepositoryRoot {
224+
<#
225+
.SYNOPSIS
226+
Discovers unique Git repository roots below the supplied paths.
227+
#>
204228
[CmdletBinding()]
229+
[OutputType([string[]])]
205230
param(
206231
[Parameter(Mandatory)]
207232
[string[]] $InputPath
@@ -224,11 +249,16 @@ function Get-LocalRepositoryRoot {
224249
}
225250
}
226251

227-
@($roots | Sort-Object -Unique)
252+
[string[]] @($roots | Sort-Object -Unique)
228253
}
229254

230255
function Get-LocalRepositoryName {
256+
<#
257+
.SYNOPSIS
258+
Resolves a repository name from its origin URL or local directory.
259+
#>
231260
[CmdletBinding()]
261+
[OutputType([string])]
232262
param(
233263
[Parameter(Mandatory)]
234264
[string] $RepositoryRoot
@@ -243,7 +273,12 @@ function Get-LocalRepositoryName {
243273
}
244274

245275
function Get-LocalDefaultBranch {
276+
<#
277+
.SYNOPSIS
278+
Resolves the Git ref used as the local repository's default branch.
279+
#>
246280
[CmdletBinding()]
281+
[OutputType([psobject])]
247282
param(
248283
[Parameter(Mandatory)]
249284
[string] $RepositoryRoot
@@ -277,7 +312,12 @@ function Get-LocalDefaultBranch {
277312
}
278313

279314
function Get-LocalWorkflowFile {
315+
<#
316+
.SYNOPSIS
317+
Reads workflow files from each local repository's default-branch Git object.
318+
#>
280319
[CmdletBinding()]
320+
[OutputType([psobject[]])]
281321
param(
282322
[Parameter(Mandatory)]
283323
[string[]] $InputPath
@@ -322,26 +362,36 @@ function Get-LocalWorkflowFile {
322362
}
323363

324364
function Get-MapKey {
365+
<#
366+
.SYNOPSIS
367+
Gets normalized string keys from dictionary-like YAML values.
368+
#>
325369
[CmdletBinding()]
370+
[OutputType([string[]])]
326371
param(
327372
[Parameter()]
328373
[AllowNull()]
329374
[object] $Map
330375
)
331376

332377
if ($null -eq $Map) {
333-
return @()
378+
return [string[]] @()
334379
}
335380

336381
if ($Map -is [Collections.IDictionary]) {
337-
return @($Map.Keys | ForEach-Object { "$_" })
382+
return [string[]] @($Map.Keys | ForEach-Object { "$_" })
338383
}
339384

340-
@($Map.PSObject.Properties.Name)
385+
[string[]] @($Map.PSObject.Properties.Name)
341386
}
342387

343388
function Get-MapValue {
389+
<#
390+
.SYNOPSIS
391+
Gets a named value from dictionary-like YAML values.
392+
#>
344393
[CmdletBinding()]
394+
[OutputType([object])]
345395
param(
346396
[Parameter()]
347397
[AllowNull()]
@@ -368,7 +418,12 @@ function Get-MapValue {
368418
}
369419

370420
function ConvertTo-TriggerMap {
421+
<#
422+
.SYNOPSIS
423+
Normalizes mapping, scalar, and list workflow trigger syntax.
424+
#>
371425
[CmdletBinding()]
426+
[OutputType([Collections.IDictionary], [Collections.Specialized.OrderedDictionary])]
372427
param(
373428
[Parameter()]
374429
[AllowNull()]
@@ -403,7 +458,12 @@ function ConvertTo-TriggerMap {
403458
}
404459

405460
function ConvertTo-StringMap {
461+
<#
462+
.SYNOPSIS
463+
Converts dictionary-like values into an ordered string map.
464+
#>
406465
[CmdletBinding()]
466+
[OutputType([Collections.Specialized.OrderedDictionary])]
407467
param(
408468
[Parameter()]
409469
[AllowNull()]
@@ -419,22 +479,32 @@ function ConvertTo-StringMap {
419479
}
420480

421481
function ConvertTo-StringArray {
482+
<#
483+
.SYNOPSIS
484+
Converts a possibly empty YAML value into a string array.
485+
#>
422486
[CmdletBinding()]
487+
[OutputType([string[]])]
423488
param(
424489
[Parameter()]
425490
[AllowNull()]
426491
[object] $Value
427492
)
428493

429494
if ($null -eq $Value) {
430-
return @()
495+
return [string[]] @()
431496
}
432497

433-
@($Value | ForEach-Object { "$_" })
498+
[string[]] @($Value | ForEach-Object { "$_" })
434499
}
435500

436501
function ConvertTo-PermissionValue {
502+
<#
503+
.SYNOPSIS
504+
Normalizes scalar and mapping workflow permission syntax.
505+
#>
437506
[CmdletBinding()]
507+
[OutputType([string], [Collections.Specialized.OrderedDictionary])]
438508
param(
439509
[Parameter()]
440510
[AllowNull()]
@@ -457,7 +527,12 @@ function ConvertTo-PermissionValue {
457527
}
458528

459529
function Get-WorkflowInventoryItem {
530+
<#
531+
.SYNOPSIS
532+
Parses a workflow file into a normalized inventory record.
533+
#>
460534
[CmdletBinding()]
535+
[OutputType([psobject])]
461536
param(
462537
[Parameter(Mandatory)]
463538
[psobject] $WorkflowFile,
@@ -618,7 +693,12 @@ function Get-WorkflowInventoryItem {
618693
}
619694

620695
function ConvertTo-MarkdownCell {
696+
<#
697+
.SYNOPSIS
698+
Escapes a value for safe rendering in a Markdown table cell.
699+
#>
621700
[CmdletBinding()]
701+
[OutputType([string])]
622702
param(
623703
[Parameter()]
624704
[AllowNull()]
@@ -633,7 +713,12 @@ function ConvertTo-MarkdownCell {
633713
}
634714

635715
function ConvertTo-WorkflowInventoryMarkdown {
716+
<#
717+
.SYNOPSIS
718+
Renders workflow inventory records as a Markdown report.
719+
#>
636720
[CmdletBinding()]
721+
[OutputType([string])]
637722
param(
638723
[Parameter(Mandatory)]
639724
[psobject[]] $Inventory,

0 commit comments

Comments
 (0)