rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Create YAML File with remote content

Open nicolasb29 opened this issue 1 year ago • 2 comments
trafficstars

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

nicolasb29 avatar Feb 16 '24 16:02 nicolasb29

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.

timtebeek avatar Feb 16 '24 17:02 timtebeek

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.

nicolasb29 avatar Feb 16 '24 18:02 nicolasb29

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

  • https://github.com/openrewrite/rewrite/pull/4098

timtebeek avatar May 08 '24 08:05 timtebeek