Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 8, 2025

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 Copilot AI changed the title [WIP] [FEATURE] Append additional information to job summary [FEATURE] Allow conventions to append additional information to job summary Jul 8, 2025
@Copilot Copilot AI requested a review from BernieWhite July 8, 2025 14:07
Copilot finished work on behalf of BernieWhite July 8, 2025 14:07
@Copilot Copilot AI requested a review from BernieWhite July 9, 2025 05:17
Copilot finished work on behalf of BernieWhite July 9, 2025 05:17
Copilot finished work on behalf of BernieWhite July 9, 2025 06:51
Copy link
Member

@BernieWhite BernieWhite left a comment

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Copilot AI commented Jul 9, 2025

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 Copilot AI requested a review from BernieWhite July 9, 2025 17:46
Copilot finished work on behalf of BernieWhite July 9, 2025 17:46
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.

[FEATURE] Append additional information to job summary
2 participants