Skip to content

GitLab Code Reviewer support#61

Open
dennismeister93 wants to merge 19 commits intoKilo-Org:mainfrom
dennismeister93:feature/gitlab-code-review-support
Open

GitLab Code Reviewer support#61
dennismeister93 wants to merge 19 commits intoKilo-Org:mainfrom
dennismeister93:feature/gitlab-code-review-support

Conversation

@dennismeister93
Copy link
Contributor

@dennismeister93 dennismeister93 commented Feb 9, 2026

Summary

  • Add GitLab platform support for the automated code review agent
  • Implement GitLab OAuth callback, webhook handling, and merge request event processing
  • Add GitLab adapter with full MR diffing, commenting, and status reporting
  • Extend cloud_agent_code_reviews schema with platform and platform_project_id columns
  • Support both OAuth and Project Access Token (PAT) authentication for GitLab
  • Add automated GitLab webhook creation for merge request events
  • Refactor code review UI and routers to be platform-agnostic (GitHub + GitLab)

Key Components

  • gitlab/adapter.ts - GitLab platform adapter for code reviews (diff fetching, PR commenting, status updates)
  • gitlab/webhook-handlers/merge-request-handler.ts - Handles GitLab MR webhooks to trigger reviews
  • gitlab/webhook-schemas.ts + webhook-sync.ts - Webhook validation and automated webhook creation
  • gitlab-service.ts - Extended GitLab integration service with OAuth and PAT support
  • prepare-review-payload.ts - Refactored to support multi-platform review payloads
  • platform-helpers.ts - Platform-agnostic prompt generation helpers
  • ReviewConfigForm.tsx / RepositoryMultiSelect.tsx - Updated UI for platform selection
  • cloud-agent / cloud-agent-next - Platform-aware session preparation and orchestration

Notes

  • GitLab reviews use the same cloud-agent infrastructure as GitHub reviews
  • DB migration adds platform column (default 'github') and platform_project_id to cloud_agent_code_reviews
  • Cloud agent Dockerfiles updated to include latest glab CLI with OAuth support

Testing / Reproduce Steps for GitLab Code Review Support

Prerequisites

  1. A GitLab account (gitlab.com works; self-hosted requires Enterprise).
  2. A GitLab project where you have Maintainer role or higher (needed for Project Access Token creation and webhook auto-configuration).
  3. The local dev server running at http://localhost:3000.
  4. Database migrated

1. Connect GitLab Integration

There are two connection methods (toggle in the UI at GitLabIntegrationDetails.tsx):

Option A: OAuth (gitlab.com)

  1. Log in as a fake user → navigate to Settings → Integrations → GitLab.
  2. Click "Connect GitLab" (OAuth button).
  3. Authorize on gitlab.com → callback at /api/integrations/gitlab/callback.
  4. Verify: integration appears as "Connected", repositories listed.

Option B: Personal Access Token (PAT)

  1. On GitLab: User Settings → Access Tokens, create a token with api scope.
  2. In the app, toggle to "Personal Access Token" tab.
  3. Paste the PAT → automatic validation fires (debounced 500ms via validatePAT tRPC mutation).
  4. Green checkmark + username should appear when valid.
  5. Click "Connect GitLab with PAT".
  6. Verify: integration appears as "Connected" with "Personal Access Token" badge.

3. Webhook Configuration

Webhooks are auto-configured when you save the code review settings:

Manual webhook setup (Has to be done for the smee setup):

  1. Go to your GitLab project → Settings → Webhooks.
  2. URL: smee url
  3. Secret Token: copy from integration metadata webhook_secret.
  4. Trigger: Merge request events.
  5. Save.

4. Trigger a Code Review

  1. Open or update a Merge Request on a configured GitLab project (non-draft).
  2. GitLab sends a webhook with X-Gitlab-Event: Merge Request Hook and action open/update/reopen.
  3. The POST /api/webhooks/gitlab handler:
  4. The handler:
  5. Returns 202 Accepted.

5. Review Payload Preparation

When the review is dispatched, prepareReviewPayload() runs:

  • GitHub path: uses githubRepo (owner/repo) + githubToken (installation token).
  • GitLab path: uses gitUrl (full HTTPS URL like https://gitlab.com/group/project.git) + gitToken (PrAT).
  • Fetches existing review state (summary notes, inline comments, head SHA, diff refs) in parallel.
  • Generates the review prompt with GitLab-specific diff context (baseSha/startSha/headSha).

7. Local Testing with ngrok/Cloudflare Tunnel

Since GitLab needs to reach your Webhook its important that the webhook url needs to be manually adapted:
Bildschirmfoto 2026-02-09 um 16 01 07

@dennismeister93 dennismeister93 force-pushed the feature/gitlab-code-review-support branch from 8aaa59a to b2d8d47 Compare February 9, 2026 14:50
@dennismeister93 dennismeister93 marked this pull request as ready for review February 9, 2026 14:55
@dennismeister93
Copy link
Contributor Author

@Sureshkumars @eshurakov @RSO I finally have a state which is working properly.

Can someone have a view and let me know if support is needed?

This PR supports Oauth or PAT integration with gitlab + code review configs with some "GitLab specialties" because they differ to GitHub Apps. Also this integration supports:

  1. Personal
  2. Organizations
  3. Self Hosted GitLab

@dennismeister93 dennismeister93 force-pushed the feature/gitlab-code-review-support branch 2 times, most recently from 9b715b7 to 4687cfd Compare February 10, 2026 18:32
@vercel
Copy link

vercel bot commented Feb 10, 2026

@dennismeister93 is attempting to deploy a commit to the emilie-6161's projects Team on Vercel.

A member of the Team first needs to authorize it.

@dennismeister93 dennismeister93 force-pushed the feature/gitlab-code-review-support branch 2 times, most recently from 00fb88f to 3a4903d Compare February 12, 2026 19:14
@dennismeister93 dennismeister93 force-pushed the feature/gitlab-code-review-support branch from 3a4903d to c55d13e Compare February 16, 2026 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant