Skip to content

feat(refactor): support for stack filtering#410

Merged
rix0rrr merged 5 commits intomainfrom
otaviom/refactor-stack-filtering
Apr 29, 2025
Merged

feat(refactor): support for stack filtering#410
rix0rrr merged 5 commits intomainfrom
otaviom/refactor-stack-filtering

Conversation

@otaviomacedo
Copy link
Contributor

@otaviomacedo otaviomacedo commented Apr 24, 2025

Users can now pass the stacks they want to be considered for refactoring:

cdk refactor StackA StackB ...

The result will include any mapping that contains at least one of the selected stacks. If no pattern is passed, all stacks are considered.

In this PR I also included the refactor command in the command line parsing list, which was missing. It was already working without it, but the command wouldn't show up in the help page, and it wouldn't recognize positional arguments. But the command itself (and its options) could be already used.

Closes #363.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the p2 label Apr 24, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team April 24, 2025 12:18
@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2025

Codecov Report

Attention: Patch coverage is 40.62500% with 19 lines in your changes missing coverage. Please review.

Project coverage is 79.98%. Comparing base (cd4ec06) to head (f9969b8).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
packages/aws-cdk/lib/cli/cdk-toolkit.ts 38.70% 19 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #410      +/-   ##
==========================================
- Coverage   80.94%   79.98%   -0.96%     
==========================================
  Files          66       66              
  Lines        6879     6894      +15     
  Branches      791      791              
==========================================
- Hits         5568     5514      -54     
- Misses       1291     1358      +67     
- Partials       20       22       +2     
Flag Coverage Δ
suite.unit 79.98% <40.62%> (-0.96%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

otaviomacedo and others added 2 commits April 24, 2025 14:21
---
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license
`requireApproval` is deprecated and has been moved to the `CliIoHost`.
this PR removes the last place where `requireApproval` was necessary in
`tmp-toolkit-helpers`, in `formatSecurityDiff`. `formatSecurityDiff` now
makes no _decisions_ on what to print; it returns the diff and a
`permissionChangeType` for the `IoHost` to interpret. this is a slight
behavior change, so all consumers of `formatSecurityDiff have been
updated accordingly (`deploy` and `diff` in `toolkit-lib` and in the
CLI).

`requireApproval` is now a vestigial structure only in use in the CLI. 

---
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license

---------

Co-authored-by: Momo Kornher <kornherm@amazon.co.uk>
@otaviomacedo otaviomacedo requested a review from Copilot April 24, 2025 16:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new refactor command to support resource stack filtering while refactoring. Key changes include:

  • Defining and integrating a new "refactor" command in the CLI, configuration, and user input structures.
  • Updating tests to verify stack filtering behavior and refining resource movements and mappings accordingly.
  • Adjusting the toolkit logic to process filtered stacks for refactoring.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/aws-cdk/test/cli/cli-arguments.test.ts Added verification for the new refactor command in the CLI arguments test.
packages/aws-cdk/test/api/refactoring/refactoring.test.ts Added tests for stack filtering and updated expectations in resource mapping.
packages/aws-cdk/lib/cli/user-input.ts Extended the user input interface with a new refactor option.
packages/aws-cdk/lib/cli/user-configuration.ts Included the REFACTOR command in the CLI command list.
packages/aws-cdk/lib/cli/parse-command-line-arguments.ts Integrated the refactor command with [STACKS..] and dry-run options.
packages/aws-cdk/lib/cli/convert-to-user-input.ts Added conversion logic for refactor command CLI arguments.
packages/aws-cdk/lib/cli/cli-config.ts Updated the CLI configuration with the refactor command details.
packages/aws-cdk/lib/cli/cdk-toolkit.ts Adjusted logic to filter stacks based on user selection for refactoring.
packages/@aws-cdk/toolkit-lib/test/actions/refactor.test.ts Updated tests to validate stack filtering scenarios for the refactor action.
packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts Revised the refactor command handling to process filtered stacks.
packages/@aws-cdk/tmp-toolkit-helpers/src/api/refactoring/index.ts Expanded resourceMappings to optionally filter mappings by selected stacks.
Comments suppressed due to low confidence (1)

packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts:967

  • There is a typo in the error message: 'Too see' should be 'To see'.
throw new ToolkitError('Refactor is not available yet. Too see the proposed changes, use the --dry-run flag.');

@otaviomacedo otaviomacedo disabled auto-merge April 25, 2025 08:15
@rix0rrr rix0rrr added this pull request to the merge queue Apr 29, 2025
Merged via the queue into main with commit d2505cd Apr 29, 2025
20 checks passed
@rix0rrr rix0rrr deleted the otaviom/refactor-stack-filtering branch April 29, 2025 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support stack filtering

5 participants