Support for nested ymlv-config
RickardCardell opened this issue · 4 comments
I would like to request support for more complex structures in the ymlv-config.
Currently the config in an ymlv-file may be a list of maps:
---
- project: MYTEAM
repo: my_repo
has_ci: true
- project: MYTEAM
repo: best_cat_pics
has_ci: false
However, it's not uncommon to have a more nested structure. E.g one want to define multiple webhooks for a repo:
- repo: "foobar"
webhooks:
- name: "on-merge"
events:
- name: "pr:merged"
- name: "repo:refs-Changed"
- name: "on-commit"
events:
- name: "pr:merged"
- name: "repo:som-event"
Current behavior:
escript: exception error: no function clause matching
bec_yml:to_mustache([#{<<"events">> =>
[#{<<"name">> => <<"pr:merged">>},
#{<<"name">> =>
<<"repo:refs-Changed">>}],
<<"name">> => <<"on-merge">>},
#{<<"events">> =>
[#{<<"name">> => <<"pr:merged">>},
#{<<"name">> =>
<<"repo:som-event">>}],
<<"name">> => <<"on-commit">>}]) (dev/github/klarna-incubator/bec/src/bec_yml.erl, line 33)
in function bitbucket_repo_config:'-read_vars/1-fun-1-'/3 (dev/github/klarna-incubator/bec/src/bitbucket_repo_config.erl, line 56)
in call from maps:fold_1/3 (maps.erl, line 411)
in call from lists:map/2 (lists.erl, line 1315)
in call from bitbucket_repo_config:verify/2 (dev/github/klarna-incubator/bec/src/bitbucket_repo_config.erl, line 28)
in call from bec:do_main/1 (dev/github/klarna-incubator/bec/src/bec.erl, line 51)
´´´
This isn't an enhancement, this is a bug. Having multiple webhooks is already supported, but the code which invokes the templating engine does not seem to work correctly with multiple webhooks.
This doesn't have to do with just webhooks. The templating should support any yaml content since that is what Mustache would support if I understand it correctly.
I agree, the bug is very likely unrelated to webhooks.
After investigating some, it seems like Mustache doesn't support inserting arbitrary yaml terms. It can only insert strings {{ name }}
, booleans {{#name}} ... {{/name}}
, and lists {{#name}} ... {{item}} ... {{/name}}
.
I think the only way to have different set of webhooks is to use separate template files.