### Install Go Dependencies Source: https://docs.reviewpad.com/contribute Run `go get` in the repository root to fetch necessary Go dependencies. This should be done after forking and creating your branch. ```bash go get ``` -------------------------------- ### Get User Teams Example Source: https://docs.reviewpad.com/guides/built-ins/getUserTeams Demonstrates how to call the getUserTeams function with a specific username. ```shell $getUserTeams("Paul") ``` -------------------------------- ### Reviewpad Configuration Example Source: https://docs.reviewpad.com/guides/built-ins/rule This example shows a `reviewpad.yml` file defining several rules (size-compliance, description-compliance, is-compliant) and a workflow (check-compliance) that uses these rules. ```yaml rules: - name: size-compliance spec: $getSize() < 100 - name: description-compliance spec: $getDescription() != "" - name: is-compliant spec: $rule("size-compliance") && $rule("description-compliance") workflows: - name: check-compliance run: if: is-compliant then: $addReviewerRandomly() ``` -------------------------------- ### Example Reviewpad Check Configuration Source: https://docs.reviewpad.com/guides/syntax An example demonstrating how to configure a 'stale' check with a maximum idle time of 30 days, a 'stale' label, and activation set to 'on'. ```yaml checks: stale: parameters: max-idle-days: 30 label: stale activation: on ``` -------------------------------- ### Reviewpad Override Logs Example Source: https://docs.reviewpad.com/guides/extends Example logs generated during the extension process, indicating which properties were overridden and by which configuration files. These logs help in understanding the final configuration. ```log [warning] Workflow 'medium-size' has been overridden by https://github.com/baz/foo/blob/main/common.yml [warning] Workflow 'small-size' has been overridden by https://github.com/baz/foo/blob/main/common.yml [warning] Workflow 'medium-size' has been overridden by https://github.com/baz/qux/blob/main/team_a.yml [warning] Workflow 'small-size' has been overridden by https://github.com/baz/qux/blob/main/team_a.yml ``` -------------------------------- ### Example: common.yml for Overriding Source: https://docs.reviewpad.com/guides/extends An example of a common configuration file that can be extended. It defines workflows that may be overridden by the main configuration. ```yaml metrics-on-merge: true workflows: - name: small-size run: if: $getSize() < 5 then: $reportInfo("this is a very small pr") - name: medium-size run: if: $getSize() >= 30 then: - $reportInfo("this is not a small pr") - $addReviewerRandomly() ``` -------------------------------- ### Reviewpad YAML Workflow Example Source: https://docs.reviewpad.com/guides/built-ins/countUserIssues This example demonstrates using countUserIssues within a reviewpad.yml workflow to add comments based on the number of issues created by the author. ```yaml workflows: - name: congratulate run: - if: $countUserIssues($getAuthor(), "all") == 1 then: $addComment("Congratulations on your first issue!") - if: $countUserIssues($getAuthor(), "all") == 10 then: $addComment("Way to go! You have created 10 issues!") ``` -------------------------------- ### Example Usage of addTeamsForReview Source: https://docs.reviewpad.com/guides/built-ins/addTeamsForReview Demonstrates how to call the addTeamsForReview built-in with a list of team slugs. This example shows a direct invocation, often used in testing or simple configurations. ```shell $addTeamsForReview(["core", "support"]) ``` -------------------------------- ### Example: team_a.yml for Overriding Source: https://docs.reviewpad.com/guides/extends Another example configuration file demonstrating how workflows can be overridden. This file is specified later in the 'extends' list, giving its properties higher precedence. ```yaml workflows: - name: small-size run: if: $getSize() < 10 then: $reportInfo("this is a small pr for team a") - name: medium-size run: if: $getSize() >= 30 then: $reportInfo("this is not a small pr") ``` -------------------------------- ### Workflow Example Using getUserTeams Source: https://docs.reviewpad.com/guides/built-ins/getUserTeams An example of a reviewpad.yml workflow that uses getUserTeams to check if the pull request author belongs to the 'onboarding' team before adding reviewers. ```yaml workflows: - name: review assignment policy in case the author belongs to team 'onboarding' on: - pull_request run: - if: $isElementOf("onboarding", $getUserTeams($getAuthor())) then: $addReviewers(["paul", "freddy"], 1) ``` -------------------------------- ### Call getOrganizationTeams Source: https://docs.reviewpad.com/guides/built-ins/getOrganizationTeams This is a basic example of how to call the getOrganizationTeams function. ```bash $getOrganizationTeams() ``` -------------------------------- ### Rule Example Source: https://docs.reviewpad.com/guides/syntax An example of a rule that checks the size of a code patch. The 'kind' field is optional and defaults to 'patch' if not specified. ```yaml rules: - name: small-change kind: patch # optional description: Checks if the pull request size is small # optional spec: $getSize() < 30 ``` -------------------------------- ### Count User Issues Example Source: https://docs.reviewpad.com/guides/built-ins/countUserIssues This example shows how to use the countUserIssues function with the current author. ```javascript $countUserIssues($getAuthor()) ``` -------------------------------- ### Count User Reviews Example Source: https://docs.reviewpad.com/guides/built-ins/countUserReviews Demonstrates how to use the countUserReviews built-in function with the getAuthor function to get the review count for the current author. ```yaml $countUserReviews($getAuthor()) ``` -------------------------------- ### Set Project Field Examples Source: https://docs.reviewpad.com/guides/built-ins/setProjectField Demonstrates how to set custom field values for a project. Use this to update fields like priority or size. ```bash $setProjectField("reviewpad", "priority", "P1") ``` ```bash $setProjectField("reviewpad", "size", "50") ``` -------------------------------- ### Basic $addLabel Usage Source: https://docs.reviewpad.com/guides/built-ins/addLabel A simple example demonstrating how to call the $addLabel function with a single label name. ```shell $addLabel("bug") ``` -------------------------------- ### Conditional Workflow Based on Size Source: https://docs.reviewpad.com/guides/built-ins/getSize An example of using the getSize built-in within a reviewpad.yml configuration to conditionally run a workflow based on the size of code changes. This example reports a blocker if the changes exceed 100 lines, ignoring lock files. ```yaml workflows: - name: check-compliance run: # Verify size ignoring lock files if: $getSize(["*.lock"]) > 100 then: $reportBlocker("Change is too big") ``` -------------------------------- ### Aladino Example: Logical Expressions Source: https://docs.reviewpad.com/guides/aladino-language Demonstrates the use of logical expressions in Aladino, such as string comparisons and function call comparisons. ```aladino "a" == "a" ``` ```aladino $fun() == 1 ``` -------------------------------- ### Get Team Members Example Source: https://docs.reviewpad.com/guides/built-ins/getTeamMembers Call the getTeamMembers function with a team slug to retrieve a list of member GitHub logins. The team must be visible to the authenticated user. ```shell $getTeamMembers("devops") ``` -------------------------------- ### Workflow Example: Fail on Git Conflicts Source: https://docs.reviewpad.com/guides/built-ins/hasGitConflicts This example demonstrates how to use the hasGitConflicts built-in within a reviewpad.yml workflow. If Git conflicts are detected, the workflow will fail with a specified message. ```yaml workflows: - name: check-compliance run: if: $hasGitConflicts() then: $fail("Pull request has git conflicts") ``` -------------------------------- ### Reviewpad YAML Workflow Example Source: https://docs.reviewpad.com/guides/built-ins/setProjectField An example of using $setProjectField within a reviewpad.yml workflow to set a project field conditionally. This snippet is part of a larger workflow definition. ```yaml workflows: - name: set-project-field run: if: $hasLinkedIssues() == false then: - $addToProject("jupiter", "in progress") - $setProjectField("jupiter", "notes", "missing issue") ``` -------------------------------- ### Aladino Example: Lambda Function Source: https://docs.reviewpad.com/guides/aladino-language Shows how to define and use lambda functions in Aladino for custom logic, such as comparing a developer to the author. ```aladino ($dev => $dev == $getAuthor()) ``` -------------------------------- ### Conditional Workflow with Get Created At Source: https://docs.reviewpad.com/guides/built-ins/getCreatedAt Use `getCreatedAt()` within a `reviewpad.yml` workflow to set conditions based on the creation time. This example reports information if the pull request was created more than 10 days ago. ```yaml workflows: - name: long-live run: # Verify if the pull request was created more than 10 days ago if: $getCreatedAt() < 10 days ago then: $reportInfo("This pull request is old. Please consider closing it.") ``` -------------------------------- ### Annotating a Symbol Source: https://docs.reviewpad.com/guides/built-ins/containsCodeAnnotation To annotate a symbol, precede its definition with a comment starting with `// reviewpad-an:`. The annotation name follows the colon. This example shows the `main` function annotated with `critical`. ```go // reviewpad-an: critical func main() { fmt.Println("Hello, World!") } ``` -------------------------------- ### Aladino Example: Function Call Source: https://docs.reviewpad.com/guides/aladino-language Illustrates how to call built-in functions in Aladino, like adding a label to a pull request. ```aladino $label("bug") ``` -------------------------------- ### Final Merged Configuration Example Source: https://docs.reviewpad.com/guides/extends Illustrates the resulting configuration after applying the 'extends' property and overriding rules. The final configuration reflects the precedence rules. ```yaml metrics-on-merge: true workflows: # we first load the "medium-size" workflow from common.yml (the first configuration in the extends section) # then we override it with the "medium-size" workflow from team_a.yml (the second configuration in the extends section) - name: medium-size run: if: $getSize() >= 30 then: $reportInfo("this is not a small pr") # we first load the "small-size" workflow from common.yml (the first configuration in the extends section) # then we override it with the "small-size" workflow from team_a.yml (the second configuration in the extends section) # and finally we override it with the "small-size" workflow from the current configuration - name: small-size run: if: $getSize() < 30 then: $reportInfo("this is a small pr") ``` -------------------------------- ### Add Pull Request to Project - CLI Source: https://docs.reviewpad.com/guides/built-ins/addToProject Use this command-line example to add a pull request to the 'reviewpad' project with the 'in progress' status. ```bash $addToProject("reviewpad", "in progress") ``` -------------------------------- ### Conditional Review in reviewpad.yml Source: https://docs.reviewpad.com/guides/built-ins/review This example demonstrates how to conditionally request changes in a reviewpad.yml configuration. The review is submitted only if specific files have not changed. ```yaml workflows: - name: validate-changes run: if: $changed("src/@1.java", "test/@1.java") == false then: $review("REQUEST_CHANGES", "Please include the tests for your change") ``` -------------------------------- ### Get Created At Function Source: https://docs.reviewpad.com/guides/built-ins/getCreatedAt Call the `getCreatedAt()` function to retrieve the creation timestamp. This function takes no parameters. ```shell $getCreatedAt() ``` -------------------------------- ### Dictionary Example with Aladino Array Values Source: https://docs.reviewpad.com/guides/syntax Shows how to use Aladino array values in a dictionary. Each array value is a JSON-formatted string. ```yaml dictionaries: - name: reviewing-teams-per-file-path description: Teams to involve in the review process based on the path of the touched files # optional spec: '**/authentication/**': '["security-team", "developers"]' '**/db/**': '["dba-team", "developers"]' '.github/workflow/**': '["devops-team"]' ``` -------------------------------- ### Dictionary Example with Aladino String Values Source: https://docs.reviewpad.com/guides/syntax Illustrates how to use Aladino string values within a dictionary. Values must be enclosed in both double and single quotes. ```yaml dictionaries: - name: label-per-file-path description: Labels to apply based on the path of the touched files # optional spec: '**/authentication/**': '"authentication"' '**/order/**': '"order"' '**/api/**': '"api"' 'LICENSE': '"license"' '.github/workflow/**': '"ops"' ``` -------------------------------- ### Conditional Workflow in reviewpad.yml Source: https://docs.reviewpad.com/guides/built-ins/selectFromJSON This example demonstrates a conditional workflow in reviewpad.yml that adds a 'rebaseable' label if the 'rebaseable' property in the context JSON is 'true'. ```yaml workflows: - name: label-rebaseable run: if: $selectFromJSON($toJSON($context), "$.rebaseable") == "true" then: $addLabel("rebaseable") ``` -------------------------------- ### Close Pull Request/Issue Examples Source: https://docs.reviewpad.com/guides/built-ins/close Demonstrates various ways to use the $close() function, including closing with and without a comment, and with or without a closure reason for issues. ```shell $close() ``` ```shell $close("Closed due inactivity") ``` ```shell $close("", "not_planned") ``` ```shell $close("This project is deprecated", "not_planned") ``` -------------------------------- ### Get All Reviewers Source: https://docs.reviewpad.com/guides/built-ins/getReviewers Fetches all reviewers assigned to the pull request. This is the default behavior when no parameters are provided. ```reviewpad $getReviewers() ``` -------------------------------- ### Configure CommitLint in Reviewpad Workflow Source: https://docs.reviewpad.com/guides/built-ins/commitLint Integrate the CommitLint built-in into a Reviewpad workflow. This example shows how to run CommitLint only when the base branch is 'main'. ```yaml workflows: - name: check-conventional-commits run: if: $getBaseBranch() == "main" then: $commitLint() ``` -------------------------------- ### Report Warning in a Workflow Source: https://docs.reviewpad.com/guides/built-ins/reportWarning This example shows how to use reportWarning within a reviewpad.yml workflow to report a specific condition. ```yaml workflows: - name: validate-changes run: if: $containsFilePattern("*.lock") then: $reportWarning("Please remove the lock file from the commit.") ``` -------------------------------- ### Configure Summarize in Reviewpad Workflow Source: https://docs.reviewpad.com/guides/built-ins/summarize Example of how to integrate the summarize command into a Reviewpad workflow configuration file. This workflow triggers the summarization when a pull request is opened. ```yaml workflows: - name: summarize-on-pull-request-creation run: if: $getEventType() == "opened" then: $summarize() ``` -------------------------------- ### Get Array Length Source: https://docs.reviewpad.com/guides/built-ins Retrieves the number of elements in an array. This is commonly used in conditional checks, for example, to ensure a minimum number of reviewers. ```yaml workflows: - name: check-compliance run: if: $length($getReviewers()) < 2 then: $reportInfo("A pull request needs at least 2 reviews") ``` -------------------------------- ### Conditional Workflow with toBool Source: https://docs.reviewpad.com/guides/built-ins/toBool An example of using toBool within a reviewpad.yml file to conditionally run a workflow step based on a context variable. ```yaml workflows: - name: label-locked run: if: $toBool($selectFromContext("$.locked")) then: $addLabel("locked") ``` -------------------------------- ### Iterate Over Organization Teams in reviewpad.yml Source: https://docs.reviewpad.com/guides/built-ins/getOrganizationTeams Use getOrganizationTeams within a reviewpad.yml workflow to iterate over all organization teams. This example assigns reviewers based on labels. ```yaml workflows: - name: assign for review to a team member based on label on: - pull_request run: - forEach: value: $orgaTeam in: $getOrganizationTeams() do: - if: $hasLabel($orgaTeam) then: $addReviewers($getTeamMembers($orgaTeam), 1) ``` -------------------------------- ### Use extractMarkdownHeadingContent in a Workflow Source: https://docs.reviewpad.com/guides/built-ins/extractMarkdownHeadingContent This example shows how to integrate extractMarkdownHeadingContent into a reviewpad.yml workflow to automatically add labels based on heading content. ```yaml workflows: - name: add-label-based-on-description-heading run: $addLabel($extractMarkdownHeadingContent($getDescription(), "Merge strategy", 2)) ``` -------------------------------- ### Use titleLint() in reviewpad.yml Source: https://docs.reviewpad.com/guides/built-ins/titleLint Example of using the titleLint built-in within a reviewpad.yml workflow to enforce conventional commits on the main branch. ```yaml workflows: - name: check-conventional-commits run: if: $getBaseBranch() == "main" then: $titleLint() ``` -------------------------------- ### Add to Project in reviewpad.yml - Workflow Source: https://docs.reviewpad.com/guides/built-ins/addToProject This example demonstrates how to use the addToProject function within a reviewpad.yml workflow. It adds an issue to the 'jupiter' project if no linked issues are found. ```yaml workflows: - name: add-to-project run: if: $hasLinkedIssues() == false then: $addToProject("jupiter", "in progress") ``` -------------------------------- ### Get Total Created Pull Requests Source: https://docs.reviewpad.com/guides/built-ins/totalCreatedPullRequests Use this snippet to retrieve the total number of pull requests created by the author of the current review. This is a basic usage example. ```javascript $totalCreatedPullRequests($getAuthor()) ``` -------------------------------- ### Basic Usage of startsWith Source: https://docs.reviewpad.com/guides/built-ins/startsWith Demonstrates how to use the startsWith function to check for prefixes in a string. The comparison is case-sensitive. ```shell $startsWith("Testing string contains", "Test") #true $startsWith("Testing string contains", "string contains") #false ``` -------------------------------- ### Conditional Workflow Based on Reviewers Source: https://docs.reviewpad.com/guides/built-ins/requestedReviewers This example demonstrates a conditional workflow in reviewpad.yml. It checks if reviewers have been assigned using $getReviewers() and reports if none are found. ```yaml workflows: - name: assign-reviewer run: if: $getReviewers() == [] then: $reportInfo("Please assign a reviewer.") ``` -------------------------------- ### Conditional Logic with getMilestone Source: https://docs.reviewpad.com/guides/built-ins/getMilestone Use getMilestone within conditional statements in your reviewpad.yml configuration to apply labels based on milestone titles. This example shows how to add a label if the milestone is 'Hacktoberfest' or starts with 'v'. ```yaml workflows: - name: label-milestone run: - if: $getMilestone() == "Hacktoberfest" then: $addLabel("hacktoberfest") - if: $startsWith($getMilestone(), "v") then: $addLabel("release") ``` -------------------------------- ### Importing Configuration Files with Extends Source: https://docs.reviewpad.com/guides/extends Specify a list of GitHub blob URLs for Reviewpad configuration files to import. Ensure the Reviewpad GitHub App has read access to these repositories. ```yaml extends: - https://github.com/baz/foo/blob/main/common.yml - https://github.com/baz/qux/blob/main/team_a.yml ``` -------------------------------- ### Conditional Logic with getHeadBranch in reviewpad.yml Source: https://docs.reviewpad.com/guides/built-ins/getHeadBranch Use getHeadBranch within a reviewpad.yml configuration to apply labels based on branch naming conventions. This example adds 'feature' or 'fix' labels if the head branch starts with 'feat/' or 'fix/' respectively. ```yaml workflows: - name: label-change-type run: - if: $startsWith($getHeadBranch(), "feat/") then: $addLabel("feature") - if: $startsWith($getHeadBranch(), "fix/") then: $addLabel("fix") ``` -------------------------------- ### Configure Merge Workflow in Reviewpad Source: https://docs.reviewpad.com/guides/built-ins/merge This example shows how to configure a workflow in `reviewpad.yml` to automatically merge pull requests that only contain markdown files. It utilizes the `$merge()` built-in. ```yaml workflows: - name: merge if: $containsOnlyFileExtensions([".md"]) then: $merge() ``` -------------------------------- ### Report Context in Workflow Source: https://docs.reviewpad.com/guides/built-ins/context This example demonstrates how to use the $context() built-in within a reviewpad.yml workflow. It reports the current context if the 'debug' label is present on the pull request. ```yaml workflows: - name: debug run: if: $isElementOf("debug", $getLabels()) then: $reportInfo($context()) ``` -------------------------------- ### Conditional Workflow Based on Commit Messages Source: https://docs.reviewpad.com/guides/built-ins/getCommits This example demonstrates how to use the getCommits built-in within a Reviewpad workflow. It checks if any commit message starts with 'fix:' and, if true, applies the 'bug' label. The expression is wrapped in quotes to prevent YAML parsing issues. ```yaml workflows: - name: label-change-type run: # Verify if any commit message starts with the word "fix:" # The expression is wrapped in quotes to avoid YAML parsing errors if: '$any($getCommits(), ($c: String => $startsWith($c, "fix:")))' then: $addLabel("bug") ``` -------------------------------- ### Basic matchString Usage Source: https://docs.reviewpad.com/guides/built-ins/matchString Demonstrates basic usage of the matchString function with different patterns and texts. Use this to verify simple string matches. ```reviewpad $matchString("a(bc)+", "abcbc") # true $matchString("\d+", "text") # false ``` -------------------------------- ### Configure Stale Check Parameters Source: https://docs.reviewpad.com/reviewpad-check Example of configuring the 'stale' check in `reviewpad.yml` to set the maximum idle days and a label for flagging stale PRs. Activation can be toggled on or off. ```yaml checks: stale: # 'stale' is the check id parameters: # 'parameters' is the standard section introducing the adjustable parameters max-idle-days: 30 # 'max-idle-days' is the only parameter of the 'stale' check label: stale # `label` is the name to be used to flag stale PRs activation: on # 'activation' status is either 'on' or 'off' ``` -------------------------------- ### Add Label if Pending Review Source: https://docs.reviewpad.com/guides/built-ins/hasAnyPendingReviews This example demonstrates how to use hasAnyPendingReviews within a workflow to conditionally add a label. Ensure your reviewpad.yml is correctly configured. ```yaml workflows: - name: attention-set run: - if: $hasAnyPendingReviews() then: $addLabel("waiting-for-review") - if: $hasAnyUnaddressedThreads() then: $addLabel("requires-author-attention") ``` -------------------------------- ### Check for Skipped or Failed Check Runs Source: https://docs.reviewpad.com/guides/built-ins/hasAnyCheckRunCompleted This example triggers a workflow if any check run has been either 'skipped' or has 'failed'. It allows for broader condition checking beyond just failures. ```yaml $hasAnyCheckRunCompleted([], ["skipped", "failure"]) ``` -------------------------------- ### Get Organization Members Source: https://docs.reviewpad.com/guides/built-ins/getOrganizationMembers Call this function to get a list of all members in the organization. This is often used in workflow conditions. ```shell $getOrganizationMembers() ``` -------------------------------- ### Get Array Length Source: https://docs.reviewpad.com/guides/built-ins/length Use the $length function to get the number of elements in an array. This is useful for conditional logic in workflows. ```yaml $length(["a", "b"]) # 2 ``` ```yaml workflows: - name: check-compliance run: if: $length($getReviewers()) < 2 then: $reportInfo("A pull request needs at least 2 reviews") ``` -------------------------------- ### Get All Changed File Paths Source: https://docs.reviewpad.com/guides/built-ins/getFilePaths Use this function to get a list of all file paths that have been modified in the pull request. It takes no parameters. ```shell $getFilePaths() ``` -------------------------------- ### Define User Groups in reviewpad.yml Source: https://docs.reviewpad.com/guides/built-ins/group This example demonstrates how to define different types of groups in your `reviewpad.yml` file. Groups can be simple lists of users or dynamically filtered based on conditions. ```yaml groups: - name: tech-leads # The expression is wrapped in quotes to avoid YAML parsing errors spec: '["john", "maria", "arthur"]' - name: juniors type: filter param: developer where: $countUserPullRequests($developer, "all") < 10 - name: ignore_paths # The expression is wrapped in quotes to avoid YAML parsing errors spec: '["engine/**", "*.yaml"]' ``` -------------------------------- ### Check for Binary Files in Reviewpad Workflow Source: https://docs.reviewpad.com/guides/built-ins/getFilePaths This example demonstrates how to use getFilePaths within a reviewpad.yml workflow to check if any binary files are present in the changes. If binary files are found, the workflow fails. ```yaml workflows: - name: binary-files-not-allowed run: if: "$any($getFilePaths(), ($filePath: String => $isBinaryFile($filePath)))" then: $fail("Binary files are not allowed.") ``` -------------------------------- ### Basic toBool Usage Source: https://docs.reviewpad.com/guides/built-ins/toBool Demonstrates the basic usage of the toBool function with string literals. ```reviewpad $toBool("true") ``` ```reviewpad $toBool("false") ``` -------------------------------- ### Blacklist binary files in Reviewpad workflow Source: https://docs.reviewpad.com/guides/built-ins/isBinaryFile This example demonstrates how to use the isBinaryFile built-in within a reviewpad.yml configuration to fail a workflow if any binary files are detected. The condition checks if any file in the specified list is binary. ```yaml workflows: - name: blacklist-binary-files run: if: '$any(["file", "folder/file"], ($file: String => $isBinaryFile($file)))' then: $fail("Blacklisted binary files aren't allowed in pull request") ``` -------------------------------- ### Workflow Example: Delete Head Branch After Merge Source: https://docs.reviewpad.com/guides/built-ins/deleteHeadBranch This example shows how to integrate the $deleteHeadBranch() built-in into a reviewpad.yml workflow. It will merge the pull request and then delete the head branch, but only if the pull request contains only files with .md extensions. ```yaml workflows: - name: check-compliance run: if: $containsOnlyFileExtensions([".md"]) then: - $merge() - $deleteHeadBranch() ``` -------------------------------- ### Extend Reviewpad Configurations Source: https://docs.reviewpad.com/guides/syntax Use the `extends` property with a list of GitHub blob URLs to inherit settings from other Reviewpad configurations. Ensure URLs point to GitHub blobs, otherwise an error will occur. ```yaml extends: - https://github.com/reviewpad/reviewpad/.github/blob/main/reviewpad-models/common.yml ``` -------------------------------- ### Get Organization Members Source: https://docs.reviewpad.com/guides/built-ins/getOrganizationMembers Retrieves all the members of the organization to which the pull request or issue is linked. ```APIDOC ## getOrganizationMembers() ### Description Retrieves all the members of the organization to which the pull request or issue is linked. ### Parameters _none_ ### Return value - **[]string** - The list of all the members within the organization. ### Request Example ``` $getOrganizationMembers() ``` ``` -------------------------------- ### Get Comments Source: https://docs.reviewpad.com/guides/built-ins/getComments Retrieves the list of comment bodies for the current pull request or issue. ```APIDOC ## getComments() ### Description Retrieves the list of comment body of the pull request / issue. ### Parameters _none_ ### Return value Type| Description ---|--- `[]string`| The list of comment body of the pull request / issue. ### Examples ``` $getComments() ``` ``` -------------------------------- ### Basic String Joining Source: https://docs.reviewpad.com/guides/built-ins/join Demonstrates joining an array of strings with a space and a comma-space separator. This function is useful for creating human-readable strings from lists. ```shell $join(["alice", "bob"], " ") # "alice bob" ``` ```shell $join(["alice", "bob"], ", ") # "alice, bob" ``` -------------------------------- ### Get User Teams Source: https://docs.reviewpad.com/guides/built-ins Fetches a list of all teams to which a specified user belongs. Requires the username as a parameter. ```javascript $getUserTeams("Paul") ``` ```yaml workflows: - name: review assignment policy in case the author belongs to team 'onboarding' on: - pull_request run: - if: $isElementOf("onboarding", $getUserTeams($getAuthor())) then: $addReviewers(["paul", "freddy"], 1) ``` -------------------------------- ### Get Milestone Title Source: https://docs.reviewpad.com/guides/built-ins Retrieves the milestone title associated with the pull request. This function is unavailable for issues. ```yaml $getMilestone() ``` ```yaml workflows: - name: label-milestone run: - if: $getMilestone() == "Hacktoberfest" then: $addLabel("hacktoberfest") - if: $startsWith($getMilestone(), "v") then: $addLabel("release") ``` -------------------------------- ### Call countApprovals() Source: https://docs.reviewpad.com/guides/built-ins/countApprovals This is how you call the countApprovals() built-in function. ```shell $countApprovals() ``` -------------------------------- ### Check String Prefix with StartsWith Source: https://docs.reviewpad.com/guides/built-ins Evaluates if a string begins with a specified prefix. This comparison is case-sensitive. Useful for conditional logic based on branch names or text patterns. ```javascript $startsWith("Testing string contains", "Test") ``` ```javascript $startsWith("Testing string contains", "string contains") ``` ```yaml workflows: - name: label-change-type run: - if: $startsWith($getHeadBranch(), "feature/") then: $addLabel("feature") - if: $startsWith($getHeadBranch(), "fix/") then: $addLabel("fix") ``` -------------------------------- ### Get Milestone Title Source: https://docs.reviewpad.com/guides/built-ins/getMilestone Call the getMilestone built-in to retrieve the milestone title. This function takes no parameters. ```bash $getMilestone() ``` -------------------------------- ### Overriding Workflows with Extends Source: https://docs.reviewpad.com/guides/extends Demonstrates how properties are overridden when importing configurations. The last specified configuration in the 'extends' list takes precedence. ```yaml extends: - https://github.com/baz/foo/blob/main/common.yml - https://github.com/baz/qux/blob/main/team_a.yml workflows: - name: small-size run: if: $getSize() < 30 then: $reportInfo("this is a small pr") ``` -------------------------------- ### Using matchString in reviewpad.yml for Branch Naming Conventions Source: https://docs.reviewpad.com/guides/built-ins/matchString Shows how to use matchString within a reviewpad.yml configuration file to enforce branch naming conventions. This example checks if the current branch name does not match a specified pattern. ```yaml workflows: - name: branch-convention run: if: '!$matchString("(feature|fix|docs)/.+", $getHeadBranch())' then: $reportBlocker("The branch name must start with 'feature/', 'fix/' or 'docs/'") ``` -------------------------------- ### Get Pull Request/Issue Title Source: https://docs.reviewpad.com/guides/built-ins Retrieves the title of the current pull request or issue. This function does not require any parameters. ```javascript $getTitle() ``` ```yaml workflows: - name: check-compliance run: if: $getTitle() == "" then: $fail("A pull request must have a title") ``` -------------------------------- ### Get Comments Function Source: https://docs.reviewpad.com/guides/built-ins/getComments Call the getComments() function to retrieve the list of comment bodies. This function takes no parameters. ```bash $getComments() ``` -------------------------------- ### Using startsWith in Reviewpad Workflows Source: https://docs.reviewpad.com/guides/built-ins/startsWith An example of using the startsWith function within a reviewpad.yml file to conditionally add labels based on the head branch name. This snippet shows how to integrate startsWith with other Reviewpad functions like $getHeadBranch(), $addLabel(), and conditional logic. ```yaml workflows: - name: label-change-type run: - if: $startsWith($getHeadBranch(), "feature/") then: $addLabel("feature") - if: $startsWith($getHeadBranch(), "fix/") then: $addLabel("fix") ``` -------------------------------- ### Get Assignees Function Source: https://docs.reviewpad.com/guides/built-ins/getAssignees Call the `getAssignees()` function to retrieve the list of assignees for the current pull request or issue. ```shell $getAssignees() ``` -------------------------------- ### Filter Slice Elements Source: https://docs.reviewpad.com/guides/built-ins/filter Filters a slice of strings, returning only those that start with 'a'. This demonstrates basic usage with a lambda function. ```reviewpad '$filter(["aa", "ab", "bb", "cc"], ($e: String => $startsWith($e, "a")))' # ["aa", "ab"] ``` -------------------------------- ### Workflow Example with Annotation Check Source: https://docs.reviewpad.com/guides/built-ins/containsCodeAnnotation This `reviewpad.yml` configuration demonstrates how to use `$containsCodeAnnotation` within a workflow. If changes include symbols annotated with 'security', it adds members of the 'security' team as reviewers. ```yaml workflows: - name: security-changes run: if: $containsCodeAnnotation("security") then: $addReviewers($getTeamMembers("security"), 1) ``` -------------------------------- ### Disable a Single Action Source: https://docs.reviewpad.com/guides/built-ins/disableActions Use this to disable a specific action like assigning a reviewer. This is a basic example of how to call the function. ```bash $disableActions(["assignReviewer"]) ``` -------------------------------- ### Get Last Event Time Source: https://docs.reviewpad.com/guides/built-ins Retrieves the timestamp of the last event in the timeline. Used to check time-based conditions in workflows. ```yaml $getLastEventTime() ``` ```yaml workflows: - name: stale run: if: $getLastEventTime() < 30 days ago then: - $addLabel("stale") - $addComment("This pull request has been automatically marked as stale") ``` -------------------------------- ### Assign Reviewers from Dictionary Source: https://docs.reviewpad.com/guides/built-ins/dictionaryValueFromKey This example demonstrates how to use dictionaryValueFromKey within a workflow to dynamically add reviewers based on project labels. It checks if a label is present and then adds reviewers from the specified dictionary key. ```yaml dictionaries: - name: seniors description: Senior developers by team spec: devops: '["blair", "casey", "max"]' qa: '["devon", "taylor"]' workflows: - name: name run: - if: $isElementOf("infra", $getLabels()) then: $addReviewers($dictionaryValueFromKey("seniors", "devops")) - if: $isElementOf("debug", $getLabels()) then: $addReviewers($dictionaryValueFromKey("seniors", "qa")) ``` -------------------------------- ### Get Event Type Source: https://docs.reviewpad.com/guides/built-ins/getEventType Call the getEventType() function to retrieve the current event type. This is useful for debugging or simple checks. ```bash $getEventType() ``` -------------------------------- ### Approve a pull request review Source: https://docs.reviewpad.com/guides/built-ins Use `$approve` as a shortcut for `$review("APPROVE", )` to submit an approved review. An optional message can be included. ```reviewpad $approve() ``` ```reviewpad $approve("LGTM") ``` -------------------------------- ### Conditional Workflow with Changed Built-in Source: https://docs.reviewpad.com/guides/built-ins/changed This example demonstrates how to use the 'changed' built-in within a reviewpad.yml workflow to conditionally fail a run if tests for Java files are missing. It checks if for every Java file in 'src', a corresponding file in 'test' is not present. ```yaml workflows: - name: validate-changes run: if: $changed("src/@1.java", "test/@1.java") == false then: $fail("Please include tests for your change.") ``` -------------------------------- ### Format Code Source: https://docs.reviewpad.com/contribute Format your code according to project standards. This command helps maintain code consistency. ```bash task format ``` -------------------------------- ### Define a Label Source: https://docs.reviewpad.com/guides/syntax Configure labels with an ID, optional name, description, and color. If a label doesn't exist, it will be created. Existing labels can have their description and color updated. ```yaml labels: small: name: small # optional description: Defines a small pull request # optional color: d2697a # optional ``` -------------------------------- ### Reviewpad Workflow: Deprecated Project Issue Source: https://docs.reviewpad.com/guides/built-ins/close An example of a Reviewpad workflow that closes an issue with a 'not_planned' reason if the project is identified as 'jupiter'. ```yaml workflows: - name: project_deprecated on: - "issue" run: if: $isElementOf("jupiter", $getLabels()) then: $close("The project `jupiter` is deprecated", "not_planned") ``` -------------------------------- ### Basic Usage of hasAnyCheckRunCompleted Source: https://docs.reviewpad.com/guides/built-ins/hasAnyCheckRunCompleted This example demonstrates the most basic usage of the hasAnyCheckRunCompleted function, which returns true if any check run has completed with any conclusion. It's useful for triggering actions when any check process finishes. ```yaml workflows: - name: has-any-check-run-completed run: if: $hasAnyCheckRunCompleted() then: $addComment("Hello") ``` -------------------------------- ### Get Pull Request/Issue Description Source: https://docs.reviewpad.com/guides/built-ins Retrieves the description of a pull request or issue. This is useful for validating or acting upon the content of the description. ```yaml workflows: - name: check-conventions run: if: $getDescription() == "" then: $fail("Pull request description is empty") ``` -------------------------------- ### Get Base Branch Name Source: https://docs.reviewpad.com/guides/built-ins Retrieves the name of the branch that the pull request is intended to be merged into. Note: This built-in is unavailable for issues. ```reviewpad $getBaseBranch() ``` ```reviewpad workflows: - name: staging-changes run: if: $getBaseBranch() == "stage" then: $reportInfo("Please make sure you've tested your changes in staging environment.") ``` -------------------------------- ### Basic String Formatting with Sprintf Source: https://docs.reviewpad.com/guides/built-ins/sprintf Use sprintf to format a string by replacing '%s' with the provided argument. The argument must be passed as a list. ```shell $sprintf("Hello, %s!", ["world"]) ``` -------------------------------- ### Get Reviewers of a Pull Request Source: https://docs.reviewpad.com/guides/built-ins/reviewers Retrieves the list of GitHub user logins that have reviewed the pull request. This built-in is unavailable for issues. ```reviewpad $reviewers() ``` -------------------------------- ### Check File Extensions Source: https://docs.reviewpad.com/guides/built-ins/containsOnlyFileExtensions Use this built-in to verify if all changed files in a patch have extensions that match the specified glob patterns. Ensure extensions are provided as strings, e.g., ".ts" or ".test.ts". ```reviewpad $containsOnlyFileExtensions(["\.test\.ts"]) ``` -------------------------------- ### Call titleLint() Source: https://docs.reviewpad.com/guides/built-ins/titleLint This is how you call the titleLint built-in. It takes no parameters. ```shell $titleLint() ``` -------------------------------- ### Using $any with a Predicate Source: https://docs.reviewpad.com/guides/built-ins/any Demonstrates how to use the $any function to check if any element in a string slice matches a given predicate. The predicate is defined as a lambda function. ```reviewpad $any(["a", "b"], ($el: String => $el == "a")) # true ``` -------------------------------- ### Reviewpad Configuration Structure Source: https://docs.reviewpad.com/guides/syntax The fundamental structure of a Reviewpad configuration file, outlining all available top-level properties. ```yaml metrics-on-merge: true | false extends: - configuration_1 - configuration_2 ... - configuration_N labels: label_1 label_2 ... label_N groups: - group_1 - group_2 ... - group_N dictionaries: - dictionary_1 - dictionary_2 ... - dictionary_N rules: - rule_1 - rule_2 ... - rule_N workflows: - workflow_1 - workflow_2 ... - workflow_N checks: check_1 check_2 ... check_N ``` -------------------------------- ### Conditional Workflow with hasLabel Source: https://docs.reviewpad.com/guides/built-ins/hasLabel Example of using hasLabel within a reviewpad.yml workflow to assign reviewers if a 'bug' label is present on a pull request. ```yaml workflows: - name: assign for review to Paul in case of a bug on: - pull_request run: if: $hasLabel("bug") then: $addReviewers(["paul"]) ``` -------------------------------- ### Conditional Actions with List of Actions Source: https://docs.reviewpad.com/guides/syntax Demonstrates using lists of actions within both 'then' and 'else' blocks of a conditional. ```yaml workflows: - name: label run: - $addLabel("bug") - $addLabel("documentation") - if: $getSize() < 100 then: # Run a list of actions - $addLabel("small") - $reportInfo("The pull request size is small") else: # Run a list of actions - $addLabel("large") - if: $getSize() > 500 # Run a single action then: $reportInfo("The pull request size is very large") - $addReviewerRandomly() ``` -------------------------------- ### Check for Linear History Source: https://docs.reviewpad.com/guides/built-ins/hasLinearHistory This is a basic usage example of the `hasLinearHistory` built-in. It can be called directly to check the current pull request's history. ```shell $hasLinearHistory() ``` -------------------------------- ### Assign Author if No Assignees Source: https://docs.reviewpad.com/guides/built-ins/getAssignees This example demonstrates a common use case in `reviewpad.yml` where the author is assigned if no assignees are found using `getAssignees()` and `getAuthor()`. ```yaml workflows: - name: by-default-assign-to-author run: if: $getAssignees() == [] then: $addAssignees([$getAuthor()]) ``` -------------------------------- ### Execute Rebase Source: https://docs.reviewpad.com/guides/built-ins/rebase This is the direct command to execute the rebase built-in. Ensure the context supports rebase operations before calling. ```shell $rebase() ``` -------------------------------- ### Workflow to Disallow Binary Files Source: https://docs.reviewpad.com/guides/built-ins/containsBinaryFiles This example demonstrates how to use the $containsBinaryFiles() built-in within a reviewpad.yml workflow to automatically close pull requests and report a blocker if any binary files are detected. ```yaml workflows: - name: disallow-binary-file run: if: $containsBinaryFiles() then: - $close() - $reportBlocker("Please don't add any binary file into the repository") ``` -------------------------------- ### Get Pull Request/Issue State Source: https://docs.reviewpad.com/guides/built-ins Retrieves the current state of a pull request or issue, which can be either 'open' or 'closed'. This function does not require any parameters. ```javascript $getState() ``` ```yaml workflows: - name: thank-contributors run: if: $getState() == "closed" then: $reportInfo("Thanks for your contribution!") ``` -------------------------------- ### Get Organization Members Source: https://docs.reviewpad.com/guides/built-ins Retrieves a list of all members in the organization linked to the pull request or issue. Useful for checking if an author is part of the organization. ```yaml $getOrganizationMembers() ``` ```yaml workflows: - name: external-contributions run: if: $isElementOf($getAuthor(), $getOrganizationMembers()) == false then: - $addTeamsForReview(["core"]) - $addLabel("external-contributor") - $addComment("Thank you for your contribution!") ```