Files
deepseek-harness/packages/experimental/forge-gitlab
LegGasai 7c4c53fb65 fix(forge-gitlab): select a reviewed merge request by the user's own review state
The `involved` list and its count selected reviewed merge requests with `not: { reviewStates: [UNREVIEWED,
REVIEW_STARTED] }`. GitLab 19.5.1 applies that negation to every reviewer, so a merge request the user approved was left
out while another reviewer had yet to review it. The connection now lists the states a given review can have, which
GitLab reads from the user's own reviewer entry.
2026-11-23 15:13:36 +08:00
..

description, kind
description kind
Serve the experimental forge registry for GitLab hosts through the GitLab CLI on the host. package-reference

@deepseek-ai/dsh-forge-gitlab

English | 中文

Summary

Read and write GitLab.com and self-managed GitLab merge requests for ctx.forge with the GitLab CLI that is already signed in on the host. Each poll reads state, changed lines, head pipeline jobs, reviewers and approvals, mergeability, unresolved discussions, and closing issues for every due merge request; the changes view reads the diff pinned to the head, the commits, and the review threads with their positions at the head and where they were last seen. It writes comments as discussions and draft notes, resolves discussions, submits and approves reviews, marks drafts ready, merges, retries pipelines, requests reviews, and rebases.

Table of Contents


Use this package

Mount the provider after the forge registry and list every self-managed host explicitly. The Forge bundle mounts it with gitlab.com. hosts lists at least one host name, each with an optional port, and is editable while the provider runs: the forge panel draws the list on this row's page on the Plugins page, and a saved list replaces the registered provider without mounting the plugin again. A list that names a host the GitHub provider serves is not registered: the Loader logs the refusal and the previous list keeps being served until a restart, where the provider that mounts second fails to load.

- name: '@deepseek-ai/dsh-experimental-forge'
- name: '@deepseek-ai/dsh-forge-gitlab'
  config:
    hosts: [gitlab.com, gitlab.example.com]

The provider runs glab as a host process, even when Sessions execute commands in another execution world. Sign in once per host with glab auth login --hostname <host>. The child receives the host environment without DSH_* variables, without variables whose names contain KEY, PASSWORD, SECRET, or TOKEN, and without the variables that make glab choose another host, repository, or remote, such as GITLAB_HOST, GITLAB_REPO, and GLAB_REMOTE_ALIAS; it runs in the temporary directory, because inside a checkout glab resolves project paths against that checkout's remotes. Prompts, update checks, telemetry, pagers, and colors are disabled, and every request names its host with --hostname. Numeric limits must be positive safe integers; only timeoutMs is bounded by the runtime timer limit. glabCommand, hosts, timeoutMs, maxOutputBytes, maxReviewThreads, maxCommits, statusBatchSize, maxConcurrentRequests, and maxCachedVersionBytes are listed in the configuration catalog.

The provider lists its configured hosts in lowercase as hosts, names itself GitLab, and calls change requests merge requests. It serves a remote URL in https, http, ssh, or git form, or in scp form such as git@gitlab.com:group/sub/app.git, when its host is configured; nested groups form the repository's owner, such as group/sub. HTTP(S) remotes retain custom ports in the host identity; SSH and Git transport ports are excluded. It serves merge request URLs of the form https://<host>/<namespace>/<project>/-/merge_requests/<number> with any trailing path, query, or fragment, and builds that form without the suffix as the canonical URL; fileUrl returns https://<host>/<namespace>/<project>/-/blob/<commit>/<path>. A readiness probe reads the REST user resource: success is ready, a refusal of the credentials is unauthenticated with glab auth login --hostname <host> as its sign-in command, and any other failure, including a glab that cannot start, is unavailable. A head lookup returns up to 20 open merge requests whose source branch is the branch and whose source project is the target project, newest first; a lookup of the project's default branch returns none.

While forge-session runs, the plugin registers the glab command rule with it. glab mr create and glab mr new bind the merge requests they print. glab mr view, glab mr update, and glab mr checkout bind the merge request that a URL selects, or a number with --repo, --repo=, or -R before or after it; a full http or https project URL supplies the URL directly, and any other repository form, such as group/app or a Git URL, resolves through glab mr view <number> --repo <repository> --output json --jq .web_url in the call's shell, which applies that shell's glab configuration and GITLAB_HOST. glab api binds the merge request its REST path names, such as projects/group%2Fapp/merge_requests/7/changes, with a leading / or api/v4/ or as a full API URL: directly when --hostname or the URL names the host, else through glab mr view <number> --repo <path>, or without --repo for the :fullpath and :id placeholders; a numeric project id names nothing.

