openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.15k stars 322 forks source link

DeleteKey removed workflow_dispatch in `.github/workflows/ci.yml` #1175

Closed aegershman closed 2 years ago

aegershman commented 2 years ago

Problem

Describe the issue you are experiencing.

Configured DeleteKey with $.jobs.build.strategy.fail-fast, and it appears to have removed workflow_dispatch. But it did remove fail-fast as expected.

Expected behavior

Describe what you expected to see.

Not having workflow_dispatch removed. Also note how it shifted {} next to main, which is interesting.

Example diff

       - "*"
   pull_request:
     branches:
-      - main
-  workflow_dispatch: {}
+      - main {}
   schedule:
     - cron: "0 18 * * *"

 jobs:
   build:
     strategy:
-      fail-fast: false
       matrix:
         java: ["11"]
         os: ["ubuntu-latest"]

Recipes in example diff:

References:

aegershman commented 2 years ago

Note, this appears to be because removeUnused() is called over the whole file. Which means "unused" keys, such as workflow_dispatch: {} will be removed, even though they are not part of the original scope of what was intended to be removed.

traceyyoshima commented 2 years ago

Update: The {} shifts because the yaml flow style is not supported yet.

The mapping is removed by removeUnused(). The removeUnused is not constrained to a parent yaml, and applies to each entry.