Saltar al contenido

Docs / GitLab y JiHu

GitLab and JiHu quickstart

Connect a GitLab or 极狐GitLab (JiHu) project with an access token, switch it on, and get merge request review, auto-merge and AI dev tasks that open merge requests.

developerz.ai runs on GitLab as well as GitHub. A GitLab project is not installed through the GitHub App: it is connected as a source. You give us a project access token, the agents read and write the project with it, and we create a project webhook that delivers to a URL we mint.

Two instances are supported:

Forge in the dashboard Instance
GitLab gitlab.com
JiHu (极狐GitLab, GitLab's China edition) jihulab.com

Any other host, including a self-managed GitLab, is refused before the token is sent anywhere.

Sign-in is GitHub-based today. There is no GitLab sign-in button yet, so you sign in at app.developerz.ai with GitHub, then connect your GitLab or JiHu projects from there. Only an account owner or admin can connect a source.


What works on GitLab today

Feature On GitLab and JiHu
AI review of every merge request Yes. Findings are posted as threads on the MR, and a thread we raised is resolved once the fix lands.
@developerz-ai review typed on an MR Yes, from the MR's author or a project member with the Developer, Maintainer or Owner role.
Auto-merge Yes, once CI and review pass, the project's policy allows it, and the target branch's protection lets the token's role merge.
AI dev tasks that open a merge request Yes, through POST /v1/tasks naming the forge and instance.
Repo pages on the dashboard Yes, each project is shown with its forge and instance.

The limits are listed below.


1. Create the access token in GitLab

In the project, open Settings > Access tokens and create a project access token with the api scope and the Maintainer role. A token without api is refused at connect, with the scopes it does have named, and so is one whose user holds less than the Developer role on the project (a token made for another project can still read a public one, but cannot write to it). Maintainer is what creating the project webhook takes, and this token is also the one the agents post threads and merge with.

You do not add a webhook yourself: the connect in the next step creates it.

2. Connect the project

From the dashboard

Open Sources in the dashboard and choose Connect a project:

Field What to enter
Forge GitLab (gitlab.com) or JiHu (jihulab.com)
Label Any name you will recognise
Project path The full path, for example group/subgroup/project
Access token The api project access token from step 1
Webhook secret Leave it empty

On connect we read the project once with your token. A token GitLab rejects, or a path it cannot see, is refused and nothing is stored. Then we mint a signing token and create the project webhook at the source's URL, signed with that token and subscribed to merge request events, comments, pipeline events and push events. The access token and the signing token are sealed and never shown back.

Over MCP

The same connect is the integration verb's source_connect action (the docs://recipes/connect_a_source recipe walks it). Send no vendor_secret, so the platform creates the webhook:

{
  "kind": "gitlab",
  "label": "my-project",
  "gesture": { "kind": "always" },
  "api_token": "glpat-…",
  "project_path": "group/project",
  "instance": "jihulab.com"
}

Leave instance out for gitlab.com. A gitlab source takes only the always gesture.

3. Check that the webhook was created

The connect answers with the source's webhook URL (it also stays on the Sources list) and with webhook_created:

  • true: GitLab confirmed the webhook. Setup is done; go to step 4.
  • false: no webhook was created. GitLab refused it (for example, the token has less than the Maintainer role), or the platform could not record the request and so did not send it. webhook_reason names which, webhook_error says it in one sentence, and webhook_next_step gives the manual steps below.
  • null: the outcome is unknown, since GitLab gave no definite answer and the request may still land. Check the project's Settings > Webhooks for the source URL before adding one.

The dashboard shows the same outcome after you connect.

Set the webhook up by hand

When webhook_created is not true and no webhook is at the source URL, follow webhook_next_step. If GitLab refused the webhook because the token's role is below Maintainer, a user with that same role cannot add it by hand either: have a project Maintainer or Owner follow these steps, or reconnect the project with a Maintainer token.

  1. Open Settings > Webhooks and add a webhook at the source URL with every trigger unchecked.
  2. Generate its signing token (it starts with whsec_) and store it on the source with Rotate secret on the Sources list, or MCP integration source_rotate with the token as vendor_secret.
  3. Only then tick these triggers: Merge request events, Pipeline events, Comments and Push events.

Setup is complete only once that webhook exists with a signing token the source holds.

If a webhook is already at the source URL, we cannot tell it is ours: send a test delivery from GitLab. If it fails verification, generate a new signing token on that webhook and store it with Rotate secret. Either way, check that all four triggers are ticked (Merge request events, Pipeline events, Comments and Push events), even when the test delivery succeeds: a webhook with only merge request events passes that test.

Deliveries are verified against the signing token, and the project named in each one must be the project you connected.

Replacing an expired access token

GitLab expires every project access token. When yours expires or is revoked, create a new one on the same project with the api scope and store it with Replace token on the Sources list, MCP integration source_replace_token, or POST /v1/webhook-sources/:id/api-token with {"api_token": "glpat-…"}. The source keeps its URL, its webhook and its signing token. The new token must read the project the source is connected to, on the same instance, and its user must hold at least the Developer role there; a token for another project or another instance, or a Guest or Reporter one, is refused and nothing changes. Do not disconnect for this: a disconnect deletes the webhook and turns the project off.

Developer is only the floor the replace checks. Give the new token the role your branch protections need, usually the role the old one had: if only Maintainers may merge into the target branch, a Developer token is accepted here but every auto-merge then fails (see auto-merge). Prefer a project access token, which acts only on this one project, where your GitLab plan offers one; a personal access token is accepted too, but it acts on every project its user can reach.

Disconnecting

Disconnecting a source from the Sources list (or MCP integration source_disconnect) also deletes, best-effort, the webhooks on the project that point at its URL, including the one the connect created. If GitLab does not answer in time, remove any that remain from Settings > Webhooks yourself.

4. Your policy file

You do not have to write .dz/maintainer/maintainer.yml yourself. When you switch the project on (next step) and its default branch has no policy file, the platform opens a merge request from the branch dz/maintainer-policy that adds one, made with the source's token and written in the recipe you chose. On the default recipe it turns on auto-merge.

The platform never merges a change to its own policy file: review the merge request, edit it if you want, and merge it yourself. Closing it unmerged declines it, and it is not proposed again. The maintainer.yml reference lists every field.

The merge request needs the token to carry the api scope and its user to be at least a Developer on the project, and dz/* branches must not be protected against that role. If any of these is missing, nothing is written and the reason is in the project's audit log. A project that already has a policy file on its default branch is left as it is.

You also need a model key under Keys, as on GitHub (see BYOK).

5. Switch the project on

Connecting stores the project switched off, like every repository. Turn it on from the dashboard's Repos page, or by addressing the project by its full path plus its forge and instance: MCP project add, or REST PATCH /v1/repos/<path> with enabled, forge (gitlab) and instance.

Switching it on queues a read of the policy file from the default branch. After that, a push to the default branch re-reads it, so a later edit to the file is picked up on the push itself. A webhook without Push events ticked (one added by hand without it) does not deliver pushes: an edit is then picked up the next time a merge request moves. Until a policy has been read, auto-merge stays off.

6. Review, merge, and dispatch work

  • Review. Open or update a merge request and the reviewer runs on it. Type @developerz-ai review as the first line of a comment to ask for a review again.

  • Auto-merge. With pr.auto_merge on, a merge request whose CI and review pass is merged, provided the target branch's protection lets the token's role merge (a protected branch's Allowed to merge must include Maintainers). A red pipeline, a conflict or open findings are escalated to you instead of being fixed on the MR (see known limits).

  • AI dev tasks. With a box enrolled (see enroll a box), a task sent to POST /v1/tasks runs on it and opens a merge request. A GitLab project is reachable only by naming its forge and instance next to its path; a GitLab forge without an instance is refused rather than guessed:

    {
      "repo_full_name": "group/project",
      "forge": "gitlab",
      "instance": "jihulab.com"
    }
    

    Those three fields go beside the task's usual body (see the REST API).


Known limits

  • Sign-in is through GitHub. No GitLab or JiHu login yet.
  • No fixes on an existing MR. Fixing a red pipeline, resolving a conflict, re-running checks and replying to review threads run on GitHub only. On a GitLab MR those cases are escalated to a person.
  • Merge requests only. GitLab issues are not taken in as work, and a red default branch is not handled: the webhook is read for merge requests, their pipelines and their comments, a push to the default branch only re-reads the policy, and everything else is ignored.
  • Goals are GitHub-only. A goal naming a GitLab project is refused.

中文摘要

developerz.ai 支持 GitLab(gitlab.com)和极狐GitLab(jihulab.com),暂不支持其他实例,包括自建的 GitLab。

接入步骤:

  1. 目前只能用 GitHub 登录 app.developerz.ai,还没有 GitLab 登录按钮。接入项目需要账户的 owner 或 admin 权限。
  2. 在项目里创建一个带 api 权限、角色为 Maintainer 的项目访问令牌。平台创建 webhook 需要 Maintainer 角色,智能体评审和合并也用这个令牌。webhook 不用自己添加。
  3. 在控制台的 Sources 页面点 Connect a project,选择 GitLab 或 JiHu,填写项目路径和访问令牌,签名令牌一栏留空。也可以通过 MCP 的 integration source_connect 接入,不传 vendor_secret。平台会生成签名令牌,并在项目上创建 webhook(订阅 MR、评论、流水线和 push 事件)。返回 webhook_created: true 就说明已经配置好了。
  4. 如果返回 false,说明没有创建成功:GitLab 拒绝了请求(比如令牌角色低于 Maintainer),或者平台没能记录这次请求,原因见 webhook_reason。如果是因为令牌角色低于 Maintainer 被拒,同样角色的用户也无法手动添加 webhook:请项目的 Maintainer 或 Owner 按下面的步骤手动添加,或者换一个 Maintainer 角色的令牌重新接入。如果返回 null,说明结果未知,请先在项目的 webhook 设置里看看有没有指向该地址的 webhook,再决定是否手动添加。手动添加时按 webhook_next_step 操作:先添加一个指向该地址、所有触发器都不勾选的 webhook,生成签名令牌,用 Rotate secret(或 source_rotate 的 vendor_secret)交给平台,最后再勾选 Merge request events、Pipeline events、Comments 和 Push events。如果该地址上已有 webhook,平台无法确认它是不是自己创建的:先在 GitLab 里发一次测试请求,验证失败的话就在它上面重新生成签名令牌,用 Rotate secret 交给平台。即使测试请求成功,也要确认 Merge request events、Pipeline events、Comments 和 Push events 四个触发器都已勾选,因为只勾了 MR 事件的 webhook 也能通过测试。断开连接时,平台会尽力删除项目上指向该地址的 webhook。
  5. 在 Repos 页面启用该项目。如果默认分支上还没有 .dz/maintainer/maintainer.yml,平台会用来源的令牌从 dz/maintainer-policy 分支发起一个添加该文件的 MR,内容按你选择的方案生成,默认方案会开启自动合并。平台不会合并对自身策略文件的修改:请审阅、按需修改,然后自己合并;不合并直接关闭即表示拒绝,之后不会再次发起。令牌需要 api 权限、在项目上至少是 Developer 角色,且 dz/* 分支没有被保护到该角色无法推送,否则什么都不写,原因记录在审计日志里。已有策略文件的项目保持不变。启用时平台会读取这个文件;之后再修改它,推送到默认分支时会重新读取;手动添加且没勾 Push events 的 webhook 收不到 push 事件,这时要等下一次 MR 有变动才会重新读取。
  6. GitLab 的项目访问令牌都会过期。过期或被撤销后,在同一个项目上新建一个带 api 权限的令牌,在 Sources 页面点 Replace token(或用 MCP 的 integration source_replace_token)替换即可。来源的地址、webhook 和签名令牌都不变。新令牌必须能读到该来源所连的项目,而且在同一个实例上,令牌的用户在该项目上至少是 Developer 角色,否则会被拒绝,什么都不改。Developer 只是替换时检查的下限:新令牌的角色要满足分支保护规则的要求,一般和旧令牌相同。如果目标分支只允许 Maintainer 合并,Developer 令牌能替换成功,但之后的自动合并都会失败。GitLab 套餐支持的话,优先用项目访问令牌,它只作用于这一个项目;个人访问令牌也可以,但它能作用于该用户能访问的所有项目。不要为此断开连接:断开会删除 webhook 并关闭该项目。

能用的功能:MR 自动评审、在 MR 里输入 @developerz-ai review 重新评审、CI 和评审通过后自动合并(前提是策略文件里开启了 pr.auto_merge,并且目标分支的保护规则允许令牌的角色合并,即受保护分支的 Allowed to merge 包含 Maintainers)、通过 POST /v1/tasks(带上 forge 和 instance)派发任务,由 AI 开发者在你的机器上完成并发起 MR。

目前的限制:修复失败的流水线、解决冲突、回复评审线程只在 GitHub 上可用,GitLab 上会转给人处理;不接收 GitLab issue,也不处理默认分支变红;Goals 只支持 GitHub。