A fetch groups references by host, splits each group into batches of statusBatchSize merge requests (default 1), and runs at most maxConcurrentRequests (default 4) GraphQL queries at once. GitLab refuses a query whose complexity passes 250; on GitLab 19.5.1 the query measures 103 for one merge request and 204 for two, and a refused batch is halved and read again. Mergeability comes from detailedMergeStatus, mergeStatus, and conflicts. The query selects the merge status before diffStatsSummary, after which GitLab 19.5 reports CONFLICT for a merge request it found mergeable. GitLab 19.5 reports the same for every mergeable merge request after the first one of a query, each of which selects diffStatsSummary, so the default reads one merge request per query and a larger statusBatchSize shows those merge requests as conflicting on that version. UNCHECKED, CHECKING, PREPARING, and APPROVALS_SYNCING are unknown, and so is a merge status GitLab has not checked since a change (UNCHECKED or CANNOT_BE_MERGED_RECHECK), whatever its last outcome says; GitLab checks it again only when a REST read of the merge request asks it to, so the poll sends one and a later poll reads the outcome. Otherwise CONFLICT is conflicting even while conflicts is false. A merge request is ready to merge when it is open, not a draft, MERGEABLE, not conflicting, and the signed-in user may merge it. The project's fast-forward setting makes the merge method rebase instead of merge, and the merge request's squash settings add, force, or omit squash. autoMerge is on while the merge request is open and autoMergeEnabled is true; it then names mergeUser as the account that turned it on, and as its method squash when GitLab reports that the merge squashes, else the project's merge or rebase. It can be turned on while the merge request is open and not a draft, the automatic merge is off, the signed-in user may merge, and availableAutoMergeStrategies lists merge_when_checks_pass, which GitLab 19.5.1 lists while a merge check blocks the merge request, a conflict included, and not once it can merge. A user who may merge can turn it off, and so can the author, whom the query's currentUser identifies. The review decision is changes-requested when a reviewer's state is REQUESTED_CHANGES, approved when GitLab reports the merge request approved, and review-required for NOT_APPROVED. Reviewers come first, then approvers who are not reviewers, never the author; a reviewer whose review is awaited is requested, and reviewer states map to approved, changes-requested, commented, and dismissed. Checks are the head pipeline's jobs without the ones a retry replaced: a failed job allowed to fail is neutral, a manual job is pending unless it is allowed to fail, which makes it skipped, and the pipeline's status decides the rollup. Every job names its pipeline's global id as its rerun, since GitLab retries a pipeline's failed and cancelled jobs together, and canRerunChecks follows the signed-in user's right to update the head pipeline. A poll reads the first 50 jobs; fetchChecks reads the rest 100 per page, refusing a page whose head moved. branchUpdates offers rebase, GitLab's only branch update, while the branches have diverged without conflicts, no rebase runs, and the user may push to the head branch; canRequestReviews follows the user's right to update the merge request. The unresolved count is GitLab's resolvable discussions less the resolved ones. Closing issues come from REST closes_issues, up to 25, and are read again only when the merge request's update time changes; a failed read keeps the last list marked truncated.

diff reads the newest MR diff version, which GitLab records for every push, and returns stale unless its head is the requested commit; it then joins the version's per-file diffs into one patch with Git's headers, ordered by path as GitLab's raw patch is, and compares a file GitLab collapsed or found too large from its text at both commits. A version whose real_size ends in +, which GitLab sets past its file limit, is too-large. For every open merge request measured, the patch matched GitLab's raw patch except for Git's index lines. commits lists the merge request's commits oldest first, at most maxCommits (default 250), reading the pages that hold the oldest ones when GitLab's X-Total counts more. compare reads repository/compare between two commits and reports a comparison GitLab stopped for time as too-large, and mergeBase reads repository/merge_base. fileText reads repository/files/<path>/raw at a full commit.

