Skip to content

refactor: Consolidate duplicate logging functions into shared module #321

@WilliamBerryiii

Description

@WilliamBerryiii

Note

Partial Completion Status (assessed 2026-02-13)

Completed:

  • Shared Write-SecurityLog function created in SecurityHelpers.psm1 (scripts/security/Modules/)
  • CIHelpers.psm1 exists with CI platform detection and annotation functions

Remaining:

  • Test-DependencyPinning.ps1 still contains local Write-PinningLog function (~25 lines)
  • Test-SHAStaleness.ps1 still contains local Write-SecurityLog function (~25 lines)
  • Neither script imports the shared module or uses the consolidated function
  • No Write-ScriptLog equivalent added to LintingHelpers.psm1 as originally proposed

Issue Description

Multiple PowerShell scripts define nearly identical logging functions that support GitHub Actions, Azure DevOps, and console output formats. Write-PinningLog in scripts/security/Test-DependencyPinning.ps1 and Write-SecurityLog in scripts/security/Test-SHAStaleness.ps1 share the same structure and should be consolidated into a single shared function in scripts/linting/Modules/LintingHelpers.psm1.

Additional Context

Current duplication:

  • Test-DependencyPinning.ps1:Write-PinningLog (~25 lines)
  • Test-SHAStaleness.ps1:Write-SecurityLog (~25 lines)

Recommended approach:

  1. Add Write-ScriptLog to LintingHelpers.psm1 with -Level (Info/Warning/Error/Debug) and -OutputFormat (github/azdo/console) parameters
  2. Update both security scripts to import and use the shared function
  3. Remove the duplicate local functions

Testing:

  • Run npm run pester to verify existing tests pass
  • Manually verify output formatting in GitHub Actions workflow

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions