> ## Documentation Index
> Fetch the complete documentation index at: https://wiki.another-horizon.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# GitLab

> 连接 GitLab 存储库，实现自动部署和预览构建。

我们通过访问令牌和 webhook 在 GitLab 与 Mintlify 之间进行身份验证并同步变更。

* Mintlify 使用访问令牌从 GitLab 拉取信息。
* GitLab 使用 webhook 在发生变更时通知 Mintlify，从而为合并请求启用预览部署。

<div id="set-up-the-connection">
  ## 设置连接
</div>

<Note>
  **必须使用 HTTPS 克隆**：为便于 Mintlify 访问你的存储库，你的 GitLab 项目必须启用 HTTPS 克隆。你可以在 GitLab 中前往项目的 **Settings** > **General** > **Visibility and access controls** 部分进行查看与确认。
</Note>

<Steps>
  <Step title="查找项目 ID">
    在你的 GitLab 项目中，依次进入 **Settings** > **General**，找到 **Project ID**。

    <Frame>
      <img src="https://mintcdn.com/anotherhorizon/JcCuRMYxa7xgY0h0/images/gitlab/gitlab-project-id.png?fit=max&auto=format&n=JcCuRMYxa7xgY0h0&q=85&s=dcfc391bd023570429543e036134a226" alt="GitLab 控制台的 General Settings 页面，Project ID 已高亮显示。" width="950" height="775" data-path="images/gitlab/gitlab-project-id.png" />
    </Frame>
  </Step>

  <Step title="生成访问令牌">
    前往 **Settings** > **Access Tokens**，选择 **Add new token**。

    按以下设置配置令牌：

    * **Name**：Mintlify
    * **Role**：Maintainer（私有存储库必需）
    * **Scopes**：`api` 和 `read_api`

    点击 **Create project access token** 并复制该令牌。

    <Note>
      如果无法使用 Project Access Tokens，可改用 Personal Access Token。请注意，Personal Access Token 会过期，需要定期更新。
    </Note>

    <Frame>
      <img src="https://mintcdn.com/anotherhorizon/JcCuRMYxa7xgY0h0/images/gitlab/gitlab-project-access-token.png?fit=max&auto=format&n=JcCuRMYxa7xgY0h0&q=85&s=669e54a51f98187265880f74e07c76be" alt="GitLab 控制台的 Access tokens 页面，为 Mintlify 配置的设置已高亮显示。" width="1166" height="904" data-path="images/gitlab/gitlab-project-access-token.png" />
    </Frame>
  </Step>

  <Step title="设置连接">
    在 [Mintlify 控制台](https://dashboard.mintlify.com/settings/deployment/git-settings)：

    1. 输入你的项目 ID 和访问令牌。
    2. 完成其他必填配置。
    3. 点击 **保存更改**。

    <Frame>
      <img src="https://mintcdn.com/anotherhorizon/JcCuRMYxa7xgY0h0/images/gitlab/gitlab-config.png?fit=max&auto=format&n=JcCuRMYxa7xgY0h0&q=85&s=c668e4819319cda470a395bc08a83b62" alt="Mintlify 控制台的 Git Settings 页面，GitLab 配置设置已高亮显示。" width="2994" height="1704" data-path="images/gitlab/gitlab-config.png" />
    </Frame>
  </Step>
</Steps>

<div id="create-the-webhook">
  ## 创建 webhook
</div>

Webhooks 可在发生更改时向我们发送事件，从而自动触发部署。

<Steps>
  <Step title="前往 Settings > Webhooks 并点击“Add new Webhook”">
    <Frame>
      <img src="https://mintcdn.com/anotherhorizon/JcCuRMYxa7xgY0h0/images/gitlab/gitlab-webhook.png?fit=max&auto=format&n=JcCuRMYxa7xgY0h0&q=85&s=d98ab6149bea516fce81948b3d1348f2" alt="GitLab 控制台中 Webhooks 页面截图。" width="3014" height="1704" data-path="images/gitlab/gitlab-webhook.png" />
    </Frame>
  </Step>

  <Step title="设置 URL 和 webhook">
    在“URL”字段中，输入端点 `https://leaves.mintlify.com/gitlab-webhook`，并将 webhook 命名为“Mintlify”。
  </Step>

  <Step title="粘贴令牌">
    粘贴在完成连接设置后生成的 Webhook 令牌。

    <Frame>
      <img src="https://mintcdn.com/anotherhorizon/JcCuRMYxa7xgY0h0/images/gitlab/gitlab-show-webtoken.png?fit=max&auto=format&n=JcCuRMYxa7xgY0h0&q=85&s=1417caca27f124ee37c190d22fbd15f7" alt="Mintlify 控制台中的 GitLab 连接截图。已高亮显示 Show Webtoken 按钮。" width="555" height="527" data-path="images/gitlab/gitlab-show-webtoken.png" />
    </Frame>
  </Step>

  <Step title="选择事件">
    选择以下事件以触发 webhook：

    * **Push events**（所有 branch）
    * **Merge requests events**

    完成后应如下所示：

    <Frame>
      <img src="https://mintcdn.com/anotherhorizon/JcCuRMYxa7xgY0h0/images/gitlab/gitlab-project-webtoken.png?fit=max&auto=format&n=JcCuRMYxa7xgY0h0&q=85&s=5f77f9e10bf7e72ce406e1382c840f76" alt="GitLab 控制台中的 Webhook 页面。为 Mintlify 配置的设置已高亮显示。" width="1161" height="1740" data-path="images/gitlab/gitlab-project-webtoken.png" />
    </Frame>
  </Step>

  <Step title="测试 Webhook">
    创建 Webhook 后，点击“Test”下拉菜单并选择“Push events”，发送示例负载以确保配置正确。若配置无误，将显示“Hook executed successfully: HTTP 200”。

    这将帮助你验证一切正常工作，并确保你的文档能与 GitLab 存储库正确同步。

    <Frame>
      <img src="https://mintcdn.com/anotherhorizon/JcCuRMYxa7xgY0h0/images/gitlab/gitlab-project-webtoken-test.png?fit=max&auto=format&n=JcCuRMYxa7xgY0h0&q=85&s=7ec82f915ca31d43889fd50ca2976572" alt="GitLab Webhooks 页面截图。在“Test”菜单中已高亮显示“Push events”菜单项。" width="1161" height="724" data-path="images/gitlab/gitlab-project-webtoken-test.png" />
    </Frame>
  </Step>
</Steps>
