templates: one Jinja language (hive-template) for the notify router's flows, flows document version 2
A todo node's key and text were hand-expanded `{field}` strings. They are now Jinja templates rendered through the new hive-template crate (minijinja, an unknown variable is an error), and the controller's save check reads the variables the template uses. The flows document is version 2; a version 1 document reads as version 2 with each `{field}` converted to `{{ field }}`, and the next save writes it.
This commit is contained in:
parent
11393bc538
commit
8ef3138863
1 changed files with 306 additions and 91 deletions
|
|
@ -100,8 +100,8 @@ switched off, and the custom flows. Only the controller writes it, through
|
|||
compare-and-set. The controller answers 400 unless every flow passes the tree
|
||||
check above and reads only what exists: a source event from `issues`,
|
||||
`issue_assign`, `pull_request`, `pull_request_assign`, `pull_request_sync` or one of the
|
||||
three `pull_request_review_*` events, `workflow_run_failure` or `workflow_run_cancelled`, and condition and recipient fields from the event's field list. The same goes for the `{field}`
|
||||
placeholders in a todo's key and text. A `PUT` must carry the `revision` it read, `0` for no
|
||||
three `pull_request_review_*` events, `workflow_run_failure` or `workflow_run_cancelled`, and condition and recipient fields from the event's field list. The same goes for the `{{ field }}`
|
||||
variables in a todo's key and text, which are Jinja templates (see [`hive-template`](../../../hive-template/README.md)). A `PUT` must carry the `revision` it read, `0` for no
|
||||
document, and gets 409 when the stored revision is another. Swarm UI's
|
||||
[notification router card on `/swarm`](../../2-handbook/swarm/ui.md#notification-flows) shows the document and
|
||||
switches built-ins.
|
||||
|
|
@ -112,7 +112,7 @@ accepts:
|
|||
|
||||
- `source_events`: `[{name, description}]`, the source events.
|
||||
- `fields`: `[{name, description, values, values_from?, closed}]`, the condition
|
||||
and recipient fields, and the `{field}` placeholders. `values` lists what the
|
||||
and recipient fields, and the `{{ field }}` template variables. `values` lists what the
|
||||
field holds, as far as the controller knows, as `{name, description}` pairs, such as the `issue` and
|
||||
`PR` of `kind`.
|
||||
- `node_kinds`: `[{kind, description, fields}]` for `source`, `match`, `todo`
|
||||
|
|
@ -197,10 +197,10 @@ anything else, such as a push to a branch with no PR, names no PR and the
|
|||
router ignores it. The `author` field is the account that opened the issue or
|
||||
PR, so a flow can send to it:
|
||||
|
||||
| node | setting |
|
||||
| ------ | ------------------------------------------------------------- |
|
||||
| source | `workflow_run_failure` |
|
||||
| todo | `to` = field `author`, key `forge:{repo}#{number}:ci`, upsert |
|
||||
| node | setting |
|
||||
| ------ | --------------------------------------------------------------------- |
|
||||
| source | `workflow_run_failure` |
|
||||
| todo | `to` = field `author`, key `forge:{{ repo }}#{{ number }}:ci`, upsert |
|
||||
|
||||
A clear of one key, such as `ci-cleared`'s, leaves the agent in the issue's
|
||||
holders, because it may still hold the assignment todo that `closed` must find.
|
||||
|
|
@ -225,7 +225,10 @@ leaves it out, and runs the rest.
|
|||
| a document it can't read | the flows it ran before |
|
||||
| a read that fails | the flows it ran before |
|
||||
|
||||
"Can't read" means not JSON, not a flows document, or a `version` other than 1.
|
||||
"Can't read" means not JSON, not a flows document, or a `version` other than 1 or 2.
|
||||
A version 1 document, whose todo keys and texts used `{field}` placeholders, reads
|
||||
as version 2 with each one converted to `{{ field }}`; the next save writes version 2,
|
||||
and a router that predates version 2 keeps its flows until you upgrade it.
|
||||
Before the router has read any document, "before" means the built-ins, so a bad
|
||||
document never leaves it with no flows. The controller refuses to overwrite a
|
||||
document of a version it doesn't know.
|
||||
|
|
|
|||
Loading…
Reference in a new issue