# GitLab Integration

Source: https://docs.ops0.com/docs/settings/integrations/gitlab

ops0 supports GitLab as a version control provider alongside GitHub. You can sync IaC projects, configurations, and discovery assets to GitLab repositories, create merge requests, and manage branches directly from ops0.

---

## Supported Features

| Feature | Description |
|---------|-------------|
| **Repository Sync** | Push and pull IaC code to/from GitLab repos |
| **Merge Requests** | Create MRs with templated descriptions from ops0 |
| **Branch Management** | Create branches, switch between them |
| **Multi-Purpose** | Connect GitLab for IaC, Configurations, Discovery, or Assets |
| **Self-Hosted** | Supports self-hosted GitLab instances with custom URLs |

---

## Adding a GitLab Integration

### Navigate to Integrations
Go to **Settings** > **Integrations** > **Add Integration**.

### Select GitLab
Choose **GitLab** from the provider list.

### Choose Token Type
Select the type of access token you want to use.

### Enter Credentials
Provide your token and, if using a self-hosted instance, your GitLab URL.

### Connect
Click **Connect** to verify the integration.

![GitLab integration setup in ops0](https://docs.ops0.com/images/settings-integrations-gitlab.png)

---

## Authentication Methods

Personal Access Token

Full access tied to your user account

Group Access Token

Scoped to a specific GitLab group

Project Access Token

Scoped to a single repository

### Integration Fields

| Field | Required | Description |
|-------|----------|-------------|
| **Name** | Yes | Integration name |
| **Token Type** | Yes | Personal, Group, or Project |
| **Access Token** | Yes | GitLab access token |
| **GitLab URL** | No | Custom URL for self-hosted instances (defaults to gitlab.com) |

### Required Token Scopes

| Scope | Purpose |
|-------|---------|
| **api** | Full API access for repository operations |
| **read_repository** | Read repository content |
| **write_repository** | Push code and create branches |

---

## Self-Hosted GitLab

If your organization runs a self-hosted GitLab instance, enter the full URL (e.g., `https://gitlab.yourcompany.com`) when adding the integration. ops0 will use the GitLab API v4 at that URL instead of gitlab.com.

**Network Access**

Your self-hosted GitLab instance must be reachable from ops0's servers. If it's behind a VPN or firewall, ensure the appropriate network rules are in place.

---

## Connecting a Project to GitLab

After adding a GitLab integration, you can link it to IaC projects, configuration projects, or discovery sessions.

### Open Project Settings
In your IaC or Configuration project, go to **Settings** > **Version Control**.

### Select GitLab
Choose your GitLab integration from the dropdown.

### Choose Repository
Browse your GitLab groups and select the target repository.

### Configure Branch
Set the default branch for syncing (e.g., `main` or `develop`).

### Sync Direction
Choose whether to push from ops0 to GitLab, pull from GitLab to ops0, or bidirectional sync.

---

## Creating Merge Requests

When you sync changes from ops0 to GitLab, ops0 can automatically create a merge request with a templated description that includes the change summary, affected resources, and policy check results.

| MR Field | Auto-populated |
|----------|----------------|
| **Title** | Change description from ops0 |
| **Description** | Resources changed, policy results, cost impact |
| **Source Branch** | ops0 working branch |
| **Target Branch** | Configured default branch |

---

## Credential Security

All GitLab access tokens are encrypted at rest using AES-256-GCM encryption. Tokens are only decrypted in memory during API calls. ops0 never logs or displays tokens after the initial connection.

---

## Troubleshooting

Token Invalid

Verify the token hasn't expired. GitLab tokens can have expiration dates. Generate a new token if needed.

Repository Not Found

Ensure the token has access to the target group or project. Group tokens only see repositories within that group.

Self-Hosted Connection Refused

Check that your GitLab URL is correct and the instance is reachable. Verify SSL certificates are valid.
