Skip to main content

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:
  1. Access GitLab and go to your profile settings:
  2. Navigate to Access Tokens:
    • In the left sidebar, scroll to find Access Tokens and click on it.
  3. Add a new token:
    • Click on the Add new token button. On recent GitLab versions, open the Generate token dropdown and select Legacy token instead.
  4. 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.
    • Under Scopes, select only api for a personal access token. It covers Kody’s API calls and repository access over HTTPS.
  5. 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.

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.
  1. Open the group’s access tokens:
    • In GitLab, open the group that contains your repositories and go to Settings > Access tokens.
  2. Add a new token:
    • Click on the Add new token button.
  3. 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.
    • Under Scopes, select api for API calls and read_repository so Kody can clone the group’s repositories over HTTPS.
  4. Finalize and save the token:
    • Click Create group access token.
    • Copy the token and store it securely. GitLab shows it only once.

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.