-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor: Replace YamlHelper utility with YamlScalarAccessor trait #154
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
base: main
Are you sure you want to change the base?
Conversation
f0f9f53
to
0a891a8
Compare
Migrated all security recipes from static YamlHelper utility methods to the YamlScalarAccessor trait pattern. This improves code organization and follows OpenRewrite best practices for LST manipulation. Changes: - Created YamlScalarAccessor trait with 6 default methods - Migrated 7 recipes to implement the trait - Deleted deprecated YamlHelper utility class - All tests pass
0a891a8
to
47ff257
Compare
Renamed org.openrewrite.github.traits to org.openrewrite.github.util to better reflect that YamlScalarAccessor is a utility interface/mixin rather than an OpenRewrite trait (which should extend Trait<T>). Changes: - Moved package from traits/ to util/ - Updated all imports in recipe files - Updated package-info documentation - All tests pass
import org.openrewrite.yaml.YamlIsoVisitor; | ||
import org.openrewrite.yaml.tree.Yaml; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import org.openrewrite.yaml.YamlIsoVisitor; | |
import org.openrewrite.yaml.tree.Yaml; | |
import org.openrewrite.yaml.YamlIsoVisitor; |
.collect(Collectors.toList()); | ||
|
||
assertThat(steps).hasSize(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.collect(Collectors.toList()); | |
assertThat(steps).hasSize(2); | |
.toList(); | |
assertThat(steps.getFirst().getActionName()).isEqualTo("actions/checkout"); | |
assertThat(steps.getFirst().getActionVersion()).isEqualTo("v3"); |
.collect(Collectors.toList()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.collect(Collectors.toList()); | |
.toList(); | |
assertThat(steps.getFirst().getActionName()).isEqualTo("actions/setup-java"); |
spec -> spec.afterRecipe(results -> { | ||
ActionStep.Matcher matcher = new ActionStep.Matcher(); | ||
List<ActionStep> steps = matcher.lower(results) | ||
.collect(Collectors.toList()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.collect(Collectors.toList()); | |
.toList(); |
.collect(Collectors.toList()); | ||
|
||
// Test semantic version | ||
assertThat(steps.get(0).getActionName()).isEqualTo("actions/checkout"); | ||
assertThat(steps.get(0).getActionVersion()).isEqualTo("v3"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.collect(Collectors.toList()); | |
// Test semantic version | |
assertThat(steps.get(0).getActionName()).isEqualTo("actions/checkout"); | |
assertThat(steps.get(0).getActionVersion()).isEqualTo("v3"); | |
.toList(); | |
assertThat(steps.getFirst().getActionName()).isEqualTo("actions/checkout"); | |
assertThat(steps.getFirst().getActionVersion()).isEqualTo("v3"); | |
assertThat(steps.getFirst().getActionOwner()).isEqualTo("actions"); | |
assertThat(steps.getFirst().isVersionPinned()).isFalse(); |
.collect(Collectors.toList()); | ||
|
||
assertThat(steps).hasSize(1); | ||
assertThat(steps.get(0).getActionName()).isEqualTo("actions/checkout"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.collect(Collectors.toList()); | |
assertThat(steps).hasSize(1); | |
assertThat(steps.get(0).getActionName()).isEqualTo("actions/checkout"); | |
.toList(); | |
assertThat(steps.getFirst().getActionName()).isEqualTo("actions/checkout"); | |
assertThat(steps.getFirst().getActionVersion()).isNull(); | |
assertThat(steps.getFirst().isVersionPinned()).isFalse(); |
.collect(Collectors.toList()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.collect(Collectors.toList()); | |
.toList(); | |
assertThat(steps.getFirst().getActionName()).isEqualTo("actions/checkout"); |
spec -> spec.afterRecipe(results -> { | ||
ActionStep.Matcher matcher = new ActionStep.Matcher(); | ||
List<ActionStep> steps = matcher.lower(results) | ||
.collect(Collectors.toList()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.collect(Collectors.toList()); | |
.toList(); |
.collect(Collectors.toList()); | ||
|
||
// Both should match - local actions are still action steps | ||
assertThat(steps).hasSize(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.collect(Collectors.toList()); | |
// Both should match - local actions are still action steps | |
assertThat(steps).hasSize(2); | |
.toList(); | |
assertThat(steps.getFirst().getActionRef()).isEqualTo("./local-action"); | |
assertThat(steps.getFirst().getActionName()).isEqualTo("./local-action"); | |
assertThat(steps.getFirst().getActionOwner()).isNull(); // No owner for local actions |
.collect(Collectors.toList()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.collect(Collectors.toList()); | |
.toList(); | |
assertThat(steps.getFirst().getActionRef()).isEqualTo("docker://alpine:3.8"); |
Migrated all security recipes from static YamlHelper utility methods to
the YamlScalarAccessor trait pattern. This improves code organization and
follows OpenRewrite best practices for LST manipulation.
Changes: