# GitLab

GitLab is a DevOps platform that provides version control, CI/CD, and project management. The Sling GitLab connector extracts data from the GitLab REST API v4, supporting projects, groups, issues, merge requests, commits, pipelines, and more. It works with both GitLab.com (SaaS) and self-hosted instances.

{% hint style="success" %}
**CLI Pro Required**: APIs require a [CLI Pro token](https://docs.slingdata.io/sling-cli/cli-pro) or [Platform Plan](https://docs.slingdata.io/sling-platform/platform).
{% endhint %}

## Setup

The following credentials and inputs are accepted:

**Secrets:**

* `personal_access_token` **(required)** -> Your GitLab Personal Access Token

**Inputs (optional):**

* `base_url` (optional) -> GitLab API base URL (default: `https://gitlab.com/api/v4`). Set this for self-hosted instances.
* `anchor_date` (optional) -> The starting date for historical data extraction (default: 1 year ago). Format: `YYYY-MM-DD`

### Getting Your Personal Access Token

1. Log in to your GitLab instance
2. Navigate to **User Settings** > **Access Tokens** (or go to `/-/user_settings/personal_access_tokens`)
3. Enter a token name (e.g., "Sling Integration")
4. Set an expiration date
5. Select the **read\_api** scope (minimum required)
6. Click **Create personal access token**
7. Copy the generated token immediately — it won't be shown again

### Using `sling conns`

Here are examples of setting a connection named `GITLAB`. We must provide the `type=api` property:

{% code overflow="wrap" %}

```bash
sling conns set GITLAB type=api spec=gitlab secrets='{ personal_access_token: glpat-xxxxxxxxxxxxxxxxxxxx }'
```

{% endcode %}

### Environment Variable

See [here](https://docs.slingdata.io/sling-cli/environment#dot-env-file-.env.sling) to learn more about the `.env.sling` file.

{% code overflow="wrap" %}

```bash
export GITLAB='{ type: api, spec: gitlab, secrets: { personal_access_token: "glpat-xxxxxxxxxxxxxxxxxxxx" } }'
```

{% endcode %}

### Sling Env File YAML

See [here](https://docs.slingdata.io/sling-cli/environment#sling-env-file-env.yaml) to learn more about the sling `env.yaml` file.

```yaml
connections:
  GITLAB:
    type: api
    spec: gitlab
    secrets:
      personal_access_token: "glpat-xxxxxxxxxxxxxxxxxxxx"
```

**For self-hosted GitLab instances:**

```yaml
connections:
  GITLAB:
    type: api
    spec: gitlab
    secrets:
      personal_access_token: "glpat-xxxxxxxxxxxxxxxxxxxx"
    inputs:
      base_url: "https://gitlab.mycompany.com/api/v4"
```

**With anchor date for historical data:**

```yaml
connections:
  GITLAB:
    type: api
    spec: gitlab
    secrets:
      personal_access_token: "glpat-xxxxxxxxxxxxxxxxxxxx"
    inputs:
      anchor_date: "2020-01-01"
```

## Replication

Here's an example replication configuration to sync GitLab data to a PostgreSQL database:

```yaml
source: GITLAB
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: gitlab.{stream_name}

streams:
  # sync all endpoints
  '*':

  # exclude specific endpoints if not needed
  project_jobs:
    disabled: true
```

**Incremental sync example:**

```yaml
source: GITLAB
target: MY_POSTGRES

defaults:
  mode: incremental
  object: gitlab.{stream_name}

streams:
  projects:
  project_issues:
  project_merge_requests:
  project_commits:
  project_pipelines:
  deployments:
```

## Endpoints

| Endpoint                 | Description                                   | Incremental |
| ------------------------ | --------------------------------------------- | ----------- |
| `projects`               | Projects accessible by the authenticated user | Yes         |
| `groups`                 | Groups accessible by the authenticated user   | No          |
| `project_issues`         | Issues for each project                       | Yes         |
| `project_merge_requests` | Merge requests for each project               | Yes         |
| `project_commits`        | Repository commits for each project           | Yes         |
| `project_pipelines`      | CI/CD pipelines for each project              | Yes         |
| `deployments`            | Deployments for each project                  | Yes         |
| `project_jobs`           | CI/CD jobs for each project                   | No          |
| `branches`               | Repository branches for each project          | No          |
| `tags`                   | Repository tags for each project              | No          |
| `project_milestones`     | Milestones for each project                   | No          |
| `project_members`        | Members of each project                       | No          |
| `releases`               | Releases for each project                     | No          |
| `project_labels`         | Labels for each project                       | No          |
| `environments`           | Environments for each project                 | No          |
| `group_milestones`       | Milestones for each group                     | No          |
| `group_labels`           | Labels for each group                         | No          |
| `group_members`          | Members of each group                         | No          |

To discover available endpoints:

```bash
sling conns discover GITLAB
```

## Notes

* The connector only extracts projects where the authenticated user has membership.
* Rate limiting is set to 5 requests/second with concurrency of 3 to respect GitLab's API limits.
* The connector automatically retries on 429 (rate limit) and 5xx (server error) responses.
* For self-hosted instances, ensure the API v4 is enabled and accessible.

If you are facing issues connecting, please reach out to us at <support@slingdata.io>, on [discord](https://discord.gg/q5xtaSNDvp) or open a Github Issue [here](https://github.com/slingdata-io/sling-cli/issues).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.slingdata.io/connections/api-connections/gitlab.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
