klarna / bec

The BitBucket Erlang Client
Apache License 2.0
47 stars 12 forks source link

Support for nested ymlv-config #63

Closed RickardCardell closed 1 year ago

RickardCardell commented 1 year ago

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)
  ´´´
jesperes commented 1 year ago

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.

thomasplarsson commented 1 year ago

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.

jesperes commented 1 year ago

I agree, the bug is very likely unrelated to webhooks.

jesperes commented 1 year ago

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.