title | description | sidebar_label | sidebar_position |
---|---|---|---|
Integrating CodeRabbit with GitLab.com |
Learn how to integrate CodeRabbit and add to your GitLab workflow. |
GitLab.com |
2 |
CodeRabbit integrates with GitLab to enhance code review and collaboration by:
- Automatically initiating code reviews for newly created merge requests.
- Displaying review comments and suggestions directly on merge requests.
- Enabling seamless interaction with the CodeRabbit bot for real-time feedback and assistance.
This guide will assist you in effectively integrating CodeRabbit with SaaS GitLab.
To enable CodeRabbit to interact with your GitLab repositories, an access token is required. This token grants the necessary permissions for interacting with the Merge Requests and Discussions APIs.
1. Personal Access Token (PAT): You can generate a PAT using a service account. We recommend creating a dedicated service account, associating it with the appropriate base group, and generating the PAT from this account.
2. Group Access Token: If your organization uses GitLab Premium or Ultimate, you can generate a Group Access Token. This option automatically creates a bot user associated with the group for managing access and posting reviews.
We recommend creating a new user as a service account, associating this user to the group you'd like to install coderabbit on, and provide CodeRabbit with a the personal access. During the installation process, CodeRabbit will automatically configure the required webhook for seamless integration.
:::note
If you wish to change the review user, you must provide the access token for the new user who will post reviews and comments. However, this requires manually removing the previous user from the projects and associated webhooks. Once this is done, you will need to reinstall the CodeRabbit app for each project.
:::
- Create a dedicated user for CodeRabbit - This ensures the user is exclusively for CodeRabbit, allowing better access control.
- Use "CodeRabbit" as the username - This makes the user easily recognizable for future reference.
- Use a dedicated email address - This helps in easy identification and management.
- Use the CodeRabbit logo as the profile picture - This further ensures easy recognition. You can download our logo from here.
- Developer Access Ensure the service account user has developer access to the group or projects that you wish to install CodeRabbit on.
- Personal access tokens have expiration dates. Ensure the expiration date covers the duration of your intended use of CodeRabbit.
- Code reviews will be attributed to the owner of the personal access token.
- If the personal access token expires, you can add a new one via the CodeRabbit UI:
- Navigate to the GitLab User page in the sidebar.
- Enter the new Access token, and click the Update button on the page.
GitLab provides an option to generate a personal access token for a new user. Follow these steps to generate the token:
- Log in as the user intended for CodeRabbit reviews. You can treat this user as an service account.
- Select your avatar on the left sidebar.
- Choose Edit Profile.
- Select Access Tokens from the left sidebar.
- Click Add New Token.
- Enter a name and an expiry date for the token.
- If no expiry date is entered, it defaults to 365 days from the current date.
- Ensure the following scopes are selected:
api
,read_api
,read_user
. - Click Create Personal Access Token
- Note down the token as it will only be displayed once.
Group Access token automatically create a bot user upon creation. With this, you simply just need to provide us the token and we will take care of the rest. Do keep in mind, a group access token only has a scope of the group it is created for. Additional groups that you wish to install CodeRabbit on will require a new group access token.
:::note
By default, GitLab restricts this option to users on the Premium or Ultimate tiers.
:::
- Navigate to the group you wish to install CodeRabbit on.
- Select Settings from the left sidebar.
- Select Access Tokens within the Settings heading.
- Create a Group Access Token.
- Ensure the following scopes are selected:
api
. - Ensure Developer Access is provided.
By default, if no access token is provided, CodeRabbit will prompt you to provide one during the installation process. However, if you wish to provide the token beforehand, you can do so by navigating to the Organization Settings tab, and selecting the GitLab User tab on the sidebar. Once entering the token, the token will be validated and saved for future use.
You can confirm the correct user is being selected by verifying the user ID shown on the UI with the user ID of the service account user you created.
- Go to the Repositories page in the CodeRabbit app.
- Select the checkbox next to the repositories where you want to install CodeRabbit. To install it on all repositories at once, select the checkbox at the top.
- Select Install Repositories.
The webhook https://coderabbit.ai/gitlabHandler
will now be installed for the projects selected.