Aladino Built-ins

One of the key advantages of using Reviewpad is that you can access a set of built-in functions and actions that allow for flexible specifications and actions.

Functions

allDevs

Description:

Lists all the members of the organization that owns the pull request.

If the authenticated user is an owner of the organization, this will return both concealed and public members, otherwise it will only return public members.

Parameters:

none

Return value:

string[]

The list of all members of the organization to where the pull request running against.

Examples:

$allDevs()

A revy.yml example:

rules:
    isAuthorFromOrganization:
        kind: patch
        description: Verifies if author belongs to organization
        spec: $isMemberOf($author(), $allDevs())

codeQuery

Description:

Verifies if the patch matches the provided code pattern, returning true or false as appropriate.

The code pattern needs to be a compilable regular expression.

Parameters:

variabletypedescription
queryPatternstringquery pattern to look for on patch

Return value:

boolean

Returns true if the patch matches the code query, false otherwise.

Examples:

$codePattern("placeBet\(.*\)")

A revy.yml example:

rules:
    usesPlaceBet:
        kind: patch
        description: Verifies if uses placeBet
        spec: $codePattern("placeBet\(.*\)")

commitsCount

Description:

Returns the total number of commits made into the pull request.

Parameters:

none

Return value:

int

The total number of commits in the pull request.

Examples:

$commitsCount()

A revy.yml example:

rules:
    hasTooManyCommits:
        kind: patch
        description: Verifies if it has than 3 commits
        spec: $commitsCount() > 3

contains

Description:

Determines whether a text includes a certain sentence, returning true or false as appropriate.

Parameters:

variabletypedescription
textstringThe text to search in
searchSentencestringThe sentence to search for

Return value:

boolean

Returns true if the value searchSentence is found within the text, false otherwise.

Examples:

$contains("Testing string contains", "string contains")     #true
$contains("Testing string contains", "test")                #false

A revy.yml example:

rules:
    hasCustomKeywordInTitle:
        kind: patch
        description: PR title has "custom" keyword
        spec: $contains($title(), "custom")

description

Description:

Returns the description of the pull request.

Parameters:

none

Return value:

string

The description of the pull request.

Examples:

$description()

A revy.yml example:

rules:
    hasDescription:
        kind: patch
        description: PR has "Testing description" description
        spec: $description() == "Testing description"

fileCount

Description:

Returns the total number of files changed in the patch.

Parameters:

none

Return value:

int

The total number of files changed in the patch.

Examples:

$filesCount()

A revy.yml example:

rules:
    changesTooManyFiles:
        kind: patch
        description: Verifies if it has than 3 files
        spec: $fileCount() > 3

filesExtensions

Description:

Determines whether all the extensions of the changed files on the patch are included on the provided list of file extensions, returning true or false as appropriate.

Each extension provided on the list needs to be a glob.

Parameters:

variabletypedescription
extensions[]stringlist of all file extensions

Return value:

boolean

Returns true if all file extensions in the patch are included in the list, false otherwise.

Examples:

$filesExtensions([".test.ts"])

A revy.yml example:

rules:
    changesAreOnlyTests:
        kind: patch
        description: Verifies if changes are only on test files
        spec: $filesExtensions([".test.ts"])

group

Description:

Lists all members that belong to the provided group. This group needs to be defined in the same revy.yml file.

group is a way to refer to a defined set of users in a short way.

Parameters:

variabletypedescription
groupNamestringthe group name to list the member from

Return value:

[]string

Returns all members from the group.

Examples:

$group("techLeads")

A revy.yml example:

groups:
  techLeads:
    description: Group with all tech leads
    kind: developers
    spec: '["john", "maria", "arthur"]'

rules:
  isAuthorByTechLead:
    description: Verifies if author is a tech lead
    kind: patch
    spec: $isMemberOf($name(), $group("techLeads"))

hasAnnotation

Description:

Verifies if the patch contains a symbol with the provided annotation, returning true or false as appropriate.

Parameters:

