Install/run via webhooks service

The webhooks service is best suited for continuous, automated reviews.

Installation and Configuration Steps:

  1. Prerequisites: Before proceeding, ensure you've completed all necessary prerequisites for self-hosted AI Code Review Agent.

  2. Server Requirement: Ensure you have a server with a domain name or IP address.

  3. Start Docker: Initialize Docker on your server.

  4. Repository Download: Download the AI Code Review Agent GitHub repository on your server.

  5. Extract and Navigate:

    • Extract the downloaded .zip file to a preferred location.

  • Navigate to the extracted folder and then to the “cra-scripts” subfolder.

  • Note the full path to the “cra-scripts” folder for later use.

  1. Open Command Line:

    • Use Bash for Linux and macOS.

    • Use PowerShell for Windows.

  2. Set Directory:

    • Change the current directory in Bash/PowerShell to the “cra-scripts” folder.

    • Example command: cd [Path to cra-scripts folder]

    • Adjust the path based on your extraction location.

  1. Configure Properties:

    • Open the bito-cra.properties file in a text editor from the “cra-scripts” folder.

    • Set mandatory properties:

      • mode = server

      • bito_cli.bito.access_key

      • git.access_token

    • Optional properties (can be skipped or set as needed):

      • git.provider

      • code_feedback

      • static_analysis

      • dependency_check

      • dependency_check.snyk_auth_token

      • server_port

Note: Detailed information for each property is provided on Agent Configuration: bito-cra.properties File page.

Check the Required Access Tokens guide to learn more about creating the access tokens needed to configure the Agent.

  1. Run the Agent:

    • On Linux/macOS in Bash: Run ./bito-cra.sh service start bito-cra.properties

    • On Windows in PowerShell: Run ./bito-cra.ps1 service start bito-cra.properties

This step might take time initially as it pulls the Docker image and performs the code review.

  1. Provide Missing Property Values: The script may prompt for values of mandatory/optional properties if they are not preconfigured.

  2. Copy Webhook Secret: During the script execution, a webhook secret is generated and displayed in the shell. Copy the string displayed under "Use below as Gitlab and Github Webhook secret:" for use in GitHub/GitLab.

  1. Add Webhook:

    • GitHub Webhook Setup Guide:

      • Login to your GitHub account.

      • Navigate to the main page of the repository. Under your repository name, click Settings.

      • In the left sidebar, click Webhooks.

      • Click Add webhook.

      • Under Payload URL, enter the URL of the webhook endpoint. This is the server's URL to receive webhook payloads.

        • Note: The GitHub Payload URL should follow this format: https://<domain name/ip-address>/api/v1/github_webhhooks, where https://<domain name/ip-address> should be mapped to Bito's AI Code Review Agent container, which runs as a service on a configured TCP port such as 10051. Essentially, you need to append the string "/api/v1/github_webhooks" (without quotes) to the URL where the AI Code Review Agent is running.

        • For example, a typical webhook URL would be https://cra.example.com/api/v1/github_webhooks

      • Select the Content type “application/json” for JSON payloads.

      • In Secret token, enter the webhook secret token that you copied above. It is used to validate payloads.

      • Click on Let me select individual events to select the events that you want to trigger the webhook. For code review select these:

        • Issue comments

        • Pull requests

      • To make the webhook active immediately after adding the configuration, select Active.

      • Click Add webhook.

    • GitLab Webhook Setup Guide:

      • Login to your GitLab account.

      • Select the repository where the webhook needs to be configured.

      • On the left sidebar, select Settings > Webhooks.

      • Select Add new webhook.

      • In URL, enter the URL of the webhook endpoint. This is the server's URL to receive webhook payloads.

        • Note: The GitLab webhook URL should follow this format: https://<domain name/ip-address>/api/v1/gitlab_webhhooks, where https://<domain name/ip-address> should be mapped to Bito's AI Code Review Agent container, which runs as a service on a configured TCP port such as 10051. Essentially, you need to append the string "/api/v1/gitlab_webhooks" (without quotes) to the URL where the AI Code Review Agent is running.

        • For example, a typical webhook URL would be https://cra.example.com/api/v1/gitlab_webhooks

      • In Secret token, enter the webhook secret token that you copied above. It is used to validate payloads.

      • In the Trigger section, select the events to trigger the webhook. For code review select these:

        • Comments

        • Merge request events

      • Select Add webhook.


Using the AI Code Review Agent

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

  1. Automated Code Review: If the webhook is configured to be triggered on the Pull requests event (for GitHub) or Merge request event (for GitLab), 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. If the webhook is configured to be triggered on the Issue comments event (for GitHub) or Comments event (for GitLab), this action will initiate the code review process. The /review command prompts the agent to review the pull request and post its feedback directly in the PR as a comment.

    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 a new optional parameter: /review #inline_comment=False

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


Stop Docker Container

To stop the Docker container running as a service, use the below command.

  • On Linux/macOS in Bash: Run ./bito-cra.sh service stop

  • On Windows in PowerShell: Run ./bito-cra.ps1 service stop


Restart Docker Container

To restart the Docker container running as a service, use the below command.

  • On Linux/macOS in Bash: Run ./bito-cra.sh service restart bito-cra.properties

  • On Windows in PowerShell: Run ./bito-cra.ps1 service restart bito-cra.properties


Check Status

To check the status of Docker container running as a service, use the below command.

  • On Linux/macOS in Bash: Run ./bito-cra.sh service status

  • On Windows in PowerShell: Run ./bito-cra.ps1 service status

Last updated

Logo

Bito Inc. (c) 2024