Skip to content

Commit d71a203

Browse files
Fix ScriptAnalyzer findings in helper
Add help comments, align close-brace formatting, and add ShouldProcess support for generated catalog page writes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent a69dbce commit d71a203

1 file changed

Lines changed: 88 additions & 10 deletions

File tree

.github/actions/update-index/src/Helper.psm1

Lines changed: 88 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ function Show-RepoList {
3737
$currentContext = Get-GitHubContext -ErrorAction SilentlyContinue
3838
if ($null -eq $currentContext) {
3939
Connect-GitHubApp -Organization $Owner -Default
40-
}
41-
elseif ($currentContext.AuthType -eq 'App') {
40+
} elseif ($currentContext.AuthType -eq 'App') {
4241
Connect-GitHubApp -Organization $Owner -Default
43-
}
44-
else {
42+
} else {
4543
Write-Output "Using existing GitHub context [$($currentContext.Name)] with auth type [$($currentContext.AuthType)]"
4644
}
4745
Get-GitHubContext | Select-Object * | Format-List | Out-String
@@ -131,6 +129,14 @@ function Update-MDSection {
131129
}
132130

133131
function Get-PropertyValue {
132+
<#
133+
.SYNOPSIS
134+
Gets the first non-empty property value from an object.
135+
136+
.DESCRIPTION
137+
Evaluates the provided property names in order and returns the first property
138+
value that exists and is not null/whitespace. Returns the default value otherwise.
139+
#>
134140
[OutputType([object])]
135141
[CmdletBinding()]
136142
param(
@@ -163,6 +169,14 @@ function Get-PropertyValue {
163169
}
164170

165171
function Invoke-GitHubApi {
172+
<#
173+
.SYNOPSIS
174+
Invokes a GitHub REST API GET request.
175+
176+
.DESCRIPTION
177+
Calls the GitHub module API wrapper, auto-selects anonymous mode when no context
178+
is configured, normalizes wrapped responses, and treats HTTP 404 as missing data.
179+
#>
166180
[OutputType([object])]
167181
[CmdletBinding()]
168182
param(
@@ -196,8 +210,7 @@ function Invoke-GitHubApi {
196210

197211
if ($item.Response -is [array]) {
198212
$payloadItems += $item.Response
199-
}
200-
else {
213+
} else {
201214
$payloadItems += , $item.Response
202215
}
203216
}
@@ -217,8 +230,7 @@ function Invoke-GitHubApi {
217230
}
218231

219232
return $rawResponse
220-
}
221-
catch {
233+
} catch {
222234
$statusCode = $null
223235
if ($_.Exception.Response) {
224236
$statusCode = $_.Exception.Response.StatusCode.value__
@@ -241,6 +253,14 @@ function Invoke-GitHubApi {
241253
}
242254

243255
function Get-RepositoryReadmeContent {
256+
<#
257+
.SYNOPSIS
258+
Gets a repository README as plain text.
259+
260+
.DESCRIPTION
261+
Downloads the repository README from GitHub and decodes the returned
262+
Base64 content to UTF-8 text.
263+
#>
244264
[OutputType([string])]
245265
[CmdletBinding()]
246266
param(
@@ -266,6 +286,14 @@ function Get-RepositoryReadmeContent {
266286
}
267287

268288
function Get-MarkdownSummary {
289+
<#
290+
.SYNOPSIS
291+
Extracts a short summary from markdown content.
292+
293+
.DESCRIPTION
294+
Removes common markdown formatting and returns the first non-empty paragraph,
295+
suitable for compact previews.
296+
#>
269297
[OutputType([string])]
270298
[CmdletBinding()]
271299
param(
@@ -297,6 +325,14 @@ function Get-MarkdownSummary {
297325
}
298326

299327
function ConvertTo-HtmlAttributeValue {
328+
<#
329+
.SYNOPSIS
330+
Converts text to a safe HTML attribute preview value.
331+
332+
.DESCRIPTION
333+
Normalizes whitespace, truncates to a max length, and escapes special HTML
334+
characters for use in attributes such as title.
335+
#>
300336
[OutputType([string])]
301337
[CmdletBinding()]
302338
param(
@@ -323,6 +359,14 @@ function ConvertTo-HtmlAttributeValue {
323359
}
324360

325361
function Get-OpenItemCount {
362+
<#
363+
.SYNOPSIS
364+
Gets the open issue or pull request count for a repository.
365+
366+
.DESCRIPTION
367+
Uses GitHub search API with a repository/type/state query and returns
368+
the total count.
369+
#>
326370
[OutputType([int])]
327371
[CmdletBinding()]
328372
param(
@@ -346,6 +390,14 @@ function Get-OpenItemCount {
346390
}
347391

348392
function Get-RepositoryVersion {
393+
<#
394+
.SYNOPSIS
395+
Gets a repository's latest version identifier.
396+
397+
.DESCRIPTION
398+
Returns the latest release tag/name when available, otherwise falls back
399+
to the most recent tag, or N/A.
400+
#>
349401
[OutputType([string])]
350402
[CmdletBinding()]
351403
param(
@@ -374,6 +426,14 @@ function Get-RepositoryVersion {
374426
}
375427

376428
function Get-WorkflowReference {
429+
<#
430+
.SYNOPSIS
431+
Gets the Process-PSModule workflow reference used by a repository.
432+
433+
.DESCRIPTION
434+
Scans common workflow entry files on the default branch and extracts the
435+
`@ref` from `uses: PSModule/Process-PSModule/...@ref` if present.
436+
#>
377437
[OutputType([string])]
378438
[CmdletBinding()]
379439
param(
@@ -409,6 +469,14 @@ function Get-WorkflowReference {
409469
}
410470

411471
function Get-ProcessReferenceStatus {
472+
<#
473+
.SYNOPSIS
474+
Computes status of a Process-PSModule workflow reference.
475+
476+
.DESCRIPTION
477+
Classifies a workflow reference value relative to the latest available
478+
Process-PSModule version.
479+
#>
412480
[OutputType([string])]
413481
[CmdletBinding()]
414482
param(
@@ -451,7 +519,15 @@ function Get-ProcessReferenceStatus {
451519
}
452520

453521
function New-ModuleCatalogPage {
454-
[CmdletBinding()]
522+
<#
523+
.SYNOPSIS
524+
Creates or updates a generated module catalog page.
525+
526+
.DESCRIPTION
527+
Builds markdown content from module metadata and writes it to the
528+
target page path.
529+
#>
530+
[CmdletBinding(SupportsShouldProcess)]
455531
param(
456532
[Parameter(Mandatory)]
457533
[string] $Path,
@@ -481,7 +557,9 @@ $($ModuleData.About)
481557
[View source README](https://github.com/$($ModuleData.Owner)/$($ModuleData.Name)#readme)
482558
"@
483559

484-
Set-Content -Path $Path -Value $content
560+
if ($PSCmdlet.ShouldProcess($Path, 'Write module catalog page')) {
561+
Set-Content -Path $Path -Value $content
562+
}
485563
}
486564

487565
function Update-ActionList {

0 commit comments

Comments
 (0)