-
Story
-
Resolution: Unresolved
-
Normal
-
None
-
None
Story (Required)
As a developer using Pipelines-as-Code templates, I want to use `body.`, `headers.`, and `files.*` placeholders independently, so that my templates evaluate correctly even when some parts of the webhook context (like the body or headers) are not present.
The current templating logic incorrectly requires both the event body and headers to be available to process any event-related placeholders. This prevents valid placeholders, such as `{{ headers.X-GitHub-Event }}`, from being evaluated if the event body is nil. This change will make the templating evaluation more robust and intuitive for users by ensuring placeholders are evaluated based only on the context they require.
Background (Required)
The `ReplacePlaceHoldersVariables` function contains a condition that checks for the existence of both `rawEvent` and `headers` before attempting to evaluate any placeholders prefixed with `body.`, `headers.`, or `files.`. This strict check causes legitimate templating to fail. For example, a `{{ headers.field }}` placeholder will not be replaced if the event has no body, even though the header data is available.
This behavior was identified and fixed in the pull request: https://github.com/openshift-pipelines/pipelines-as-code/pull/2264(https://github.com/openshift-pipelines/pipelines-as-code/pull/2264)
Out of scope
- Introducing new placeholder types (e.g., `{{ new_context.* }}`).
- Changes to the underlying CEL (Common Expression Language) evaluation library.
Approach (Required)
The logic for placeholder replacement should be updated to evaluate each placeholder type based on its own data requirements, rather than a single, all-encompassing condition.
- `{{ body.* }}` placeholders should only require the `rawEvent` payload to be present.
- `{{ headers.* }}` placeholders should only require the `headers` map to be present.
- `{{ files.* }}` placeholders should be evaluated independently of `rawEvent` and `headers`.
Additionally, comprehensive unit tests must be added to verify the corrected behavior and cover various edge cases, such as nil inputs and different data types in the payload.
Dependencies
There are no known dependencies for this story.
Acceptance Criteria (Mandatory)
- [ ] GIVEN a template contains a `{{ body.field }}` placeholder, WHEN `rawEvent` is provided but `headers` are nil, THEN the placeholder is replaced successfully.
- [ ] GIVEN a template contains a `{{ headers.field }}` placeholder, WHEN `headers` are provided but `rawEvent` is nil, THEN the placeholder is replaced successfully.
- [ ] GIVEN a template contains a `{{ files.field }}` placeholder, WHEN both `rawEvent` and `headers` are nil, THEN the placeholder is replaced successfully.
- [ ] GIVEN a template contains a `{{ body.field }}` placeholder, WHEN `rawEvent` is nil, THEN the placeholder is not replaced.
- [ ] GIVEN a template contains a mix of `dico`, `body`, and `header` placeholders, WHEN all corresponding data is provided, THEN all placeholders are correctly evaluated.
- [ ] Unit test coverage for the templating logic is significantly improved.