-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: for each loops #911
feat: for each loops #911
Conversation
f4a496d
to
a6a7c1d
Compare
@zolamk I need some time to go over these changes. Please bare with me. |
Pull request is not up to date with the base branch. Reviewpad will rebase it. After the rebase, please trigger Reviewpad by running the command |
/reviewpad summarize |
…emporary variables
…sed to teams and groups built-ins
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.
Some minor tweaks - the big issue is that we need variable scoping.
The following program will "break":
groups:
- name: test1
spec: '["team1", "team2"]'
- name: test2
spec: '["team3", "team4"]'
workflows:
- name: test
run:
- forEach:
value: $teamName
in: $group("test1")
do:
- forEach:
value: $teamName
in: $group("test2")
do: $addLabel($teamName)
- $addLabel($teamName)
Pull request is not up to date with the base branch. Reviewpad will rebase it. After the rebase, please trigger Reviewpad by running the command |
engine/exec.go
Outdated
if run.ForEach != nil { | ||
var executedActions []string | ||
|
||
value, err := interpreter.ProcessList(run.ForEach.In) | ||
if err != nil { | ||
return ExitStatusFailure, nil, err | ||
} | ||
|
||
// create a new execution scope for the for-each block | ||
// so that the temporary variables are not shadowed | ||
scopedInterpreter := interpreter.NewExecutionScope() | ||
|
||
for _, val := range value.(*lang.ArrayValue).Vals { | ||
scopedInterpreter.StoreTemporaryVariable(run.ForEach.Value, val) | ||
|
||
exitStatus, forEachActions, err := execStatementBlock(scopedInterpreter, run.ForEach.Do, rules) | ||
executedActions = append(executedActions, forEachActions...) | ||
if err != nil { | ||
return exitStatus, executedActions, err | ||
} | ||
} | ||
|
||
return ExitStatusSuccess, executedActions, nil | ||
} | ||
|
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.
/reviewpad explain
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 code block is a part of the evaluation and execution of the workflows defined in the configuration file. The specific part you highlighted is responsible for handling the forEach
construct within the workflow run block. It iterates over the values specified in the "in" parameter of the forEach construct, creates a new execution scope for the interpreter to prevent any variable shadowing, and then processes the nested statements inside the "do" block of the forEach construct.
The forEach construct allows iterating through lists of values and performing some actions based on each value in that list while keeping the temporary variables within their own execution scope. This code block is responsible for controlling this iteration and maintaining the correct execution scope while going through the list of values and executing the statements in the nested "do" block.
…ing new execution scope
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.
Some comments. For the TODOs, it is okay at this stage to simply open issues for follow-up to not block this PR (up to you to decide).
Pull request is not up to date with the base branch. Reviewpad will rebase it. After the rebase, please trigger Reviewpad by running the command |
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 is ready to be merged. Reviewpad will merge it for you.
We will fix in a separate pull request |
Description
Introduces support for
forEach
loops in reviewpad DSL.Summary generated by Reviewpad on 31 May 23 10:28 UTC
This pull request contains several changes across the codebase. The
env.go
andtypeinfer.go
files have modifications to support built-ins and check for their existence. Theengine
package has several changes, including new imports, implementations of built-in functions, and modifications to structs and methods to support new features. A new filereviewpad_with_conditional_foreach_workflow.yml
has been added, which defines a group and workflow, including a conditional statement. Another new filereviewpad_with_foreach_workflow.yml
defines a workflow that iterates over a list of teams and adds a label to each. ThelintShadowedVariables()
function has been added to handle variable shadowing in workflow runs and workflows. Finally, theinline_rules_normalized.go
andexec.go
files have changes to support forEach blocks and new package imports.🤖 Generated by Copilot at eb1dd26
This pull request adds support for
forEach
clauses in run blocks, using thelang
package from reviewpad/v4 to handle list expressions and values. It updates the engine, the linter, and the aladino interpreter to parse, validate, normalize, transform, and execute theforEach
clauses. It also adds aType
method to theValue
interface and its implementations, and enables type inference and evaluation for list expressions and temporary variables in the aladino language. It modifies several files in theengine
andlang/aladino
packages, and refactors some test functions inlang/aladino/interpreter_internal_test.go
.Code review and merge strategy
Ask: this pull request requires a code review before merge
How
🤖 Generated by Copilot at eb1dd26
lang
package from reviewpad/v4 to uselang.Value
interface and other types (link, link, link)ProcessList
andStoreTemporaryVariable
methods toInterpreter
interface to evaluate and store list expressions and temporary variables in engine environment (link)Type
method for all value types in aladino interpreter, returning the corresponding type instances (link, link, link, link, link, link, link)ForEach
field toPadWorkflowRunBlock
struct, holding a pointer toPadWorkflowRunForEachBlock
struct, which has fields forvalue
,in
, anddo
offorEach
clause (link)forEach
clause in run block, by validating the fields, callingnormalizeRun
andtransformRunBlock
recursively ondo
block, and iterating over the list expression and executing thedo
block for each value (link, link, link, link)forEach
clause, and return an error if it has nothen
block, no actions, no extra actions, and noforEach
block (link, link)evalGroup
function toevalList
in aladino interpreter, and update error messages and test functions to use the term list instead of group (link, link, link, link, link, link)