Refactor: Extract duplicated transformation logic in Export-AzRetirementReport#20
Merged
cocallaw merged 4 commits intofeature/add-wrkbookrecs-psfrom Jan 13, 2026
Merged
Conversation
…ment Co-authored-by: cocallaw <11371083+cocallaw@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] WIP address feedback on 'Feature/add wrkbookrecs ps' PR
Refactor: Extract duplicated transformation logic in Export-AzRetirementReport
Jan 13, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors the Export-AzRetirementReport function to eliminate code duplication by extracting the data transformation logic that was repeated across CSV, JSON, and HTML export branches.
Changes:
- Extracted the transformation logic for handling Description/Solution substitution to execute once before format selection
- Removed approximately 40 lines of duplicated code across the three export branches
- Updated the HTML export branch to use pre-transformed data instead of performing inline transformation
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: cocallaw <11371083+cocallaw@users.noreply.github.com>
cocallaw
added a commit
that referenced
this pull request
Jan 13, 2026
* Switch to Az.Advisor module by default, add API mode Changed default behavior to use the Az.Advisor PowerShell module for retrieving Azure retirement recommendations, with REST API access now available via the -UseAPI switch. Added Test-AzAdvisorSession for module/session validation, updated Connect-AzRetirementMonitor to require -UsingAPI for API mode, and improved documentation and error handling throughout. This is a breaking change and requires Az.Advisor for default usage; see release notes for migration details. * Add quick start guide for AzRetirementMonitor v2.0 Introduces QUICKSTART.md with setup instructions, usage examples, troubleshooting tips, and migration notes for AzRetirementMonitor v2.0. Highlights new default method using Az.Advisor and provides guidance for both PowerShell and API workflows. * Update README for v2.0.0 with new workflows and breaking changes Documents major changes in version 2.0.0, including the new default use of the Az.Advisor module, updated authentication workflows, and the introduction of API mode via switches. Adds migration guidance, clarifies command usage, updates example outputs, and provides a comparison table between the default and API methods. Improves overall structure and detail for installation, authentication, and usage scenarios. * Enhance retirement recommendation parsing logic Improved detection of retirement recommendations by parsing extended properties for retirementFeatureName and retirementDate, and updated logic to check both text and extended properties. Also, switched to using ResourceMetadataResourceId for resource identification and improved description building to prefer retirement feature details. * Add Support for PowerShell Desktop version 5 (#17) * Expand PowerShell compatibility in module manifest Updated AzRetirementMonitor.psd1 to support both PowerShell Core (7+) and Desktop (5.1) editions. This change broadens compatibility for users on different PowerShell platforms. * Fix UTC time generation for PowerShell 5.1 compatibility Replaced usage of Get-Date -AsUTC with [DateTime]::UtcNow to ensure compatibility with PowerShell 5.1, which does not support the -AsUTC parameter. * Update README for PowerShell compatibility Clarifies that the module now supports both PowerShell Desktop 5.1 and Core 7+, updating prerequisites and feature notes to reflect expanded compatibility. * Update QUICKSTART.md * Update docs for PowerShell compatibility and formatting Added clarification that both PowerShell Desktop 5.1 and Core 7+ are supported. Improved formatting and readability in QUICKSTART.md and README.md for better guidance and migration instructions. * Improve Solution field for Az.Advisor export formats Transforms the Solution field to use Description when Problem and Solution are identical and Description exists, providing more informative output for Az.Advisor mode in CSV, JSON, and HTML exports. * Rename 'Solution' column to 'Description' in HTML report Updated the HTML export table header to use 'Description' instead of 'Solution' for clarity and consistency with report content. * Update tests to use -UseAPI parameter Added the -UseAPI parameter to relevant Connect-AzRetirementMonitor and Get-AzRetirementRecommendation calls in the test suite to ensure API-based authentication and error handling are properly validated. * Update Get-AzRetirementRecommendation.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Get-AzRetirementRecommendation.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix subscription context not being set when querying specific subscriptions via Az.Advisor (#19) * Initial plan * Fix subscription context handling in Get-AzRetirementRecommendation Co-authored-by: cocallaw <11371083+cocallaw@users.noreply.github.com> * Add error handling for context restoration Co-authored-by: cocallaw <11371083+cocallaw@users.noreply.github.com> * Update Public/Get-AzRetirementRecommendation.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Public/Get-AzRetirementRecommendation.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add test coverage for subscription context switching behavior Co-authored-by: cocallaw <11371083+cocallaw@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: cocallaw <11371083+cocallaw@users.noreply.github.com> Co-authored-by: Corey Callaway <coreylcallaway@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor: Extract duplicated transformation logic in Export-AzRetirementReport (#20) * Initial plan * Refactor: extract duplicated transformation logic before switch statement Co-authored-by: cocallaw <11371083+cocallaw@users.noreply.github.com> * Update Public/Export-AzRetirementReport.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add functional tests for transformation logic Co-authored-by: cocallaw <11371083+cocallaw@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: cocallaw <11371083+cocallaw@users.noreply.github.com> Co-authored-by: Corey Callaway <coreylcallaway@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Documentation verification: Add explicit compatibility notes to Export-AzRetirementReport help (#21) * Initial plan * Enhanced Export-AzRetirementReport help documentation Co-authored-by: cocallaw <11371083+cocallaw@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: cocallaw <11371083+cocallaw@users.noreply.github.com> * Refactor and sanitize export for CSV in report script Refactored the transformation of recommendation objects to ensure all properties are strings and not arrays, improving export consistency. Enhanced CSV export by explicitly sanitizing all fields to prevent formula injection in spreadsheet applications. This improves data safety and reliability for CSV consumers. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: cocallaw <11371083+cocallaw@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The transformation logic for using
DescriptionwhenProblemequalsSolutionwas duplicated across CSV and JSON export branches, reducing maintainability.Changes:
Before:
After:
Test Coverage:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.