Skip to content

Conversation

@theakshaypant
Copy link
Contributor

@theakshaypant theakshaypant commented Nov 12, 2025

📝 Description of the Change

Allow custom parameters from Repository CR to be accessed directly as CEL variables without template expansion. Parameters can now be used as: param_name == "value" on top of "{{param_name}}" == "value".

👨🏻‍ Linked Jira

https://issues.redhat.com/browse/SRVKP-9118

🔗 Linked GitHub Issue

N/A

🚀 Type of Change

  • 🐛 Bug fix (fix:)
  • ✨ New feature (feat:)
  • 💥 Breaking change (feat!:, fix!:)
  • 📚 Documentation update (docs:)
  • ⚙️ Chore (chore:)
  • 💅 Refactor (refactor:)
  • 🔧 Enhancement (enhance:)
  • 📦 Dependency update (deps:)

🧪 Testing Strategy

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

🤖 AI Assistance

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

If you have used AI assistance, please provide the following details:

Which LLM was used?

  • GitHub Copilot
  • ChatGPT (OpenAI)
  • Claude (Anthropic)
  • Cursor
  • Gemini (Google)
  • Other: ____________

Extent of AI Assistance:

  • Documentation and research only
  • Unit tests or E2E tests only
  • Code generation (parts of the code)
  • Full code generation (most of the PR)
  • PR description and comments
  • Commit message(s)

Important

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: Gemini [email protected]
Co-authored-by: ChatGPT [email protected]
Co-authored-by: Claude [email protected]
Co-authored-by: Cursor [email protected]
Co-authored-by: Copilot [email protected]

**💡You can use the script ./hack/add-llm-coauthor.sh to automatically add
these co-author trailers to your commits.

✅ 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

@pipelines-as-code
Copy link

pipelines-as-code bot commented Nov 12, 2025

🔍 PR Lint Feedback

Note: This automated check helps ensure your PR follows our contribution guidelines.

⚠️ Items that need attention:

🤖 AI attribution

The following commits lack an explicit AI attribution footer:

  • 354354e feat(cel): add direct custom param variable access in expressions

If no AI assistance was used for a commit, you can ignore this warning.
Otherwise add an Assisted-by: or Co-authored-by: footer referencing the AI used.


ℹ️ Next Steps

  • Review and address the items above
  • Push new commits to update this PR
  • This comment will be automatically updated when issues are resolved
🔧 Admin Tools (click to expand)

Automated Issue/Ticket Creation:

  • /issue-create - Generate a GitHub issue from this PR content using AI
  • /jira-create - Create a SRVKP Jira ticket from this PR content using AI

⚠️ Important: Always review and edit generated content before finalizing tickets/issues.
The AI-generated content should be used as a starting point and may need adjustments.

These commands are available to maintainers and will post the generated content as PR comments for review.

🤖 This feedback was generated automatically by the PR CI system

Copy link
Contributor Author

@theakshaypant theakshaypant left a comment

Choose a reason for hiding this comment

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

TODO: Docs update