variabletypedescription
annotationstringannotation to look for in the patch

Return value:

boolean

Returns true if the patch changes a symbol with the provided annotation, false otherwise.

Examples:

$hasAnnotation("critical")

A revy.yml example:

rules:
    changesCritical:
        kind: patch
        description: Verifies if changes critical code
        spec: $hasAnnotation("critical")

hasFileName

Description:

Determines whether the provided filename is among the files on patch, returning true or false as appropriate.

Parameters:

variabletypedescription
filenamestringfilename to look for in the patch. case sensitive.

Return value:

boolean

Returns true if the patch has a file with the provided filename, false otherwise.

The provided filename and the filename on the patch need to be exactly the same in order to get a positive result.

Examples:

$hasFileName("placeBet.js")

A revy.yml example:

rules:
    changesPlaceBet:
        kind: patch
        description: Verifies if changes place bet file
        spec: $hasFileName("placeBet.js")

hasFilePattern

Description:

Determines whether the provided file pattern matches any of the files in the patch, returning true or false as appropriate.

The file pattern needs to be a glob.

Parameters:

variabletypedescription
filePatternstringfile pattern glob to look for on patch

Return value:

boolean

Returns true if any of the files on patch matches the provided file pattern, false otherwise.

Examples:

$hasFilePattern("src/transactions/**")

A revy.yml example:

rules:
    changesTransactions:
        kind: patch
        description: Verifies if changes transactions
        spec: $hasFilePattern("src/transactions/**")

hasLinkedIssues

Description:

Checks if a pull request has associated issues that might be closed by it.

Parameters:

none

Return value:

boolean

Returns true if it has linked issues. false otherwise.

Examples:

$hasLinkedIssues()

A revy.yml example:

rules:
    hasLinkedIssues:
        kind: patch
        description: Verifies if the PR has linked issues
        spec: $hasLinkedIssues()

isDraft

Description:

Verifies whether the pull request is Draft, returning true or false as appropriate.

To know more about GitHub Draft pull request.

Parameters:

none

Return value:

boolean

A boolean value which is true if the pull request is Draft, false otherwise.

Examples:

$isDraft()

A revy.yml example:

rules:
    isDraft:
        kind: patch
        description: Verifies if is Draft
        spec: $isDraft()

isMemberOf

Description:

Determines whether a list includes a certain value among its entries, returning true or false as appropriate.

Parameters:

variabletypedescription
searchElementliteralThe value to search for
list[]literalThe list to search in

Return value:

boolean

Returns true if the value searchElement is found within the list, false otherwise.

Examples:

$isMemberOf("john", ["maria", "john"])  # true
$isMemberOf(3, [1, 2])                  # false

A revy.yml example:

rules:
  authoredByJunior:
    description: Verifies if author is junior
    kind: patch
    spec: $isMemberOf($name(), $group("junior"))

name

Description:

Retrieves the pull request author GitHub login.

Parameters:

none

Return value:

string

The GitHub login of the pull request author.

Examples:

$name()

A revy.yml example:

rules:
    isAuthoredByTechLead:
        kind: patch
        description: Verifies if authored by tech lead
        spec: $name() == "john"

size

Description:

Returns the total amount of changed lines in the patch.

Any added or removed line is considered a change. For instance, the following patch will have a size of 2 (one line removed and one line added.)

function helloWorld() {
-   return "Hello"
+   return "Hello World"
}

Parameters:

none

Return value:

int

The sum of all changed lines in the patch.

Examples:

$size()

A revy.yml example:

rules:
    isBigChange:
        kind: patch
        description: Verifies if change is big
        spec: $size() > 100

team

Description:

Returns the members of a team and child teams.

To list members in a team, the team must be visible to the authenticated user.

:warning: Requires a GitHub token :warning:

By default a GitHub action does not have permission to access organization members.

Because of that, in order for the function team to work we need to provide a GitHub token to the Reviewpad action.

Please follow this link to know more.

Parameters:

variabletypedescription
teamSlugstringThe slug of the team name on GitHub.

