Skip to content
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

Feature - YAML search - find properties with a specific scalar value #4657

Merged
merged 3 commits into from
Nov 12, 2024

Conversation

aamotharald
Copy link
Contributor

@aamotharald aamotharald commented Nov 8, 2024

What's changed?

I have changed the org.openrewrite.yaml.search.FindProperty search recipe to allow searching for yaml properties which have a specific scalar value. The new reciped parameter propertyValue is OPTIONAL which ensures downwards-compatibility.

What's your motivation?

I need this search functionality for a specific use case I am working on.
I want to alter a yamle file if the specified yaml key does have a certain value. The search recipe can act as a Precondition here.

Anything in particular you'd like reviewers to focus on?

I thried to create a dedicated org.openrewrite.yaml.search.FindPropertyWithValue recipe inheriting from org.openrewrite.yaml.search.FindProperty, but recipes are final and do not allow for inheritance. This is why I added an optional parameter to the existing recipe instead.
Also I did not find out how to test a negative search case. I marked hence the negative test as @Disabled.

Have you considered any alternatives or workarounds?

Alternative: Use SourceGraph to find the repos having the specified Yaml condition. Well then I can also run the change with Sourcegraph.

Any additional context

I love the generic yaml stuff you have

Checklist

  • I've added unit tests to cover both positive and negative cases (well comment about the negative test case)
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@aamotharald aamotharald marked this pull request as ready for review November 8, 2024 09:20
@aamotharald aamotharald changed the title Feature - YAML search - working draft Feature - YAML search - find properties with a specific scalar value Nov 8, 2024
…perty.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@sambsnyd sambsnyd merged commit e8f149e into openrewrite:main Nov 12, 2024
@sambsnyd
Copy link
Member

Thanks @aamotharald !

MBoegers pushed a commit to MBoegers/rewrite that referenced this pull request Dec 18, 2024
…penrewrite#4657)

* working draft

* IntelliJ formatting

* Update rewrite-yaml/src/main/java/org/openrewrite/yaml/search/FindProperty.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: Sam Snyder <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants