Expressions are small computations on Pull Request attributes. Expressions are most useful in workflow conditions, string templates, and custom merge checks. Expressions can be as simple as a constant (like a number or a string) or an attribute value, but expressions can also be more complex manipulation of attributes.
Some examples of expressions are
-
draft -
true -
'Hello World' -
'PR ${title} opened by ${author}' -
source ~= 'bugfix/*' -
count(approved-by) -
builds.successful -
forall(changed-files, $1 ~= '**/*.js')
Expressions can be composed in any form or fashion using expression operators described below, as long as their type requirements are fulfilled. If an expression does not type-check (e.g., source > 3), it will make the devsensei.yaml file invalid.
Expressions can return any type, but expressions involved in conditions have to return a boolean. For example, even though count(approved-by) is a valid expression, it is not valid as part of the conditions.
String Template Literals
A literal string also supports templating. Arbitrary expressions can be spliced in with ${expr} if expr is convertible to string.
Template Examples
-
'PR: ${title}'directly embeds thetitleattribute of typestring. -
'Found ${count(commits)} commits'embeds the expressioncount(commits)of typeintby automatic conversion tostring.
String Conversions
Expressions of the following types may be directly inserted into a string template: int, boolean, string.
💡 We plan to support more data types in string templates soon. Let us know if you need this for your use case.
Lambda functions 🔬
Some functions require a lambda function as argument, for example exists or forall. A lambda function looks like a usual expression except $1 is used as a placeholder for the function argument.
For example, the following expressions are valid lambdas:
-
$1 ~= 'alice' -
'${$1}' ~= 'alice'(the same via conversion.) -
!$1 -
count($1) < 50 -
contains(reviewers.approved, $1)
As a complete example, the following expression checks that at least one reviewer is called "alice":
-
exists(reviewers, $1 = 'alice'),
in this expression reviewers is a collection of type set, and $1 is a placeholder that will be substituted with each reviewer in the collection until a true result is found.
Expression Syntax reference
Atomic expressions
|
Kind |
Example |
|---|---|
|
boolean literals |
|
|
integer literals |
|
|
string literals, enclosed in single quotes. Within quotes, single quotes |
|
|
an attribute reference |
|
|
lambda function argument reference |
|
|
wrapped expressions: |
|
compound expressions
|
Kind |
Syntax |
Example |
|---|---|---|
|
infix operator |
|
|
|
prefix operator |
|
|
|
function call |
|
|
|
property access |
|
|
Whitespace
Outside of string literals, spaces are insignificant.
Expression types
Here are the following types that can be involved in expressions
|
Type name |
Description |
|---|---|
|
|
a wildcard meaning any type is accepted. |
|
|
a value that is one of either |
|
|
any UTF-8 text value. |
|
|
an integer value (between |
|
|
a sequence of elements, may contain duplicates. |
|
|
an aggregate of unique elements, may have optional properties, (e.g. |
|
|
A registered application user; can be identified by both username and email. |
|
|
a lambda function expression taking an argument of type |
|
|
Value that represents a duration, such as 1 minute or 2 days. Durations can be created using the |
|
|
Regular expression object to be used for string comparisons (with the |
|
|
Represents values between a lower bound (inclusive) and an upper bound (exclusive). Ranges can be created using the |
Expression Operators
Use Operators to transform expressions into more complex ones. For example, to compare two int values or to count the number of elements in a set. Operators can be infix (only for binary operators), prefix or call. Infix operators are placed within their arguments, prefix operators must be placed before their arguments, and call operators must enclose their argument(s) in parenthesis, separated by commas.
|
Operator |
Meaning |
Type |
Position |
Example |
|---|---|---|---|---|
|
|
Glob match with a branch pattern. |
|
|
|
|
|
Regex match |
|
|
|
|
|
Glob or regex match which returns true when at least one file path in the set matches. (only |
|
|
|
|
since 9.1 |
Regex match which returns true when one of the changed lines content matches. |
|
|
|
|
|
Negation of glob or regex match (i.e. no matches) |
|
|
|
|
|
Equals |
|
|
|
|
|
Not equals |
|
|
|
|
|
Negate a boolean attribute (use of |
|
|
|
|
|
Number or string length comparison |
|
|
|
|
|
Computes the number of elements in a |
|
|
|
|
|
Checks for membership of an element in a |
|
|
|
|
|
Negates a boolean expression |
|
|
|
|
|
Checks whether the items in the first argument collection all satisfy the predicate specified by the lambda in the second argument. Always returns |
|
|
|
|
|
Checks whether there is at least one item in the first argument collection that satisfy the predicate specified by the lambda in the second argument. Always returns |
|
|
|
|
since 9.2 |
Keeps only elements from the collection in the first argument that satisfy the predicate specified by the lambda in second argument. |
|
|
|
|
since 9.2 |
Returns a new collection by transforming all elements in the first argument collection by the lambda in the second argument. |
|
|
|
|
|
Joins the string elements of a collection into a single string, separated by the specified delimiter. |
|
|
|
|
|
Creates a range between the specified bounds (lower is inclusive, upper is exclusive) |
|
|
|
|
since 9.3 |
Returns the part of the string in the first argument with characters taken from the range specified as second argument. If the range is empty (i.e., lower bound bigger than or equal to the upper bound), then returns the empty string. |
|
|
|
|
|
Creates a duration from its expression. A duration expression is a number followed by a time unit ( |
|
|
|
|
|
Creates a regular expression from its string pattern representation. If the pattern is not valid, the DevSensei configuration will be invalid as well. Please refer to the re2 regex specification for its syntax. |
|
|
|
|
since 9.3 |
Uses a regular expression with a matching group to extract its value within the string given as first argument. The regular expression must have exactly 1 defined group, otherwise the expression is invalid. If the regular expression does not match the string, this function returns the empty string. |
|
|
|
Attributes🔰
These are the various attributes available to use in conditions, retrigger-on, and merge-checks. Each attribute results in a typed value when evaluated.
Attributes labelled with the lightning emoji ⚡️ can be used in the retrigger-on section
|
Condition Attribute |
Type |
Meaning |
|---|---|---|
|
|
|
The pull request title |
|
|
|
The pull request description |
|
|
|
Source branch of pull request |
|
|
|
Destination branch of pull request |
|
|
|
Destination repository of pull request |
|
|
|
The SHA-1 hash of commit of the HEAD ref on the source branch |
|
|
|
Is it a draft pull request |
|
|
|
Whether the Pull Request currently has conflicts with the target branch. |
|
since 8.6 |
|
The user who created the PR. |
|
since 8.11 |
|
Time since the pull request was opened. Conditions involving the age can be configured via a schedule. |
|
|
|
The set of tasks that are still open in the PR. |
|
|
|
The set of username slugs corresponding to users who have approved the PR. |
|
|
|
The set of users who are reviewers of the PR and their review status. Has properties |
|
since 8.6 |
|
The set of all files that are affected by the pull request. Has properties |
|
since 9.1 |
|
The list of all changed lines (added or removed) that are affected by the pull request. Has properties |
|
since 8.6 |
|
The set of builds for the most recent commit for the pull request. Has properties |
|
since 8.7 |
|
The set of users who are watchers of the PR. Watchers are people that interacted with the pull request. See Bitbucket documentation. |
|
since 8.7 |
|
List of commits in this PR. Has properties |
|
since 8.7 |
|
Set of Jira keys mentioned in all commit messages. |
Attribute and data types Properties 🔬
Some attributes have properties, (for use in property access expressions) that provide a view over the contained data.
|
attribute/data type |
Property |
Meaning |
|---|---|---|
|
|
|
The successful builds |
|
|
|
The failed builds |
|
|
|
The builds that are in progress |
|
|
|
Only the new files that were not seen before |
|
|
|
Only the files that will be deleted after merging |
|
|
|
Only the files that changed (and possibly also moved). |
|
|
|
Only the files that were not changed, but were moved |
|
|
|
Only the reviewers who have approved the PR. |
|
|
|
Only the reviewers who have requested changes on the PR. |
|
|
|
Only the reviewers who have not completed their review. |
|
|
|
list of all tiles of the commits. |
|
|
|
list of all commit messages. |
|
|
|
set of all authors of all the commits |
|
|
|
The title of the commit message (the first line) |
|
|
|
set of Jira keys in commit. Eg |
|
since 9.1 |
|
The content of the line Eg |
|
|
|
The path (from repository root) of the line |
|
|
|
Whether the line was added within the PR |
|
|
|
Whether the line was removed within the PR |
|
since 9.2 |
|
The path (from repository root) of the file in the PR diff. Eg |
|
|
|
Whether the file was added in the PR |
|
|
|
Whether the file was deleted in the PR |
|
|
|
Whether the file was modified in the PR |