You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit introduces a new command `tkn pac cel` that allows
users to interactively evaluate CEL (Common Expression Language)
expressions. The command is designed to help users test and debug
CEL expressions, which are commonly used in Pipelines-as-Code.
Key features include:
- Interactive and non-interactive modes.
- Support for webhook payloads and headers.
- Provider auto-detection (GitHub, GitLab, Bitbucket Cloud,
Bitbucket Data Center, Gitea).
- Direct access to variables as per PAC documentation.
- Cross-platform history with readline experience.
- Comprehensive help and example expressions.
Note: this evaluator is primarily intended for repository or GitHub app
admins, as it requires access to webhook payloads and headers.
Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
Copy file name to clipboardExpand all lines: docs/content/docs/guide/cli.md
+108Lines changed: 108 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -409,6 +409,114 @@ You can specify a different directory than the current one by using the -d/--dir
409
409
410
410
{{< /details >}}
411
411
412
+
{{< details "tkn pac cel" >}}
413
+
414
+
### CEL Expression Evaluator
415
+
416
+
{{< hint danger >}}
417
+
The CEL evaluator is only useful for admins, since the payload and headers as seen by Pipelines-as-Code needs to be provided and is only available to the repository or GitHub app admins.
418
+
{{< /hint >}}
419
+
`tkn pac cel` — Evaluate CEL (Common Expression Language) expressions interactively with webhook payloads.
420
+
421
+
This command allows you to test and debug CEL expressions as they would be evaluated by Pipelines-as-Code, using real webhook payloads and headers. It supports interactive and non-interactive modes, provider auto-detection, and persistent history.
422
+
423
+
To be able to have the CEL evaluator working, you need to have the payload and the headers available in a file. The best way to do this is to go to the webhook configuration on your git provider and copy the payload and headers to different files.
424
+
425
+
The payload is the JSON content of the webhook request, The headers file supports multiple formats:
426
+
427
+
1.**Plain HTTP headers format** (as shown above)
428
+
2.**JSON format**:
429
+
430
+
```json
431
+
{
432
+
"X-GitHub-Event": "pull_request",
433
+
"Content-Type": "application/json",
434
+
"User-Agent": "GitHub-Hookshot/2d5e4d4"
435
+
}
436
+
```
437
+
438
+
3.**Gosmee-generated shell scripts**: The command automatically detects and parses shell scripts generated by [gosmee](https://github.com/chmouel/gosmee) which are generated when using the `--save` feature, extracting headers from curl commands with `-H` flags:
439
+
440
+
```bash
441
+
#!/usr/bin/env bash
442
+
curl -X POST "http://localhost:8080/" \
443
+
-H "X-GitHub-Event: pull_request" \
444
+
-H "Content-Type: application/json" \
445
+
-H "User-Agent: GitHub-Hookshot/2d5e4d4" \
446
+
-d @payload.json
447
+
```
448
+
449
+
#### Usage
450
+
451
+
```shell
452
+
tkn pac cel -b <body.json> -H <headers.txt>
453
+
```
454
+
455
+
*`-b, --body`: Path to JSON body file (webhook payload)
456
+
*`-H, --headers`: Path to headers file (plain text, JSON, or gosmee script)
0 commit comments