Return value:

[]string

Returns the list of all team and child teams members GitHub login.

Examples:

$team("devops")

A revy.yml example:

rules:
  isAuthorByDevops:
    description: Verifies if author belongs to devops team
    kind: patch
    spec: $isMemberOf($name(), $team("devops"))

title

Description:

Returns the title of the pull request.

Parameters:

none

Return value:

string

The title of the pull request.

Examples:

$title()

A revy.yml example:

rules:
    hasTitle:
        kind: patch
        description: PR has "Test custom builtins" title
        spec: $title() == "Test custom builtins"

totalCreatedPRs

Description:

Returns the total number of pull requests created by the provided GitHub user login.

Parameters:

variabletypedescription
userLoginstringthe GitHub user login

Return value:

int

The total number of created pull requests created by GitHub user login.

Examples:

$totalCreatedPRs($author())

A revy.yml example:

rules:
    isJunior:
        kind: patch
        description: Verifies if author is junior
        spec: $totalCreatedPRs($author()) < 3

Actions

addLabel

Description:

Adds a label to the pull request.

This built-in assumes that the label has been created. Otherwise, it returns an error.

Parameters:

variabletypedescription
namestringname of the label

Return value:

Error if the label does not exist in the repository.

Examples:

$addLabel("bug")

A revy.yml example:

protectionGates:
  - name: label-small-pull-request
    description: Label small pull request
    patchRules:
      - rule: isSmall
    actions:
      - $addLabel("small")

assignRandomReviewer

Description:

Assigns a random user of the GitHub organization as the reviewer.
This action will always pick a user different than the author of the pull request.

However, if the pull request already has a reviewer, nothing happens. This is to prevent
adding a reviewer each time the pull request is updated.

When there's no reviewers to assign to, an error is returned.

Parameters:

none

Return value:

none

Examples:

$assignRandomReviewer()

A revy.yml example:

protectionGates:
  - name: assign-random-reviewer
    description: Assign random reviewer
    patchRules:
      - rule: tautology
    actions:
      - $assignRandomReviewer()

assignReviewer

Description:

Assigns a defined amount of reviewers to the pull request from the provided list of reviewers.

When there's not enough reviewers to assign to, an warning is returned.

If a reviewer from the defined list has performed a review, his review will re-requested.

Parameters:

variabletypedescription
reviewers[]stringlist of GitHub logins to select from
total (optional)inttotal of reviewers to assign. by default assigns to all reviewers

Return value:

none

Examples:

$assignReviewer(["john", "marie", "peter"], 2)

A revy.yml example:

protectionGates:
  - name: review-code-from-new-joiners
    description: Assign senior reviewers to PRs from new joiners
    patchRules:
      - rule: authoredByJunior
    actions:
      - $assignReviewer($group("seniors"), 2)

merge

Description:

Merge a pull request with a specific merge method.

By default, if no parameter is provided, it will perform a standard git merge.

:warning: Requires a GitHub token :warning:

By default a GitHub action does not have permission to access organization members.

Because of that, in order for the function team to work we need to provide a GitHub token to the Reviewpad action.

Please follow this link to know more.

Parameters:

variabletypedescription
methodstringmerge method (merge, rebase or squash)

Return value:

none

Examples:

$merge()

A revy.yml example:

protectionGates:
  - name: auto-merge-small-pull-request
    description: Auto-merge small pull request
    patchRules:
      - rule: isSmall
    actions:
      - $merge()

removeLabel

Description:

Removes a label applied to a pull request.

If the label is not applied to the pull request then nothing happens.

This built-in assumes that the label has been created. Otherwise, it returns an error.

Parameters:

variabletypedescription
namestringname of the label

Return value:

Error if the label does not exist in the repository.

Examples:

$removeLabel("bug")

A revy.yml example:

protectionGates:
  - name: remove-small-label-in-pull-request
    description: Remove small label applied to pull request
    patchRules:
      - rule: isNotSmall
    actions:
      - $removeLabel("small")

Did this page help you?