readReview reads REST discussions 100 per page until maxReviewThreads threads, beside GraphQL pages of the signed-in user's rights on the merge request and on each discussion and note, the user's draft notes, and their approval, then the diff versions; the newest version must be at the requested head, else the read is stale. A thread is a discussion whose first note is a diff note on a text or file position; discussions on the overview, on images, and without notes are left out, and system notes are dropped from threads. GitLab keeps one position per thread, at the last diff version whose lines the thread's lines were unchanged in: a position at the head gives current, and every line thread keeps its position as original. GitLab does not move a multi-line thread's line_range when it carries the thread to a new version, so a range's first line is its last line less the range's length. An outdated thread's diffHunk is cut from its position's diff: the version's file when GitLab keeps it, or a comparison of the file's text at the position's merge base and head, since GitLab drops the files of earlier versions once a merge request merges. Those patches never change and are kept until they pass maxCachedVersionBytes (default 16 MiB); a version larger than that serves its read without being kept. The read is truncated when it stops before the last discussion page, leaves the rights of a discussion or of a note past a discussion's first 100 unread, or drops the threads whose hunks and drafts bring the result past maxOutputBytes. A thread may be replied to when the user may comment, and resolved when GitLab lets the user resolve its discussion; a note may be edited and deleted when GitLab grants the user adminNote on it. The user's draft notes are their pending review, whose id is draft-notes: a draft reply joins its thread as a pending comment, and a draft on a file position is a thread of its own, which cannot be replied to or resolved before it is published. GitLab reports no creation time for drafts, so they carry the read's time. reviewEvents offers comment to a user who may comment, approve when GitLab lets them approve or they already approved, since GitLab Community Edition lets authors approve their own merge requests, and request-changes only to reviewers, since GitLab records that decision only for them.

markReady calls the GraphQL mergeRequestSetDraft mutation, and merge puts merge with sha set to the confirmed head and squash for the squash method, so GitLab refuses with HTTP 409, reported as stale, once the head moved; the merge request's own setting decides whether GitLab deletes the head branch. setAutoMerge turns the automatic merge on through the GraphQL mergeRequestAccept mutation with the strategy MERGE_WHEN_CHECKS_PASS, sha set to the confirmed head, and squash for the squash method; the strategy keeps GitLab from merging at once and from adding the merge request to a merge train. GitLab's error for a sha that is not the head is reported as stale, and every other error it lists, such as an automatic merge that is already on, as failed. It turns the automatic merge off by posting REST cancel_auto_merge, which GitLab answers with HTTP 403 for a user who may not cancel it and with HTTP 409 once the automatic merge is off, both failed.

Review writes read the newest diff version first and refuse with stale unless its head is the confirmed commit. A comment's position names that version's merge base, target tip, and head: an added line names its new line, a deleted line its old line, and any other line both, inside or outside the hunks, and a range adds a line_range with GitLab's line codes; a line the version's diff does not hold is refused before anything is written, and a comment on an unchanged line reads back on the new side. A file GitLab collapsed or found too large is placed on the diff compared from its texts, and a file's new path names it over another file's old path. submitReview starts a discussion for one comment. A review writes each comment as a draft note, approves at the head when its decision is approve, and publishes the drafts with the summary and the review state of comment (reviewed) or request-changes (requested_changes); a refused draft or approval deletes the drafts it wrote. After a refused publication the drafts are read again, since GitLab can publish them before refusing the summary: they are deleted only when all remain, else the result is unknown. A deletion that fails makes the result unknown with the number of drafts that may remain. A review is refused while the user holds drafts, which publishing would include. Pending replies and comments are draft notes, which submit-pending publishes in the same way and discard-pending deletes one by one, reporting how many it deleted before a refusal. An approval is skipped when the user already approved, since GitLab answers a second one with HTTP 401. Replies, resolutions, edits, and deletions go through the merge request's own paths, so GitLab refuses ids of another merge request.

rerunChecks retries the head pipeline once it has failed jobs and none pending. requestReviews adds new reviewers with mergeRequestSetReviewers and asks current ones again with mergeRequestReviewerRereview; a merge request that takes one reviewer, as on GitLab's free tier, refuses a second, and GitLab has no team reviewers. reviewerCandidates lists at most 20 of GitLab's matches among the users who can see the project, never the author, none suggested. updateBranch only rebases: GitLab names no head in a rebase request, so the provider reads the head first and refuses a moved one with stale, and GitLab rebases in the background once it accepted the request. Writes are never retried: a 4xx answer is a refusal, failed, except HTTP 401, unauthenticated, and HTTP 409 to a merge or an approval, stale; a 5xx answer, an answer without a status, and a write past timeoutMs are unknown.

