-
Notifications
You must be signed in to change notification settings - Fork 116
feat(cel): add direct custom param variable access in expressions #2320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(cel): add direct custom param variable access in expressions #2320
Conversation
🔍 PR Lint Feedback
|
There was a problem hiding this 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 |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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?
|
/gemini review |
There was a problem hiding this 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.
3d13ed7 to
6e26664
Compare
|
/gemini review |
There was a problem hiding this 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!
| } else { | ||
| conflictingVar[k] = true | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
- Pass the
loggerfromMatchPipelinerunByAnnotationinto thiscelEvaluatefunction. - Add a logging statement inside this
elseblock, like:
logger.Warnf("Custom parameter %q conflicts with a standard CEL variable and will be ignored", k)
6e26664 to
52e29ce
Compare
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]>
52e29ce to
354354e
Compare
aThorp96
left a comment
There was a problem hiding this 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. | |
There was a problem hiding this comment.
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?
| | 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. | |
| // Determine the effective repository for this PipelineRun | ||
| effectiveRepo := repo | ||
| if prMatch.Repo != nil { | ||
| effectiveRepo = prMatch.Repo | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
| // 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
📝 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
fix:)feat:)feat!:,fix!:)docs:)chore:)refactor:)enhance:)deps:)🧪 Testing Strategy
🤖 AI Assistance
If you have used AI assistance, please provide the following details:
Which LLM was used?
Extent of AI Assistance:
Important
If the majority of the code in this PR was generated by an AI, please add a
Co-authored-bytrailer 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.shto automatically addthese co-author trailers to your commits.
✅ Submitter Checklist
fix:,feat:) matches the "Type of Change" I selected above.make testandmake lintlocally to check for and fix anyissues. For an efficient workflow, I have considered installing
pre-commit and running
pre-commit installtoautomate these checks.