cel.Lib(celPac{vcx, ctx, event}),
conflictingVar := make(map[string]bool)
for k, v := range customParams {
// Don't overwrite standard params
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Want to confirm if we want this behaviour. Modeled it on this

for k := range customParams {
// Don't overwrite standard params
if _, ok := conflictingVar[k]; !ok {
customParamDecls = append(customParamDecls, decls.NewVariable(k, types.StringType))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All variables are used as strings, do we want them to be DynType?

@theakshaypant
Copy link
Contributor Author

/gemini review

Copy link

@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 introduces a useful feature allowing custom parameters from the Repository CR to be accessed directly as CEL variables, which improves the usability of CEL expressions. The implementation looks solid, reusing existing logic for parameter resolution and safely adding the custom parameters to the CEL context. The test coverage for the new functionality is also comprehensive.

I have a couple of minor suggestions for code simplification and to improve clarity in one of the new tests.

@theakshaypant theakshaypant force-pushed the SRVKP-9118-fix-cel-custom-params branch from 3d13ed7 to 6e26664 Compare November 13, 2025 12:34
@pipelines-as-code pipelines-as-code bot added documentation Improvements or additions to documentation feature New feature or request labels Nov 13, 2025
@theakshaypant
Copy link
Contributor Author

/gemini review

Copy link

@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 introduces a great feature allowing direct access to custom parameters as CEL variables. The implementation is solid, and the documentation updates are clear. I've identified one important bug related to how parameters are resolved when target-namespace is used, and I've suggested a fix. I also have a couple of suggestions to improve logging for conflicting parameters and to enhance documentation consistency. Overall, great work!

Comment on lines +96 to +98
} else {
conflictingVar[k] = true
}

Choose a reason for hiding this comment

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

medium

When a custom parameter conflicts with a standard CEL variable (e.g., a user defines a parameter named event), it is silently ignored. This can be confusing for users and make debugging difficult.

It would be more user-friendly to log a warning when this happens. To do this, you would need to:

  1. Pass the logger from MatchPipelinerunByAnnotation into this celEvaluate function.
  2. Add a logging statement inside this else block, like:
    logger.Warnf("Custom parameter %q conflicts with a standard CEL variable and will be ignored", k)

@theakshaypant theakshaypant force-pushed the SRVKP-9118-fix-cel-custom-params branch from 6e26664 to 52e29ce Compare November 13, 2025 12:53
Allow custom parameters from Repository CR to be accessed directly as
CEL variables without template expansion. Parameters can now be used
as: param_name == "value" on top of "{{param_name}}" == "value".

Jira: https://issues.redhat.com/browse/SRVKP-9118

Signed-off-by: Akshay Pant <[email protected]>
@theakshaypant theakshaypant force-pushed the SRVKP-9118-fix-cel-custom-params branch from 52e29ce to 354354e Compare November 13, 2025 14:36
@theakshaypant theakshaypant changed the title feat(cel): add direct custom param variable access feat(cel): add direct custom param variable access in expressions Nov 13, 2025
@theakshaypant theakshaypant marked this pull request as ready for review November 14, 2025 02:16
Copy link
Member

@aThorp96 aThorp96 left a comment

Choose a reason for hiding this comment

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

This is looking good so far. Thanks! I haven't gone through it entirely yet; I had a couple questions/suggestions which might change the implementation approach

| `headers` | The full set of headers as passed by the Git provider. Example: `headers['x-github-event']` retrieves the event type on GitHub. |
| `.pathChanged` | A suffix function to a string that can be a glob of a path to check if changed. (Supported only for `GitHub` and `GitLab` providers.) |
| `files` | The list of files that changed in the event (`all`, `added`, `deleted`, `modified`, and `renamed`). Example: `files.all` or `files.deleted`. For pull requests, every file belonging to the pull request will be listed. |
| Custom params | Any [custom parameters]({{< relref "/docs/guide/customparams" >}}) defined in the Repository CR `spec.params` are available as CEL variables. Example: `enable_ci == "true"`. See [Using custom parameters in CEL matching expressions]({{< relref "/docs/guide/customparams#using-custom-parameters-in-cel-matching-expressions" >}}) for details. |
Copy link
Member

Choose a reason for hiding this comment

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

Since some custom params may not be available based on their filter, "any param defined" could be interpreted to suggest filters may not be applied in this case. I think "any param provided" is less absolute so is more aligned when a param doesn't match its filter. Maybe there is another word which would be clearer though?

Suggested change
| Custom params | Any [custom parameters]({{< relref "/docs/guide/customparams" >}}) defined in the Repository CR `spec.params` are available as CEL variables. Example: `enable_ci == "true"`. See [Using custom parameters in CEL matching expressions]({{< relref "/docs/guide/customparams#using-custom-parameters-in-cel-matching-expressions" >}}) for details. |
| Custom params | Any [custom parameters]({{< relref "/docs/guide/customparams" >}}) provided from the Repository CR `spec.params` are available as CEL variables. Example: `enable_ci == "true"`. See [Using custom parameters in CEL matching expressions]({{< relref "/docs/guide/customparams#using-custom-parameters-in-cel-matching-expressions" >}}) for details. |

Comment on lines +288 to +292
// Determine the effective repository for this PipelineRun
effectiveRepo := repo
if prMatch.Repo != nil {
effectiveRepo = prMatch.Repo
}
Copy link
Member

Choose a reason for hiding this comment

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

An event is repository-scoped, so as far as I know the repository should be the same across all pipelineruns in the prMatch. AFAICT prMatch.Repo can never be different within the same event unless the pipelinerun does not annotate a targetNamespace.

I believe the checks above are unnecessary as well, since the Repo is identified in all cases by the event's repository URL, and Repository CRs must all have unique URL.

In any case, I think this can be simplified by using repo instead of using an effectiveRepo which gets updated each loop.

Copy link
Contributor Author

@theakshaypant theakshaypant Nov 14, 2025

Choose a reason for hiding this comment

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

That was my original thought as well. After this comment, I modified my implementation. Would love to get your thoughts on this.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. I believe Gemini is BSing. AFAIK one event can only create pipelineruns for a single Repository CR, but I'll defer to @chmouel's understanding. I could be wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even Claude backed the comment so I decided to move to this version of getting an effective repo.

if cached, found := customParamsCache[cacheKey]; found {
customParams = cached
} else {
customParams = resolveCustomParamsForCEL(ctx, effectiveRepo, event, cs, vcx, eventEmitter, logger)
Copy link
Member

Choose a reason for hiding this comment

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

Since the Repository CR is specific to an event, we can evaluate the customParams at the top of the loop so we shouldn't need caching logic. Good thought to have the caching though, had the Repository CRs been dependent on the specific pipelinerun

Comment on lines +540 to +543
// resolveCustomParamsForCEL resolves custom parameters from the Repository CR for use in CEL expressions.
// It returns a map of parameter names to values, excluding reserved keywords.
// All parameters are returned as strings, including those from secret_ref.
func resolveCustomParamsForCEL(ctx context.Context, repo *apipac.Repository, event *info.Event, cs *params.Run, vcx provider.Interface, eventEmitter *events.EventEmitter, logger *zap.SugaredLogger) map[string]string {
Copy link
Member

Choose a reason for hiding this comment

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

Any reason we can't use customparams.NewCustomParams() directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, my thinking was influenced by this comment. Would be nice to get an experienced perspective.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry I think my original comment wasn't clear. I mean to ask: wherever we call resolveCustomParamsForCEL, would we not instead call customparams.NewCustomParams().GetParams()? It seems like these are very similar, but maybe I'm missing the difference

Copy link
Contributor Author

@theakshaypant theakshaypant Nov 17, 2025

Choose a reason for hiding this comment

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

Ah, sorry meant to have this reply on the earlier comment.
As for customparams.NewCustomParams(), it is used by resolveCustomParamsForCEL and then filters the params to only return the ones defined in the repo CR.

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

Labels

documentation Improvements or additions to documentation feature New feature or request repo-cr

Development

Successfully merging this pull request may close these issues.

2 participants