Skip to content

feat(cel): enable string and list extension functions in CEL expressions#2725

Open
zakisk wants to merge 1 commit into
tektoncd:mainfrom
zakisk:SRVKP-11940-support-string-ops-in-cel
Open

feat(cel): enable string and list extension functions in CEL expressions#2725
zakisk wants to merge 1 commit into
tektoncd:mainfrom
zakisk:SRVKP-11940-support-string-ops-in-cel

Conversation

@zakisk
Copy link
Copy Markdown
Member

@zakisk zakisk commented May 13, 2026

📝 Description of the Change

Previously, CEL expressions in Pipelines-as-Code only had access to the core CEL operators, which limited users to basic comparisons and logical expressions. Functions like join(), replace(), substring(), and other string/list manipulation operations were unavailable, forcing users to work around these limitations.

This adds cel-go's ext.Strings() and ext.Lists() extensions to the CEL environment in pkg/cel/cel.go. This unlocks the full set of standard CEL string operations (join, replace, substring, split, trim, upperAscii, lowerAscii, etc.) and list operations, which can be used in both on-cel-expression annotations and {{ cel: }} template expressions.

Changes:

  • pkg/cel/cel.go: Register ext.Strings() and ext.Lists() extensions on the CEL environment alongside existing variable declarations
  • pkg/templates/templating_test.go: Add unit tests for join(), replace(), and substring() via the template placeholder path; improve test failure message to show actual vs expected values
  • test/testdata/pipelinerun-cel-string-join.yaml: New e2e test fixture that uses files.all.join(", ") in a cel: template
  • test/github_pullrequest_test.go: Add GHE e2e test (TestGithubGHEPullRequestCELJoin) that verifies join() works end-to-end by checking the PipelineRun pod log output matches the expected changed file path

Note: The e2e test uses regex matching (empty goldenFile param) rather than golden file comparison, since the output is a single dynamic file path that varies per test run.

🔗 Linked GitHub Issue

Fixes #

JIRA

https://redhat.atlassian.net/browse/SRVKP-11940

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

🤖 AI Assistance

AI assistance can be used for various tasks, such as code generation,
documentation, or testing.

Please indicate whether you have used AI assistance
for this PR and provide details if applicable.

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

Important

Slop will be simply rejected, if you are using AI assistance you need to make sure you
understand the code generated and that it meets the project's standards. you
need at least know how to run the code and deploy it (if needed). See
startpaac to make it easy
to deploy and test your code changes.

If the majority of the code in this PR was generated by an AI, please add a Co-authored-by trailer to your commit message.
For example:

Co-authored-by: Claude noreply@anthropic.com

✅ Submitter Checklist

  • 📝 My commit messages are clear, informative, and follow the project's How to write a git commit message guide. The Gitlint linter ensures in CI it's properly validated
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • ♽ I have run make test and make lint locally to check for and fix any
    issues. For an efficient workflow, I have considered installing
    pre-commit and running pre-commit install to
    automate these checks.
  • 📖 I have added or updated documentation for any user-facing changes.
  • 🧪 I have added sufficient unit tests for my code changes.
  • 🎁 I have added end-to-end tests where feasible. See README for more details.
  • 🔎 I have addressed any CI test flakiness or provided a clear reason to bypass it.
  • If adding a provider feature, I have filled in the following and updated the provider documentation:
    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

Previously, CEL expressions in Pipelines-as-Code only had access to
the core CEL operators, which limited users to basic comparisons and
logical expressions. Functions like join(), replace(), substring(),
and other string/list manipulation operations were unavailable,
forcing users to work around these limitations.

This adds cel-go's ext.Strings() and ext.Lists() extensions to the
CEL environment in pkg/cel/cel.go. This unlocks the full set of
standard CEL string operations (join, replace, substring, split,
trim, upperAscii, lowerAscii, etc.) and list operations, which can
be used in both `on-cel-expression` annotations and `{{ cel: }}`
template expressions.

Changes:
- pkg/cel/cel.go: Register ext.Strings() and ext.Lists() extensions
  on the CEL environment alongside existing variable declarations
- pkg/templates/templating_test.go: Add unit tests for join(),
  replace(), and substring() via the template placeholder path;
  improve test failure message to show actual vs expected values
- test/testdata/pipelinerun-cel-string-join.yaml: New e2e test
  fixture that uses files.all.join(", ") in a cel: template
- test/github_pullrequest_test.go: Add GHE e2e test
  (TestGithubGHEPullRequestCELJoin) that verifies join() works
  end-to-end by checking the PipelineRun pod log output matches
  the expected changed file path

Note: The e2e test uses regex matching (empty goldenFile param)
rather than golden file comparison, since the output is a single
dynamic file path that varies per test run.

Signed-off-by: Zaki Shaikh <zashaikh@redhat.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.28%. Comparing base (c615efb) to head (1aa9629).
⚠️ Report is 2 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2725      +/-   ##
==========================================
+ Coverage   59.25%   59.28%   +0.02%     
==========================================
  Files         208      208              
  Lines       20573    20593      +20     
==========================================
+ Hits        12191    12209      +18     
- Misses       7610     7612       +2     
  Partials      772      772              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enables CEL string and list extensions to support operations like join, replace, and substring, and includes corresponding unit and E2E tests. The reviewer noted that the go.mod file contains redundant direct dependencies on both v84 and v85 of go-github and requested that the test failure message modification be reverted to maintain helpful diff output.

Comment thread go.mod
github.com/google/cel-go v0.28.0
github.com/google/go-cmp v0.7.0
github.com/google/go-github/scrape v0.0.0-20260403152401-96a365122246
github.com/google/go-github/v84 v84.0.0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Having both v84 and v85 of github.com/google/go-github as direct dependencies is redundant and can lead to dependency conflicts. Please remove the unused version.

got := ReplacePlaceHoldersVariables(tt.template, tt.dicto, tt.rawEvent, tt.headers, tt.changedFiles)
if d := cmp.Diff(got, tt.expected); d != "" {
t.Fatalf("-got, +want: %v", d)
t.Fatalf("-got %s, +want: %s", got, tt.expected)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The test failure message was modified to remove the diff output (d). Using cmp.Diff and printing the diff is standard practice for test debugging and should be preserved.

Suggested change
t.Fatalf("-got %s, +want: %s", got, tt.expected)
t.Fatalf("-got, +want: %v", d)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants