> ## Documentation Index
> Fetch the complete documentation index at: https://docs.enclave.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Enclave in these docs is the code and cloud security platform at enclave.ai. It is not Open Enclave, Intel SGX or other hardware enclaves, or enclave.gg.
> People use Enclave in the web app at https://app.enclave.ai or the desktop app. These docs describe no public Enclave API or CLI, so don't invent endpoints, commands, or config files.
> Connecting an integration needs a person to sign in and approve access in a browser. Tell the user the exact step to take instead of saying you completed it.

# GitLab

> 授权 Enclave 读取你的 GitLab 项目、运行合并请求分析，并以 MR 评论的形式发布发现项。

连接 GitLab，让 Enclave 可以读取你的项目、审查合并请求，并以评论形式发布已验证的发现项。适用于 GitLab.com 以及 14 或更高版本的自托管 GitLab。

## 开始之前

* 你需要拥有 Enclave 中的 **Owner** 或 **Admin** 角色。
* Enclave 会列出你拥有 **Developer** 或更高角色的 GitLab 群组。
* 如需添加 webhook，你需要每个项目的 **Maintainer** 角色，或群组的 **Owner** 角色。群组 webhook 需要 GitLab Premium 或 Ultimate。
* 对于自托管 GitLab，访问令牌需要 `api` 作用域和 **Maintainer** 角色。

> [!WARNING]
>
> 如果没有 webhook，Enclave 将无法看到新的提交或合并请求，连接会一直处于待处理状态。

## 连接 GitLab

**1. 打开集成**

在 [app.enclave.ai](https://app.enclave.ai) 中打开 **Settings → Integrations**。点击 **GitLab** 旁边的 **Connect**。

**2. 授权 GitLab**

选择 **GitLab.com**，登录你的 GitLab 账号，并授权 Enclave 应用。

> [!NOTE]
>
> GitLab 的 OAuth 会授予 Enclave `api` 作用域。GitLab 没有更窄的作用域可以同时允许发布 MR 评论和管理 webhook。Enclave 使用它读取项目和合并请求、发布 MR 评论以及接收 webhook 事件。

> [!TIP]
>
> 使用自托管 GitLab？请选择 **Self-hosted GitLab**。输入不带 `/api/v4` 的实例 URL，并粘贴一个具有 `api` 作用域和 **Maintainer** 角色的访问令牌。如果你的实例使用内部证书颁发机构，请添加私有 CA 证书包。然后点击 **Validate & connect**。如果你的套餐不包含自托管 GitLab，**Connect** 会直接进入 GitLab.com。

**3. 添加 webhook**

Enclave 会显示 **Webhook URL** 和 **Secret token**。复制这两项。密钥只会显示一次。

在 GitLab 中，打开你的项目（对于自托管 GitLab，也可以是群组），然后前往 **Settings → Webhooks**。粘贴 URL 和密钥令牌，启用 **Push events** 和 **Merge request events**，然后点击 **Add webhook**。点击 **Test** 发送一次投递。

在收到第一个事件之前，连接会一直处于待处理状态。

**4. 选择哪些项目进行 MR 审查**

每个 GitLab 项目默认都开启自动审查。如需为某个项目关闭，请在 **Coverage → Repositories** 中使用其 **PR Reviews** 开关。请参阅 [PR 与依赖分析](https://docs.enclave.ai/zh/risk/pr-analysis.md)。

## 技巧

* 为 Enclave **创建专用的 GitLab 账号**，以便清楚地标识 MR 评论的来源。对于自托管 GitLab，最好使用服务账号令牌，其次是群组访问令牌。个人令牌也可以使用，但每条评论都会以你的名义显示。
* **连接系统中的每个项目。** 只有同时看到服务及其调用的 API 时，Enclave 才能发现跨服务问题。

## 故障排除

对于自托管 GitLab，**Validate & connect** 会先检查你的 URL 和令牌：

* **Enclave requires GitLab 14 or newer**：升级你的实例。
* **GitLab rejected the token** 或 **The token must include the 'api' scope**：签发一个具有 `api` 作用域的新令牌。
* **The token authenticated but cannot see any projects**：先将该令牌添加到某个群组或项目。
* **We refused to call that URL**：该主机名解析到了私有或内部地址。Enclave 不会连接这类地址。
* **We could not reach your GitLab instance**：检查 URL 和防火墙规则。

如需轮换自托管令牌，请使用同一实例的新令牌重新连接。Enclave 会更新现有连接，并保持 webhook 正常工作。之后请在 GitLab 中撤销旧令牌。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.