Guide for Bitbucket

Integrate the AI Code Review Agent into your Bitbucket workflow.

Boost your development workflow by configuring the AI Code Review Agent with your Bitbucket repositories. In this guide, you'll learn how to set up the Agent to receive automated code reviews that trigger whenever you create a pull request, as well as how to manually initiate reviews using available commands.

You need a Bito 10X Developer paid plan to get started. For more information about costs, please visit our Pricing Page.

Get a 1-month FREE trial of Bito's AI Code Review Agent.

Video tutorial

Watch the step-by-step guide for setting up Bito's AI Code Review Agent on Bitbucket.

Prerequisites

Before proceeding, ensure you've completed all necessary prerequisites.

  1. Create a Bitbucket Access Token: For Bitbucket pull request code reviews, you can use any of the following types of access tokens: Repository Access Token, Project Access Token, or Workspace Access Token. All these tokens, available for Bitbucket Cloud, are fully compatible with the AI Code Review Agent.

    1. A Repository Access Token grants access to a single repository. To create a token, go to the required repository and click on the left hand side menu Repository Settings and then click on menu Access Token. Click on the button Create Repository Access Token.

      When setting up the token, ensure that the following scopes are selected:

      • Under Webhooks, select Read and write.

      • Under Pull requests, select Write.

      For more information, refer to the Bitbucket documentation.

    2. A Project Access Token grants access to a single project and its repositories. To create a token, go to the required project and click on the left hand side menu Project Settings and then click on menu Access Token. Click on the button Create Project Access Token.

      When setting up the token, ensure that the following scopes are selected:

      • Under Webhooks, select Read and write.

      • Under Pull requests, select Write.

      For more information, refer to the Bitbucket documentation.

    3. A Workspace Access Token grants access to a single workspace, including its repositories and projects. To create a token, click on top-right settings icon and then drop-down menu Workspace Settings (as shown in below screenshot). Click on the left hand side menu Access Token and then click on the button Create Workspace Access Token.

      When creating a token, ensure that the following scopes are selected:

      • Under Webhooks, select Read and write.

      • Under Pull requests, select Write.

      For more information, refer to the Bitbucket documentation.

Installation and configuration steps

Follow the step-by-step instructions below to install the AI Code Review Agent using Bito Cloud:

  1. Log in to Bito Cloud with a workspace subscribed to the Bito 10X Developer plan.

  2. From the left sidebar, click on the Explore Agents menu to view all available Agents for installation.

Currently, we only offer the AI Code Review Agent. More dev agents are coming soon.

  1. Find the Code Review Agent in the list and click the Create New Instance button.

  2. Configure Agent:

    • From the Git provider dropdown menu, select Bitbucket.

    • Generate a Bitbucket Access Token in your Bitbucket account and enter it into the Bitbucket Access Token input field. For guidance, refer to the instructions in the Prerequisites section.

    • Agent actions: This section contains all the actions that the AI Code Review Agent can perform. The Agent can execute these actions as part of a workflow or manually.

      • /review command: Initiate a manual code review by commenting /review on a pull request. It provides separate code suggestions for each detected issue below the code diffs.

      • Additionally, you can pass an optional parameter like /review #inline_comment=False to get code review in a single post.

    • Agent instance details: In this section, you can set the name and description of your Agent instance.

      • Instance name: Assign a unique alphanumeric identifier for your instance. You can invoke the Agent in supported clients using @<instance_name> command.

      • Instance description: Provide a brief description of the specific use case or project where this AI Code Review Agent instance will be deployed. This description will help you easily identify and manage it among multiple instances.

    • Filters: Exclude specific files and folders from code reviews or skip automated reviews for selected Git branches. For more information and examples, see Excluding Files, Folders, or Branches with Filters.

      • Files and folders: A list of files/folders that the AI Code Review Agent will not review if they are present in the diff. You can specify the files/folders to exclude from the review by name or glob/regex pattern. The Agent will automatically skip any files or folders that match the exclusion list. This filter applies to both manual reviews initiated through the /review command and automated reviews triggered via webhook.

      • Source or Target branch: This filter allows users to skip automated reviews for pull requests based on the source or target branch. It is useful in scenarios where automated reviews are unnecessary or could potentially disrupt the workflow. This filter applies only to automatically triggered reviews. Users should still be able to trigger reviews manually via the /review command.

      • Draft pull requests: A toggle switch that controls the automated review of pull requests (PR) based on their draft status. The default setting is enabled (turned on), which means automated review is skipped for draft pull requests.

    • Save configuration: Click Save & view setup instructions to complete the installation and access detailed instructions on configuring the new Agent instance with your repository using webhook.

  3. Add Webhook:

    • You will be redirected to a page that provides the webhook payload URL and secret key needed to set up a webhook in GitHub, along with a detailed step-by-step guide. Follow the guide to successfully integrate the AI Code Review Agent with your repository.

      We have also provided a step-by-step guide below to assist you in adding a webhook in Bitbucket.

Webhook setup guide

You can also consult the official Bitbucket documentation to learn how to create a webhook.

  1. Login to your BitBucket account.

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

  3. On the left sidebar, select Repository Settings > Webhooks.

  4. Select Add webhook.

  5. Enter a Title.

  6. Copy the Webhook URL from the Setup Instructions screen on Bito Cloud. Then, navigate to the webhook creation form in BitBucket, and in URL input field, paste the URL of the webhook endpoint you've just copied. This unique Webhook URL, provided by Bito Cloud, is designed to receive webhook payloads.

  7. Copy the Secret token from the Setup Instructions screen on Bito Cloud. Then, navigate to the webhook creation form in BitBucket, and in Secret token input field, paste the webhook secret token you've just copied. The Secret token is used to validate payloads.

  8. In the Triggers section, select the events to trigger the webhook. For code review select these:

    • Pull Request > Comment created - for on-demand code review.

    • Pull Request > Created - for automatic code review when a pull request is created.

    • Pull Request > Updated - for incremental code review.

    • Pull request > Merged - for evaluating if the issues found by the Bito agent were fixed.

    • Pull request > Declined - for evaluating if the issues found by the Bito agent were fixed.

  9. Select Save.

Using the AI Code Review Agent

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

Note: To enhance efficiency, the AI Code Review Agent is disabled by default for pull requests involving the "main" or "master" branches. This prevents unnecessary processing and token usage, as changes to these branches are typically already reviewed in release or feature branches. To modify this default behavior and include the "main" or "master" branches, you can use the Source or Target branch filter.

The AI Code Review Agent automatically reviews code changes up to 5000 lines when a pull request is created. For larger changes, you can use the /review command.

  1. Automated code review: If the webhook is configured to trigger on the Pull Request > Created event, 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 initiate a manual review, simply type /review in the comment box on the pull request and submit it. If the webhook is configured to trigger on the Pull Request > Comment created event, this action will start 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.

    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.

Screenshots

Screenshot # 1

AI-generated pull request (PR) summary

Screenshot # 2

Changelist showing key changes and impacted files in a pull request.

Screenshot # 3

AI code review feedback posted as comments on the pull request.

Last updated

Logo

Bito Inc. (c) 2024