openrewrite / rewrite

Automated mass refactoring of source code.

Home Page:https://docs.openrewrite.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create YAML File with remote content

nicolasb29 opened this issue · comments

What problem are you trying to solve?

I want to create a Yaml file with a remote content

What precondition(s) should be checked before applying this recipe?

Check that the URL exists and the content type is yaml

Describe the situation before applying the recipe

Nothing

Describe the situation after applying the recipe

With an URL with content

content:
  languages:
    - french
    - english

I want to have a yaml file with this content

Have you considered any alternatives or workarounds?

No

Hi! You might be interested to look at our existing create yaml file recipe. That allows you to create a file where one does not already exist.

From your description it seems you'd like either an option, or similar recipe that calls out to an external source to get the Yaml contents? Should not be hard given what's there already, and knowing we already have a RemoteFile.

Could you describe the use case a bit more? That way we can better gauge if that's something to provide out of the box, or merely help you write your own recipe.

Hi!

The idea is to use a recipe like this

---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.CreateYamlFileExample
displayName: Create YAML file example
recipeList:
  - org.openrewrite.yaml.CreateYamlFile:
      relativeFileName: foo/bar/baz.yaml
      fileContentsUrl: https://raw.githubusercontent.com/openrewrite/rewrite/main/rewrite.yml

So the content of the file foo/bar/baz.yaml will be

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.self.Rewrite
displayName: The rewrite recipes that rewrite rewrite recipes
description: >
  The set of recipes that run against the rewrite codebase itself.
recipeList:
  - org.openrewrite.text.EndOfLineAtEndOfFile

I think that it is very useful for yaml file bigger than 10-20 lines.

Thanks for the suggestion! @PhilKes was kind enough to contribute this in