fix(gitlab): write nested maps as blocks only where the schema declares one - #26
Open
jccguimaraes wants to merge 1 commit into
Open
fix(gitlab): write nested maps as blocks only where the schema declares one#26jccguimaraes wants to merge 1 commit into
jccguimaraes wants to merge 1 commit into
Conversation
…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
Go test coverage: 66.6% for commit 9e14eea
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #23.
writeGenericMapdecided block-vs-attribute from the value's shape — any nested map became an HCL block. The schema inprovider/gitlab/config.godeclares several of those keys ashcl.Expression, so the output did not parse:cache.keyas a map (thekey: files:form)services[].variablesdefault.retryas a mapinclude.inputs(CI components)each failing with
Blocks of type "..." are not expected here.The writer now reads block names off the
hcltags and carries the matching schema down as it descends, so the decision comes from the same place the parser's does.artifacts.reportsstill writes as a block — that is what itshcl:",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
rulesas 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 throughwriteJobBlock, which already handlesrule,cache,artifactsandservice.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.