Skip to content

Add configurable CSV output columns for detailed results#3026

Merged
BernieWhite merged 9 commits into
mainfrom
copilot/fix-1165
Sep 5, 2025
Merged

Add configurable CSV output columns for detailed results#3026
BernieWhite merged 9 commits into
mainfrom
copilot/fix-1165

Conversation

Copilot AI commented Sep 2, 2025

Copy link
Copy Markdown
Contributor

This PR implements configurable CSV output columns for PSRule, allowing users to customize which columns are included in CSV detailed output format.

Progress

  • Implement OutputOption.CsvDetailedColumns property in PSRule configuration
  • Update CsvOutputWriter to support configurable columns with fallback to defaults
  • Add comprehensive test coverage for default, custom, and nested property scenarios
  • Leverage existing object path infrastructure for nested property access
  • Maintain full serialization support for YAML and environment variables
  • Add help documentation to about_PSRule_Options.md for the new csvDetailedColumns option
  • Reorder CsvDetailedColumns property to appear after Culture in OutputOption.cs
  • Add test coverage for Info.Annotations.severity, Field.resourceGroup, and Tag.category columns
  • Update documentation to correctly describe custom properties under Info.Annotations, Tag, and Field

Problem

Previously, CSV output had a fixed column structure that couldn't be customized. Users needed flexibility to:

  • Include only specific columns of interest
  • Access nested properties like Info.Synopsis or Level
  • Reduce output size by excluding unnecessary columns
  • Integrate with downstream tools that expect specific column formats

Solution

Added a new CsvDetailedColumns property to OutputOption that accepts an array of column names. The implementation supports:

Configuration Methods

YAML Configuration:

output:
  csvDetailedColumns:
  - RuleName
  - TargetName
  - Outcome
  - Synopsis

Environment Variable:

export PSRULE_OUTPUT_CSVDETAILEDCOLUMNS="RuleName;TargetName;Outcome;Synopsis"

Supported Column Types

  • Standard properties: RuleName, TargetName, TargetType, Outcome, OutcomeReason, Synopsis, Recommendation
  • Custom properties: Properties under Info.Annotations, Tag, and Field using dotted notation

Key Features

  • 100% Backward Compatible: No configuration means identical output to previous versions
  • Flexible: Supports both simple property names and nested object paths
  • Robust: Invalid column names result in empty values (no errors)
  • Consistent: Uses same configuration patterns as other PSRule options

Examples

Before (fixed output):

RuleName,TargetName,TargetType,Outcome,OutcomeReason,Synopsis,Recommendation
"Test.Rule","Resource1","TestType","Pass","Processed","Test synopsis","Test recommendation"

After (configurable):

RuleName,Outcome,Synopsis
"Test.Rule","Pass","Test synopsis"

Implementation Details

  • Modified CsvOutputWriter to use configurable columns with default fallback
  • Added comprehensive test coverage for default, custom, and nested property scenarios
  • Leveraged existing object path infrastructure for nested property access
  • Maintained full serialization support for YAML and environment variables
  • Added complete documentation in about_PSRule_Options.md with examples for all configuration methods
  • Properly ordered CsvDetailedColumns property after Culture in OutputOption.cs
  • Enhanced test coverage to include Info.Annotations.severity, Field.resourceGroup, and Tag.category

Fixes #1165.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: BernieWhite <13513058+BernieWhite@users.noreply.github.com>
Copilot AI changed the title [WIP] Configure columns for CSV output Add configurable CSV output columns for detailed results Sep 2, 2025
Copilot AI requested a review from BernieWhite September 2, 2025 23:29

@BernieWhite BernieWhite left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Add help content to the markdown file concepts/PSRule/en-US/about_PSRule_Options.md for the new option csvDetailedColumns.

Co-authored-by: BernieWhite <13513058+BernieWhite@users.noreply.github.com>

Copilot AI commented Sep 3, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Add help content to the markdown file concepts/PSRule/en-US/about_PSRule_Options.md for the new option csvDetailedColumns.

Added comprehensive help documentation for the csvDetailedColumns option to about_PSRule_Options.md. The documentation includes:

  • Complete description of the feature and its behavior
  • All supported column types (standard, nested, custom properties)
  • Configuration examples for PowerShell, YAML, and environment variables
  • Integration with GitHub Actions and Azure Pipelines examples
  • Updated example configurations showing default and custom usage

Commit: f183837

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/microsoft/PSRule/commits
    • Triggering command: /usr/bin/python3 /home/REDACTED/.local/bin/mkdocs build --quiet (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@BernieWhite BernieWhite left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Reorder properties in src/PSRule/Configuration/OutputOption.cs so that CsvDetailedColumns is after Culture.

Comment thread tests/PSRule.Tests/Pipeline/Output/CsvOutputWriterTests.cs Outdated
Comment thread docs/concepts/PSRule/en-US/about_PSRule_Options.md Outdated
Comment thread docs/concepts/PSRule/en-US/about_PSRule_Options.md Outdated
…ntation

Co-authored-by: BernieWhite <13513058+BernieWhite@users.noreply.github.com>

Copilot AI commented Sep 3, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Reorder properties in src/PSRule/Configuration/OutputOption.cs so that CsvDetailedColumns is after Culture.

Reordered the CsvDetailedColumns property to appear after Culture in OutputOption.cs. Updated all related methods (constructor, copy constructor, Equals, GetHashCode, Combine, and Load methods) to maintain the proper order. Commit: 9363ec0

@BernieWhite BernieWhite marked this pull request as ready for review September 4, 2025 14:02
@BernieWhite BernieWhite requested a review from a team as a code owner September 4, 2025 14:02
@BernieWhite BernieWhite merged commit e0589ee into main Sep 5, 2025
20 checks passed
@BernieWhite BernieWhite deleted the copilot/fix-1165 branch September 5, 2025 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configure columns for CSV output

2 participants