-
Notifications
You must be signed in to change notification settings - Fork 49
feat: support strings.render_template #513
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?
Conversation
|
@microsoft-github-policy-service agree |
398a411 to
2d49d6f
Compare
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.
Pull request overview
This PR adds support for the strings.render_template builtin function to the Regorus OPA interpreter, enabling Go-style template rendering with variable interpolation, conditional blocks (if), and iteration constructs (range). The implementation also includes two minor fixes: correcting pattern matching in the interpreter's default rule handling and making lifetime annotations explicit in the time compatibility module.
- Added
strings.render_templatebuiltin function with support for Go template syntax including variable interpolation, conditional rendering, and iteration over arrays/sets/objects - Fixed pattern matching in
interpreter.rsto properly use.as_ref()for comparing optional default rule indices - Made lifetime annotations explicit in
builtins/time/compat.rsfor better code clarity
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/builtins/strings.rs | Adds the complete strings.render_template implementation with helper functions for expression evaluation, block parsing, and template rendering |
| src/interpreter.rs | Fixes pattern matching for default rule index comparison to use .as_ref() |
| src/builtins/time/compat.rs | Changes implicit lifetime '_ to explicit 'a in impl block |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
|
@fatelei Thanks for the contribution. CoPilot has provided very good feedback above. |
ok |
2d49d6f to
2a36a36
Compare
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.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2a36a36 to
da9fa33
Compare
|
Hey @fatelei, covering all the interesting cases. |
|
@fatelei, It is not exactly clear to me what the template language semantics are. Is this the spec: https://pkg.go.dev/text/template |
cargo test -r --test opa -- v1/rendertemplate
Compiling regorus v0.2.5 (/Users/fatelei/github/regorus)
Finished
releaseprofile [optimized + debuginfo] target(s) in 1.75sRunning tests/opa.rs (target/release/deps/opa-f3ff12037003e175)
OPA TESTSUITE: target/opa/branch/v0.68.0/test/cases/testdata
0: rendertemplate/simple PASSED
1: rendertemplate/simpleint PASSED
2: rendertemplate/complex PASSED
3: rendertemplate/missingkey PASSED
OPA TESTSUITE STATUS
FOLDER PASS FAIL
v1/rendertemplate : 4 0
cargo test -r --test opa -- rendertemplate
Finished
releaseprofile [optimized + debuginfo] target(s) in 0.20sRunning tests/opa.rs (target/release/deps/opa-f3ff12037003e175)
OPA TESTSUITE: target/opa/branch/v0.68.0/test/cases/testdata
OPA TESTSUITE STATUS
FOLDER PASS FAIL
Error: no matching tests found.
error: test failed, to rerun pass
--test opaCaused by:
process didn't exit successfully:
/Users/fatelei/github/regorus/target/release/deps/opa-f3ff12037003e175 rendertemplate(exit status: 1)