viewer offers the review-requested, authored, and involved lists on every configured host, up to 100 merge requests per read, GitLab's page maximum. listForViewer reads one list of open merge requests, most recently updated first, through one GraphQL request to currentUser. review-requested holds the merge requests that still await the user's review, where the user is a reviewer whose state is UNREVIEWED or REVIEW_STARTED, and authored the ones the user wrote. GitLab has no single query for involved, so its request reads two connections, merges them by update time, and reports the sum of their sizes as the total: the merge requests the user reviewed and did not write, and the ones assigned to the user who neither wrote nor reviews them. A reviewed merge request is one where the user's own review state is REVIEWED, REQUESTED_CHANGES, APPROVED, or UNAPPROVED, whatever the states of its other reviewers. These two share no merge request with each other or with the other two lists. A repository limits a read to one project by its full path, and a path with a segment GitLab does not permit returns not-found without a request. Each item carries the head pipeline's status as its check outcome and changes-requested, approved, or none as its review decision by the rules of a status read. When the user is among the first 20 reviewers, the user's review state gives the item its review or its review request; every item of review-requested names a request. A merge request without commits has no head and is left out of the items, though the total counts it. countForViewer reads the sizes of the same four connections in every project through one request. The involved list and the counts name the user by username in their requests: the provider keeps the username that the latest viewer read on a host answered as, reads it through one more request when it keeps none, and repeats a read once when its answer names another user, as after glab signed in as someone else. An answer without a user is unauthenticated. readDescription reads description, createdAt, up to 100 labels, and the project's id in one GraphQL query. GitLab writes an upload in Markdown without host or project, as /uploads/<32 hex digits>/<file>, and serves it at https://<host>/-/project/<project id>/uploads/…; where a Markdown link or image or an HTML src names an upload, the description returns that address, as GitLab's own rendering does. A label's #rrggbb color is returned without #, and images maps nothing.

readActivity sends two requests together. One GraphQL query, of complexity 37 against GitLab's limit of 250, reads the latest 100 notes oldest first, the project's id, and the user's createNote right, which viewerCanComment reports. One REST read of resource_state_events lists the first 100 state changes, because GitLab keeps merged, closed, and reopened there and not as notes; any other state it records is an other entry with the state's name. A note a person wrote outside the diff is a comment, with its uploads at the addresses a description gives them. GitLab has no review that holds comments, so diff comments one author wrote in a row are one review with the verdict commented, an empty body, their number, and the time and page of the first; a system note in a diff thread is left out. Every other system note maps by systemNoteMetadata.action, which names what the note records whatever language its sentence is in. approved, requested_changes, and reviewed are a review with the verdict approved, changes-requested, or commented. reviewer is one review-requested for each account it asks and an other entry for the requests it withdraws. title is ready-for-review or converted-to-draft for a draft mark, else renamed with both titles as plain text, read from the HTML in which GitLab 19 marks the changed words or from the {- -} and {+ +} marks of earlier versions. commit is one commit for each commit its list names, with the abbreviated object name GitLab lists, and an other entry for each item that only counts commits, which GitLab writes for commits from another branch and for the earlier commits of a long push. merge is auto-merge-enabled, or auto-merge-disabled when the automatic merge was cancelled or aborted. Every other action, such as description, cross_reference, discussion, and assignee, is an other entry with the note's sentence as plain text, without its Markdown and HTML. Entries are ordered by time; GitLab reports a note's time in whole seconds, so a note precedes a state change of its second. A page that leaves out earlier notes drops the state changes before its first note, and a result of more than 100 entries keeps the latest 100; both mark it truncated. addComment creates one note through REST notes and is never retried: the comment is saved once the answer carries the note's id, an accepted request whose answer names no note is unknown, and failures follow the rule of the other writes.


Understand the implementation

Implementation internals — click to expand

Each status query reads several merge requests under aliases with their project paths and numbers as variables, so a missing project or merge request fails only its own alias.

Source Responsibility
src/index.ts Configuration validation, and provider and command rule registration
src/commands.ts The glab command rule that forge-session binds merge requests by
src/provider.ts URL mapping, batching, closing issue and diff caches, the signed-in username kept per host, and actions
src/api.ts REST, GraphQL, and write requests through glab api, and failure mapping
src/status.ts Status query construction and snapshot mapping
src/diff.ts Version-pinned patches, comparisons, merge bases, and file texts
src/commits.ts Commit listing oldest first
src/review.ts Discussion, draft note, and permission reads, and mapping onto head and original positions
src/writes.ts Review writes and submissions through discussions, draft notes, and approvals
src/position.ts Diff note positions and line codes from a version's file diff
src/overview.ts Pipeline retries, review requests, reviewer candidates, rebases, and automatic merges
src/viewer.ts Viewer list, count, and username queries, and summary mapping
src/description.ts Description and label reads, and the addresses of uploads
src/activity.ts Note and state change reads, and their mapping to activity entries
src/pool.ts Bounded concurrency
src/glab.ts Host glab execution with environment scrubbing and limits
src/urls.ts Remote, merge request, and issue URL parsing, and project path validation

