GitLab

GitLab is a code platform: kōjō takes requests there from mentions and from the events you map to skills, answers in comments, and opens merge requests. kōjō works with gitlab.com and self-managed GitLab through one access token and one webhook.

See Surfaces for how GitLab compares with GitHub and Forgejo, and Who may trigger what for whose requests may change code.

Set up

  1. Create a project or group access token with the api scope. The token’s bot user is the account kōjō acts as. Give it enough access to create branches and merge requests in the projects it works on.

  2. Add the forge to kojo.yaml. base_url defaults to https://gitlab.com.

    forges:
      gitlab:
        base_url: https://gitlab.example.com
        token: ${GITLAB_TOKEN}
        webhook_secret: ${GITLAB_WEBHOOK_SECRET}
  3. In the project or group, add a webhook with the URL <public_url>/webhooks/gitlab and the secret token set to the value of webhook_secret. Enable comments, issues events, merge request events, pipeline events and push events. Enable the confidential variants of comments and issues if kōjō should see them. A session a confidential issue or an internal note starts never gets a shareable report.

  4. Enable the repositories in the dashboard. The ID is gitlab/ followed by the project’s full path.

  5. Run kojo doctor. It checks that GitLab answers, that the token is active and not expired, and that it has the api scope. GitLab before 15.5 cannot describe a token, so there the scope check is skipped.

Events

X-Gitlab-Event Becomes
Note Hook, Confidential Note Hook A mention, when a new comment on an issue or merge request mentions the bot user. On a merge request, any other new comment is pr_comment, or pr_review_comment when it is on a line of the diff: feedback
Issue Hook, Confidential Issue Hook (action open) issue_opened, or a mention when the description mentions the bot user
Merge Request Hook (open, reopen, or taken out of draft) pr_opened, or a mention when a newly opened merge request’s description mentions the bot user
Merge Request Hook (update with new commits) pr_updated
Merge Request Hook (merge, close) pr_closed: the merge request was merged, or closed without merging
Pipeline Hook (status failed, not a tag pipeline) check_failed
Push Hook to a branch A reload of .factory/, when the branch is the default branch

The mention is @ plus the username of the token’s bot user. For a project access token that is a generated name such as project_123_bot_....

GitLab has no review text of its own: the summary of a review and each of its comments on the diff arrive as comments, so the “comments” and “merge request events” triggers above are all that learning from reviews needs. A comment on the diff carries its file and line but not the diff; kōjō reads the merge request’s diff for it.

Webhook

The webhook is authenticated by comparing X-Gitlab-Token with forges.gitlab.webhook_secret in constant time. Redeliveries are de-duplicated by Idempotency-Key (GitLab 17.4 and later) or X-Gitlab-Event-UUID.

The status codes kōjō answers a delivery with are the same for every forge: see webhook responses.

Follow-ups

On a merge request kōjō opened, a mention, or a failed pipeline where the repository opts in, starts a follow-up that commits to the merge request’s branch. What it uses on GitLab:

  • The review, for get_review_comments: the merge request’s notes that are on a line of the diff, with their file and line (a note on a removed line has the old file’s line). GitLab’s approval has no text, and a comment on the merge request itself is one of its comments, not part of the review. At most the newest 300.
  • The checks, for get_check_runs: the jobs of the latest pipeline per ref and source of the commit. For a failed job, its failure reason and the end of its log, read from GET /jobs/{id}/trace for the first five failed jobs, without terminal colours and section markers, cut to its last 16 KiB. A job allowed to fail counts as passed. A commit without pipelines lists its commit statuses with their descriptions.
  • Which merge request a failed pipeline is about: the merge request the Pipeline Hook names, or else the pipeline’s ref among the open merge requests kōjō recorded.
  • The commit: written through the commits API on top of the commit the session cloned. The branch is read first and must point there, and each updated or deleted file names the last commit that changed it there (last_commit_id), so GitLab refuses the commit when a push in between changed one of those files.
  • A person’s merge request (commits on a person’s pull request): who added the kojo:commit label is the latest add of the merge request’s resource label events (GET /merge_requests/{iid}/resource_label_events) that no remove follows, read from at most 10 pages of 100; more events count as no adder, with a warning. On GitLab a Reporter can add labels, so it counts only when the person who added it has trigger_permission. A merge request whose source project is another one (a fork) is never written to. A failed pipeline on such a merge request is matched by the merge request the hook names, or else by its ref among the project’s open merge requests from the project itself.

Clone credentials

Not short-lived. GitLab has no equivalent of an installation token. For clones, kōjō hands the proxy the configured token itself. The token is not scoped to one repository, it can write, and it lives until its own expiry date.

The token never enters the sandbox: the proxy injects it, as Basic auth for git. kojo-proxy treats it as read-only. It sets the token only on git’s fetch: GET …/<project>/info/refs?service=git-upload-pack and POST …/<project>/git-upload-pack, with or without .git, outside /api/v4 and /api/graphql. Everything else goes out without it. A push or a writing API call cannot use it, and neither can an API read: for a Maintainer those include the project’s CI/CD variables (GET /api/v4/projects/:id/variables) and its runners token (in GET /api/v4/projects/:id). GET /jwt/auth and GET …/conan/<version>/users/authenticate, which answer with a registry token that can push, are refused it on every host as well, so the GitLab container and Conan registries cannot be used with the clone credential from a sandbox.

With sbx. Docker Sandboxes’ own proxy sets the token on every request to the GitLab host. The sbx driver adds deny rules there, so a push, a writing API call or a registry token request is refused with sbx’s 403 (see Read-only credentials).

Limits

  • Merges use merge or squash. GitLab cannot rebase and merge in one call.
  • A push payload carries at most 20 commits. For a larger push the changed files are unknown.
  • Required reviews come from approval rules, which only paid tiers have.
Scroll to move. + - zoom, 0 fit, Esc close.100%