feat(cel): add fold support#156
Conversation
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThis PR introduces CEL fold functionality with two independent changes: a new fold library for CEL expressions supporting list and map aggregation patterns, plus documentation examples; and removal of the disabled goconst linter configuration. ChangesCEL Fold Feature
Linter Configuration Cleanup
Sequence DiagramsequenceDiagram
participant User as User Code
participant Parser as CEL Parser
participant Macro as Fold Macro
participant Comp as CEL Comprehension
participant Helpers as Runtime Helpers
participant Result as Result
User->>Parser: fold(items, acc, expr)
Parser->>Macro: Invoke fold macro
Macro->>Macro: Extract identifiers & validate
Macro->>Helpers: foldInitialValue(items)
Helpers->>Result: Return seed value
Macro->>Comp: Generate comprehension<br/>with step expression
Comp->>Helpers: Call merge() or<br/>accumulator update
Helpers->>Comp: Return new accumulator
Comp->>Comp: Iterate over items
Comp->>Result: Final accumulator value
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 0/1 reviews remaining, refill in 54 minutes and 17 seconds.Comment |
|
|
||
| out, err := gomplate.RunExpression(map[string]any{ | ||
| "tags": []map[string]any{ | ||
| {"key": "application", "value": "IIAB"}, |
There was a problem hiding this comment.
| {"key": "application", "value": "IIAB"}, | |
| {"key": "application", "value": "ACME"}, |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cel_fold.go`:
- Around line 109-112: The temporary fold entry name generation (entryVar) in
cel_fold.go currently only tries a single fallback "__fold_entry2__" and can
still collide with user vars; change the logic that sets entryVar so it
iteratively picks a name that does not conflict with keyVar, valVar, or accuVar
(e.g., "__fold_entry__", "__fold_entry2__", "__fold_entry3__", ...) by
looping/incrementing a suffix until an unused name is found; update any code
that references entryVar to use the chosen unique name.
- Around line 152-157: The code currently picks the fold seed by using
m.Iterator() and taking the first iteration result (it.HasNext()/it.Next()),
which is nondeterministic for Go maps; change foldInitialValue logic to select
the seed deterministically by enumerating map keys (use m.Keys() or collect
entries), convert keys to a stable sortable representation (e.g., string form),
sort them, pick the first sorted key, and then call m.Get(firstKey) to set
first; keep the same conversion to types.DefaultTypeAdapter.NativeToValue(nil)
where needed and update any references to first and foldInitialValue
accordingly.
- Around line 180-182: The comparator used in sort.SliceStable(keys, ...) is not
a total order because it only compares fmt.Sprint(keys[i].Value()) —
different-typed values like int(1) and string("1") stringify the same and can
leave the order undefined; update the comparator for the keys slice (the
sort.SliceStable call) to produce a total ordering by incorporating the value
type before the stringified value (for example using the value's concrete type
name or a type-tag plus the printed value via reflect.TypeOf or
fmt.Sprintf("%T:%v")) so that items with equal printed forms but different types
are ordered deterministically.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cdc9cc48-a9d3-40e9-87e5-07bce712f179
📒 Files selected for processing (5)
.golangci.ymlCEL.mdcel.gocel_fold.gotests/cel_test.go
💤 Files with no reviewable changes (1)
- .golangci.yml
Summary by CodeRabbit
Release Notes
New Features
Documentation
Tests