Introduction to the PAT
To enable Kody to perform automatic Code Reviews, you need to generate a Personal Access Token (PAT) in GitLab. This token allows Kody to securely access your repositories and conduct code analysis in a controlled way. Kody posts reviews as the GitLab user the token belongs to. With a personal access token, reviews appear under your own account, as they do when you connect with OAuth. To have them appear under a separate bot user, use a group access token, described below.Generating the PAT (Personal Access Token)
Follow these steps to set up the token correctly:- Access GitLab and go to your profile settings:
-
Navigate to
Access Tokens:- In the left sidebar, scroll to find
Access Tokensand click on it.
- In the left sidebar, scroll to find
-
Add a new token:
- Click on the
Add new tokenbutton.
- Click on the
-
Set up the new token with the following specifications:
- Token Name: Choose an easily identifiable name, such as
kody_code_review. - Expiration Date: If possible, select a long expiration date, preferably at least 180 days.
- Permissions: Set the following permissions:
- api
- read_api
- read_user
- read_repository
- write_repository
- Token Name: Choose an easily identifiable name, such as
-
Finalize and save the token:
- After configuring the permissions, click
Generate token. - Make sure to copy the generated token and store it securely, as you’ll need it to configure Kody.
- After configuring the permissions, click
Using a Group Access Token
A group access token posts reviews as a bot user that GitLab creates for the token, named after it. The bot has access to every project in the group and its subgroups.On GitLab.com, group access tokens require a Premium or Ultimate subscription and are not available during a trial. On GitLab Self-Managed and GitLab Dedicated, they are available with any license.
-
Open the group’s access tokens:
- In GitLab, open the group that contains your repositories and go to
Settings>Access tokens.
- In GitLab, open the group that contains your repositories and go to
-
Add a new token:
- Click on the
Add new tokenbutton.
- Click on the
-
Set up the new token with the following specifications:
- Token name: The name Kody’s reviews will show, such as
Kody. - Expiration date: If possible, select a long expiration date, preferably at least 180 days.
- Role:
Maintainer. Kody needs it to create the webhook on each project. - Scopes:
apiandread_repository. Kody clones your repositories, and on a group access tokenapidoes not include Git over HTTPS.
- Token name: The name Kody’s reviews will show, such as
-
Finalize and save the token:
- Click
Create group access token. - Copy the token and store it securely. GitLab shows it only once.
- Click
Adding the Token to Kody
After generating the token, paste it into Kodus:- During onboarding: on Connect your Git tool, pick the Gitlab tab and click Connect via token.
- Later: in the sidebar, open Repositories, click Gitlab under Connect a provider, switch to the Token tab, paste the token and click Validate and save. For a self-managed GitLab, turn on Self-hosted and enter the Gitlab URL.
- Replacing a token: on Repositories, click Update token on the Gitlab card, paste the new token and click Update token. Webhooks and selected repositories are kept.
- Switching from OAuth: Update token is not offered for a connection made with OAuth. Click Reset, choose Just reset the integration, then connect again with the token as described above and select your repositories.