Install/run via GitHub Actions

Seamlessly integrate automated code reviews into your GitHub Actions workflows.

Prerequisites

  • Bito Access Key: Obtain your Bito Access Key. View Guide

  • GitHub Personal Access Token (Classic): For GitHub PR code reviews, ensure you have a CLASSIC personal access token with repo access. We do not support fine-grained tokens currently. View Guide


Installation and Configuration Steps:

  1. Enable GitHub Actions:

    • Login to your GitHub account.

    • Open your repository and click on the "Settings" tab.

    • Select "Actions" from the left sidebar, then click on "General".

    • Under "Actions permissions", choose "Allow all actions and reusable workflows" and click "Save".

  2. Set Up Environment Variables:

    • Still in the "Settings" tab, navigate to "Secrets and variables" > "Actions" from the left sidebar.

    • Configure the following under the "Secrets" tab:

      For each secret, click the New repository secret button, then enter the exact name and value of the secret in the form. Finally, click Add secret to save it.

      • Name: BITO_ACCESS_KEY

      • Name: GIT_ACCESS_TOKEN

        • Secret: Enter your GitHub Personal Access Token (Classic) with repo access. We do not support fine-grained tokens currently. For more information, see the Prerequisites section.

Check the above "Prerequisites" section to learn more about creating the access tokens needed to configure the Agent.

  • Configure the following under the "Variables" tab:

    For each variable, click the New repository variable button, then enter the exact name and value of the variable in the form. Finally, click Add variable to save it.

    • Name: STATIC_ANALYSIS_TOOL

      • Value: Enter the following text string as value: fb_infer,astral_ruff,mypy

    • Name: GIT_DOMAIN

      • Value: Enter the domain name of your Enterprise or self-hosted GitHub deployment or skip this if you are not using Enterprise or self-hosted GitHub deployment.

      • Example of domain name: https://your.company.git.com

    • Name: EXCLUDE_BRANCHES

      • Value: Specify branches to exclude from the review by name or valid glob/regex patterns. The agent will skip the pull request review if the source or target branch matches the exclusion list.

      • Note: For more information, see Source or Target branch filter.

    • Name: EXCLUDE_FILES

      • Value: Specify files/folders to exclude from the review by name or glob/regex pattern. The agent will skip files/folders that match the exclusion list.

      • Note: For more information, see Files and folders filter.

    • Name: EXCLUDE_DRAFT_PR

      • Value: Enter True to disable automated review for draft pull requests, or False to enable it.

      • Note: For more information, see Draft pull requests filter.

  1. Create the Workflow Directory:

    • In your repository, create a new directory path: .github/workflows.

  2. Add the Workflow File:

    • Download this test_cra.yml file from AI Code Review Agent's GitHub repo.

    • In your repository, upload this test_cra.yml file inside the .github/workflows directory either in your source branch of each PR or in a branch (e.g. main) from which all the source branches for PRs will be created.

    • Commit your changes.

Customizations for self-hosted GitHub

  1. Create a self-hosted Runner using Linux image and x64 architecture as described in the GitHub documentation.

  2. Create a copy of Bito's repository gitbito/codereviewagent main branch into your self-hosted GitHub organization e.g. "myorg" under the required name e.g. "gitbito-bitocodereview". In this example, now this repository will be accessible as "myorg/gitbito-bitocodereview".

  3. Update test_cra.ymlas below:

    • Change line from:

      • runs-on: ubuntu-latest

    • to:

      • runs-on: <label of the self-hosted GitHub Runner> e.g. self-hosted, linux etc.

  4. Update test_cra.ymlas below:

    • Replace all lines having below text:

      • uses: gitbito/codereviewagent@main

    • with:

      • uses: myorg/gitbito-bitocodereview@main

  5. Commit and push your changes in test_cra.yml .

Using the AI Code Review Agent

After configuring the GitHub Actions, you can invoke the AI Code Review Agent in the following ways:

Note: To improve efficiency, the AI Code Review Agent is disabled by default for pull requests involving the "main" branch. This prevents unnecessary processing and token usage, as changes to the "main" branch are typically already reviewed in release or feature branches. To change this default behavior and include the "main" branch, please contact support.

  1. Automated Code Review: The agent will automatically review new pull requests as soon as they are created and post the review feedback as a comment within your PR.

  2. Manually Trigger Code Review: To start the process, simply type /review in the comment box on the pull request and submit it. This command prompts the agent to review the pull request and post its feedback directly in the PR as a comment.

    Bito also offers specialized commands that are designed to provide detailed insights into specific areas of your source code, including security, performance, scalability, code structure, and optimization.

    • /review security: Analyzes code to identify security vulnerabilities and ensure secure coding practices.

    • /review performance: Evaluates code for performance issues, identifying slow or resource-heavy areas.

    • /review scalability: Assesses the code's ability to handle increased usage and scale effectively.

    • /review codeorg: Scans for readability and maintainability, promoting clear and efficient code organization.

    • /review codeoptimize: Identifies optimization opportunities to enhance code efficiency and reduce resource usage.

    By default, the /review command generates inline comments, meaning that code suggestions are inserted directly beneath the code diffs in each file. This approach provides a clearer view of the exact lines requiring improvement. However, if you prefer a code review in a single post rather than separate inline comments under the diffs, you can include the optional parameter: /review #inline_comment=False

    For more details, refer to Available Commands.

It may take a few minutes to get the code review posted as a comment, depending on the size of the pull request.

Last updated

Logo

Bito Inc. (c) 2024