An Action is an automated development workflow that leverages Rules to do some task, for example automating code reviews. While a Rule lives next to your code in a codelingo.yaml file, it is inert until an Action uses it.
Under the hood, an Action is a pipeline of serverless functions, called Action Functions. Action Functions allow Actions to integrate with your existing tools and infrastructure. Action Functions are also what glue Rules and Actions together, with the use of query decorators. Let's walk through the following Rule to see how this works:
rules: - name: example-rule actions: codelingo/docs: title: Find functions named helloWorld. codelingo/review: comment: "This is a function named helloWorld." query: | import codelingo/ast/go @review comment go.func_decl(depth = any): go.ident: name == "helloWorld"
Import & Config#
Actions that can be used with the above Rule are configured under the
# ... actions: codelingo/review: comment: "This is a function named helloWorld." # ...
Here we are importing the
review action from the
codelingo owner and configuring it to comment "This is a function named helloWorld." on any query matches.
Action Function Decorators#
The Rule query searches for all Go functions named "helloWorld":
# ... query: | import codelingo/ast/go @review comment go.func_decl(depth = any): go.ident: name == "helloWorld" # ...
Rule queries are decorated with Action Function decorators which extract the results of the query to be used by the Action. In this case,
@review comment is the decorator for the comment Action Function of the Review Action:
# ... @review comment go.func_decl: # ...
By decorating the
go.func_decl fact with
@review comment the Review Action's comment function extracts the file and line from the query result, to be used by the Review Action to comment on that line.
We have deprecated flows in favor of actions. Please modify your codelingo.yaml files accordingly.
Documentation on how to compose custom Actions is coming soon. In the mean time, please see the Rules documention to understand how Actions work with Rules.