PSRule icon indicating copy to clipboard operation
PSRule copied to clipboard

[FEATURE] Allow conventions to append additional information to job summary

Open Copilot opened this issue 6 months ago • 1 comments

This PR implements the ability for conventions to contribute custom content to PSRule job summaries, providing extensibility for the generated output.

Changes Made

Core Implementation

  • Added IJobSummaryContributor interface: Allows conventions to provide custom content sections
  • Added JobSummarySection class: Represents custom sections with title and markdown content
  • Enhanced JobSummaryWriter: Now collects and displays convention contributions in job summaries
  • Updated AssertPipelineBuilder: Passes convention contributors to JobSummaryWriter during pipeline construction

Key Features

  • Backward compatible: Existing conventions and job summaries continue to work unchanged
  • Extensible: Conventions can add multiple sections with custom titles and markdown content
  • Error resilient: Exceptions from individual conventions don't break the entire job summary
  • Flexible content: Supports any markdown content including tables, lists, links, code blocks, etc.

Usage Example

Conventions can implement the IJobSummaryContributor interface to add custom sections:

public class MyConvention : BaseConvention, IConventionV1, IJobSummaryContributor
{
    public IEnumerable<JobSummarySection>? GetJobSummaryContent()
    {
        return new[] 
        {
            new JobSummarySection("Custom Metrics", "- Processed: 100 items\n- Success rate: 95%"),
            new JobSummarySection("Environment Info", "- Runtime: .NET 8.0\n- OS: Linux")
        };
    }
    
    // ... other convention implementation
}

The job summary will include additional sections after the standard PSRule content:

# PSRule result summary

❌ PSRule completed with an overall result of 'Fail' with 10 rule(s) and 5 target(s) in 00:00:02.123.

## Analysis
...

## Custom Metrics
- Processed: 100 items
- Success rate: 95%

## Environment Info
- Runtime: .NET 8.0
- OS: Linux

Testing

  • Added comprehensive unit tests covering normal operation, empty contributors, and error scenarios
  • All existing tests continue to pass, ensuring backward compatibility
  • Created example convention demonstrating the feature

This implementation provides the requested extensibility for job summaries while maintaining all existing functionality and following PSRule's architectural patterns.

Fixes #2667.


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

Copilot avatar Jul 08 '25 13:07 Copilot

Allow registering conventions by using the IRuntimeServiceCollection interface. Similar to AddService add a method for AddConvention.

Added AddConvention<TConvention>() method to IRuntimeServiceCollection interface, similar to AddService. This allows conventions to be registered using the same service collection pattern. Also added GetConventions() method to ILanguageScope to retrieve registered conventions. Changes made in 59894e8.

Copilot avatar Jul 09 '25 17:07 Copilot