Further Exploration


Model Experience

None, as the provider reads and writes merge requests for host-side watchers and the panel without contributing model context.

KV Cache effect

None. Provider output reaches only host-side watchers.

Known Limitations and Deferred Work

  • GitLab CLI on the host — glab must be installed and signed in for each configured host; tokens in environment variables are not forwarded. Hosts missing from hosts are never read; a status fetch returns unavailable for their references, and a head lookup rejects before starting glab. A host whose SSH remotes use another host name, or a GitLab installed under a path prefix, is not recognized.
  • No viewed marks — the provider keeps no viewed marks, so the changes view keeps them in the browser, as GitLab's own pages do.
  • Rebase without a head check — a push between the head read and the rebase request is rebased too, and a rebase GitLab fails in the background is not reported.
  • Automatic merges — only GitLab's strategy that waits for the merge checks is turned on, so a merge request whose only available strategies are merge trains offers no automatic merge; one that GitLab's own pages put on a merge train reads as on, and turning it off takes it off the train, as GitLab documents for cancel_auto_merge. A moved head is recognised by GitLab's English error sentence, and a reworded one is failed. cancel_auto_merge exists since GitLab 19.5, so an earlier GitLab answers HTTP 404, failed, and the status query reads autoMergeEnabled, which GitLab 17.11 introduced. Both requests follow GitLab's API documentation and its 19.5.1 source; neither was sent to a GitLab instance.
  • Overview discussions — discussions that are not on a file count toward unresolvedThreads but are not returned as threads.
  • Bots and draft times — the authors of review thread comments are never marked as bots, and draft notes carry the read's time.
  • Viewer lists — GitLab has no team review requests, so no list item names a team. involved holds the merge requests the user reviewed or is assigned to, not the ones that only mention the user or that the user only commented on. List items carry no reviewed commit, so the review page cannot tell an approval of the head from an older one, and they never report review-required, because the lists read no merge status. The list and count queries need a GitLab version whose reviewRequestedMergeRequests accepts reviewStates and not; they work on GitLab 19.5.1, and the oldest version that accepts them is not known.
  • Descriptions — an upload image of a private project needs a GitLab session and does not load. GitLab's own reference forms, such as !12, #34, and @name, are plain text.
  • Activity — one read returns the latest 100 entries with no earlier page, and reads only the first 100 state changes. A submitted review is not one entry: its diff comments, its summary comment, and its decision are separate entries, replies in a diff thread count as diff comments, and a withdrawn approval is an other entry. Draft marks, automatic merges, and title changes of the earlier form are recognised by their English sentence, and a note that words one differently is an other entry with its sentence; a reviewer note that withdraws a request in other words than GitLab's English ones reads as a request for the accounts it names. On GitLab 19.5.1 every sampled sentence of a user whose language is Chinese was English, except that of a review request asked again, which maps by its @ mention; an instance whose default language is not English was not measured. other entries are in the language GitLab wrote them in. The limits of a description's uploads and reference forms apply to a comment. The actor of a state change is never marked as a bot. A note and a state change of the same second are listed note first, whichever came first. GitLab runs the quick actions in a comment that addComment sends, such as /close, and removes them from the note. The read works on GitLab 19.5.1; the oldest version that answers it is not known.
  • CE fields only — the status query reads fields Community Edition has; required approvals, code owners, suggested reviewers, and merged-results pipelines of paid tiers are not read.
  • Rate limits — every poll costs one GraphQL query per merge request, or per batch of a larger statusBatchSize, plus one REST request per merge request whose update time changed; a review read costs one REST and one GraphQL request per 100 discussions, one request each for the versions, the draft notes, and the approval, and up to two per outdated file not yet cached; a write reads the newest version first, and a comment reads its version's files once; a viewer list costs one GraphQL request and the counts cost one, plus one for the username when the involved list or the counts are read before any viewer read on the host named it; an activity read costs one GraphQL and one REST request, addComment one REST request, and setAutoMerge one request.

Dev Note

Working context for maintainers — click to expand

None.