feat: add --preview flag to preview aviator remediations before applying - #1076
feat: add --preview flag to preview aviator remediations before applying#1076dhanwanthp wants to merge 4 commits into
Conversation
…and to display the correct value for __action__
…rics for better readability, removed a redundant field and added tests for code that was not covered before.
| * Applies or previews remediations for each source entry until done or the issue-id filter is exhausted. | ||
| * Caller owns {@code source} lifecycle (try-with-resources). | ||
| */ | ||
| public static ApplyResult apply( |
There was a problem hiding this comment.
As the number of parameters keep growing, maybe better to combine in a single object that implements builder pattern (through Lombok @Builder), i.e.,
apply(ApplyArgs.builder()
.source(source)
.sourceCodeDirectory(sourceCodeDirectory)
...
.build();
Same could potentially be applied to other methods in Aviator code to reduce number of parameters.
| */ | ||
| @Reflectable | ||
| @JsonPropertyOrder({"changeIndex", "lineFrom", "lineTo", "originalCode", "newCode", "context", "fuzzyMatched"}) | ||
| public record FileChange( |
There was a problem hiding this comment.
Similar comment as before; maybe better to add Lombok @Builder instead of relying on constructor parameter order.
| unirest, logger, progressWriter, resolved.artifacts())) { | ||
| ApplyResult applyResult = RemediationsApplyHelper.apply( | ||
| source, sourceCodeDirectory, logger, issueIdFilter, LOG); | ||
| source, sourceCodeDirectory, logger, issueIdFilter, LOG, previewMode); |
There was a problem hiding this comment.
Related to the apply comment elsewhere, what about:
- Move the various options that define method parameter values into a separate Picocli ArgGroup that can be shared between SSC and FoD commands
- Have that ArgGroup implement some interface with getters for each of the option values (through Lombok
@Getterannotations on the options/class) - Have the
RemediationsApplyHelper::applymethod take an instance of that interface
This way, the FoD & SSC apply-remediations commands can simply pass the ArgGroup to the apply method (together with the loggers, which remain separate method parameters), and due to interface abstraction, RemediationsApplyHelper doesn't have a compile-time dependency on CLI-specific code (like the ArgGroup).
| unirest, logger, progressWriter, resolved.artifacts())) { | ||
| ApplyResult applyResult = RemediationsApplyHelper.apply( | ||
| source, sourceCodeDirectory, logger, issueIdFilter, LOG); | ||
| source, sourceCodeDirectory, logger, issueIdFilter, LOG, previewMode); |
There was a problem hiding this comment.
Why are you passing LOG to a different class? Usually, each class has its own Slf4j logger, which also makes it much easier to identify which class generated a particular log message.
| unirest, logger, progressWriter, resolved.artifacts())) { | ||
| ApplyResult applyResult = RemediationsApplyHelper.apply( | ||
| source, sourceCodeDirectory, logger, issueIdFilter, LOG); | ||
| source, sourceCodeDirectory, logger, issueIdFilter, LOG, previewMode); |
There was a problem hiding this comment.
I think there's some overlap between FoD and SSC implementations of the apply-remediations command; please check whether it makes sense to introduce a common AbstractAviatorApplyRemediationsCommand base class.
This MR adds a new
--previewflag to the fcli aviator ssc apply-remediations and fcli fod aviator apply-remediations commands, enabling users to preview what changes would be applied to their source code without actually modifying files.Features:
Usage:
Output format:-