m-khvoinitsky / workflow-templater

Template engine for (currently) Jira and Email. Uses yaml and jinja2. It helps you create multiple (possibly cross-liked) jira issues and emails from a template.
MIT License
6 stars 3 forks source link

Issue defaults fields #1

Open dmfs opened 3 years ago

dmfs commented 3 years ago

Often times, all the issues of a workflow share some common fields. For instance, in the example all issues have the same project and labels. How about a defaults file which contains fields which are applied to all issues (unless it has been overridden in the issue). This way we don't have to add those fields to every file.

m-khvoinitsky commented 3 years ago

I don't like the idea of "implicit defaults" (which you have described) at least for the following reasons:

But the general idea about reducing copy-paste is great but I would rather prefer "explicit defaults", for example, using YAML anchors:

defaults: &somecommonfields
  project:
    key: TEST1234
...
<< : *somecommonfields

The example above works in regular YAML but only inside one file which is quite useless in our case. It would be great if it was possible to load anchors from one file ("defaults" file) and use it in all the rest. The implementation would require digging into YAML parser. So, if you have ideas on how to implement it (and, preferably, future-proof from changes in internal ruamel.yaml API), I would be happy to merge Pull Request.

dmfs commented 3 years ago

Right, I had similar thoughts and I agree that explicit defaults are a better way to go. Right after I opened the issue I tried using a Jinja include like so:

{% include 'defaults.yaml' %}
summary: …

only to realize that Jinja is applied to the values after parsing the YAML file.

Evaluating the Jinja template before parsing the YAML file could allow for more flexibility. The downside is that syntax highlighting wouldn't work anymore and the structure might become more complex and harder to get right.

Another option would be another special key like include:

include: project_defaults.yaml
summary: …