Skip to content

fix(gitlab): write nested maps as blocks only where the schema declares one - #26

Open
jccguimaraes wants to merge 1 commit into
mainfrom
fix-gitlab-nested-blocks
Open

fix(gitlab): write nested maps as blocks only where the schema declares one#26
jccguimaraes wants to merge 1 commit into
mainfrom
fix-gitlab-nested-blocks

Conversation

@jccguimaraes

Copy link
Copy Markdown
Contributor

Closes #23.

writeGenericMap decided block-vs-attribute from the value's shape — any nested map became an HCL block. The schema in provider/gitlab/config.go declares several of those keys as hcl.Expression, so the output did not parse:

  • cache.key as a map (the key: files: form)
  • services[].variables
  • default.retry as a map
  • include.inputs (CI components)

each failing with Blocks of type "..." are not expected here.

The writer now reads block names off the hcl tags and carries the matching schema down as it descends, so the decision comes from the same place the parser's does. artifacts.reports still writes as a block — that is what its hcl:",remain" body declares. A top-level key outside the schema keeps the permissive behaviour, since there is nothing to check it against.

Templates had the mirror bug: their bodies went through the generic writer too, which wrote rules as an attribute (An argument named "rules" is not expected here) because the value was a list rather than a map. A template body is a job body, so it now goes through writeJobBlock, which already handles rule, cache, artifacts and service.

Five of the six subtests verified to fail against the previous code. The sixth (artifacts.reports) passes both ways on purpose — it guards against over-correcting the keys that were already right.

…es one

writeGenericMap turned every nested map into an HCL block, guessing from the
value's shape. The schema in config.go declares several of those keys as
attributes, so the HCL that came out did not parse: cache.key as a map,
services[].variables, default.retry as a map, and include.inputs all failed
with "Blocks of type ... are not expected here".

Read the block names off the hcl tags instead, and pass the matching schema
down as the writer descends. artifacts.reports keeps its block form, which is
what its `hcl:",remain"` body declares.

Template bodies had the mirror problem: written by the generic writer, their
rule blocks came out as a "rules" attribute. A template body is a job body, so
write it with writeJobBlock.

Closes #23
@github-actions

Copy link
Copy Markdown
Go test coverage: 66.6% for commit 9e14eea
⚠️ 1 of 20 packages have zero coverage.
  • github.com/yldio/cinzel/internal/test
View coverage for all packages
# Package Name                                     | Coverage
+ github.com/yldio/cinzel                          |    80.0%
+ github.com/yldio/cinzel/internal/ai              |    46.8%
+ github.com/yldio/cinzel/internal/cinzelerror     |    18.2%
+ github.com/yldio/cinzel/internal/command         |    39.5%
+ github.com/yldio/cinzel/internal/filereader      |    50.0%
+ github.com/yldio/cinzel/internal/filewriter      |    88.9%
+ github.com/yldio/cinzel/internal/fsutil          |    68.0%
+ github.com/yldio/cinzel/internal/hclparser       |    63.7%
+ github.com/yldio/cinzel/internal/maputil         |    93.3%
+ github.com/yldio/cinzel/internal/naming          |    93.1%
+ github.com/yldio/cinzel/internal/pin             |    54.8%
- github.com/yldio/cinzel/internal/test            |     0.0%
+ github.com/yldio/cinzel/internal/yamldoc         |    77.4%
+ github.com/yldio/cinzel/internal/yamlwriter      |    88.9%
+ github.com/yldio/cinzel/provider/github          |    70.9%
+ github.com/yldio/cinzel/provider/github/action   |    76.9%
+ github.com/yldio/cinzel/provider/github/job      |    95.0%
+ github.com/yldio/cinzel/provider/github/step     |    71.7%
+ github.com/yldio/cinzel/provider/github/workflow |    85.1%
+ github.com/yldio/cinzel/provider/gitlab          |    67.9%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gitlab: nested maps in cache, service and default are written as blocks the parser rejects

1 participant