How to Submit Code Reviews to GitLab Merge Requests via glab in tuicr

You submit code reviews to GitLab merge requests via glab by using tuicr's GitLabGlabBackend, which maps your inline comments to glab mr comment or glab api commands after you trigger the :submit action in the TUI.

The tuicr repository implements a modular forge backend system that treats GitLab as a first-class citizen. When you need to submit code reviews to GitLab merge requests via glab, the application delegates all GitLab-specific operations to the GitLabGlabBackend struct defined in src/forge/gitlab/glab.rs, wrapping the official glab CLI tool to ensure compatibility with both GitLab.com and self-hosted instances.

Understanding the Forge Backend Architecture

tuicr abstracts code review platforms through the ForgeBackend trait defined in src/forge/traits.rs. This contract requires implementations to handle three core responsibilities: listing merge requests, fetching diffs, and submitting reviews.

For GitLab integration, the GitLabGlabBackend struct in src/forge/gitlab/glab.rs fulfills this contract by shelling out to the glab binary rather than using a library API. This design ensures that authentication, rate limiting, and API versioning are managed by the official CLI tool already installed on your system.

The backend implements four critical methods:

  • list_pull_requests (lines 50-66 of glab.rs): Executes glab mr list --repo <repo> … --output json and deserializes the JSON into PullRequestSummary objects.
  • get_pull_request (lines 84-95 of glab.rs): Runs glab mr view <id> --repo <repo> --output json to construct PullRequestDetails.
  • get_pull_request_diff (after line 400 of glab.rs): Retrieves the unified diff via glab mr diff <id> --repo <repo>.
  • create_review: Maps internal comment structures to GitLab's API requirements, ultimately invoking either glab mr comment for single notes or glab api for bulk submissions (implemented in src/forge/submit.rs).

The Code Review Submission Pipeline

Submitting a review follows a four-stage pipeline that transforms your TUI interactions into authenticated GitLab API calls.

Remote Detection and Backend Initialization

When you launch tuicr from a repository directory, the detect_vcs function (located in src/forge/mod.rs) identifies the version control system and extracts the remote URL. The parse_any_remote_url function then recognizes GitLab URLs and instantiates a GitLabGlabBackend, configuring it with the appropriate repository identifier.

For self-hosted GitLab instances, the backend constructs full URLs using the repo_arg helper (lines 21-26 of glab.rs), ensuring the --repo flag receives the complete path (https://<host>/<owner>/<repo>).

Fetching Merge Request Details

Opening a specific merge request triggers the data fetching phase. The backend calls get_pull_request to retrieve metadata and get_pull_request_diff to obtain the patch text. These operations use glab's JSON output mode to ensure structured data parsing, with the response models defined in src/forge/gitlab/models.rs (structs like GlabMrSummary and GlabMrDetails).

Creating and Storing Comments

As you navigate the diff in the TUI (rendered by src/ui/app_layout.rs), pressing i initiates inline comment mode. Your text is stored in an in-memory ReviewSession struct (defined in src/model/review.rs) which maintains a collection of Comment objects with file paths and line numbers. Pressing Ctrl+S persists these to the session without yet transmitting them to GitLab.

Submitting via glab

When you execute the :submit command (handled in src/ui/app_layout.rs), control passes to src/forge/submit.rs. This generic submission logic iterates over your ReviewSession comments and invokes create_review on the backend.

The GitLabGlabBackend translates each comment into a position-aware GitLab anchor comprising file, line, and position parameters. For single comments, it executes:

glab mr comment 42 \
    --repo owner/repo \
    --position file_path:line \
    --body "Your comment text"

For reviews containing multiple inline comments, the backend batches them using glab api with a constructed JSON payload. The run_api helper method (lines 39-45 of glab.rs) handles the HTTP POST operation, ensuring atomic submission of complex reviews.

Practical Implementation Examples

The following workflows demonstrate how to submit code reviews to GitLab merge requests via glab using tuicr.

Prerequisites: Authentication

Ensure glab is installed and authenticated before starting tuicr:


# Install glab

curl -s https://glab.rocks/install.sh | bash

# Authenticate (stores token in ~/.config/glab)

glab auth login

Interactive TUI Workflow

Navigate to your repository and open a specific merge request:


# Open MR #42 in the tuicr TUI

tuicr pr open 42

Inside the interface:

  1. Navigate to the target line and press i to insert a comment.
  2. Type your feedback and press Ctrl+S to save the draft.
  3. Press : to enter command mode, type submit, and confirm.

tuicr automatically invokes the appropriate glab commands based on your backend configuration, displaying the submission status in the UI.

Non-Interactive CLI Workflow

For automation or scripting, use the review CLI commands:


# Add a line-specific comment without opening the TUI

tuicr review add --repo . --type line \
    --file src/lib.rs --line 128 \
    --message "Consider extracting this constant."

# Submit all pending comments

tuicr review submit --repo .

Both commands ultimately reach the same GitLabGlabBackend::create_review code path, ensuring consistent behavior between interactive and batch modes.

Key Implementation Details

Understanding the internal mechanics helps debug submission failures and optimize review workflows.

Position-Aware Anchoring: GitLab requires precise positioning data for diff comments. The backend in src/forge/submit.rs calculates the correct position parameter (indicating whether the comment applies to the old or new version of a line) before invoking glab.

Self-Hosted Support: The repo_arg method automatically detects non-standard GitLab hosts from your Git remote configuration. If your remote URL points to gitlab.company.com, tuicr constructs the full repository path for the --repo flag without requiring manual configuration.

Bulk Submission: When a review contains more than one comment, tuicr bypasses individual glab mr comment calls in favor of glab api with a JSON array. This reduces API round-trips and ensures that either all comments succeed or all fail together, maintaining review integrity.

Summary

  • tuicr submits code reviews to GitLab merge requests via glab through the GitLabGlabBackend implementation in src/forge/gitlab/glab.rs.
  • The ForgeBackend trait in src/forge/traits.rs abstracts platform differences, requiring implementations to handle listing, fetching, and creating reviews.
  • Comments are stored in a ReviewSession (defined in src/model/review.rs) during editing, then mapped to glab mr comment or glab api calls upon submission.
  • The run_api method (lines 39-45 of glab.rs) handles bulk submissions, while single comments use the higher-level glab mr comment CLI interface.
  • Self-hosted GitLab instances are supported automatically via the repo_arg helper (lines 21-26), which constructs full repository URLs from Git remotes.

Frequently Asked Questions

What authentication does tuicr require to submit GitLab reviews?

tuicr relies entirely on the glab CLI's authentication state. You must run glab auth login once to store an OAuth token in ~/.config/glab. tuicr inherits these credentials automatically; it does not manage tokens independently or support token injection via environment variables.

How does tuicr handle line positioning for multi-line comments?

The src/forge/submit.rs module calculates GitLab's required positioning parameters by comparing the comment's line number against the diff hunks stored in the ReviewSession. For each comment, it determines whether the anchor refers to the base or head version of the file, then passes this as the position argument to glab mr comment or includes it in the JSON payload for glab api.

Can I use tuicr with self-hosted GitLab Enterprise Edition?

Yes. The GitLabGlabBackend detects self-hosted instances during the detect_vcs phase by parsing the remote URL. The repo_arg method (lines 21-26 of glab.rs) constructs the full repository identifier (https://<host>/<owner>/<repo>) required by glab, ensuring compatibility with private GitLab deployments without additional configuration.

Why does tuicr use the glab CLI instead of a Rust GitLab library?

The implementation in src/forge/gitlab/glab.rs wraps the glab binary to delegate authentication, API versioning, and rate limiting to the officially maintained CLI tool. This reduces maintenance burden in tuicr and ensures that users benefit from glab's built-in token management and enterprise-specific features without requiring Rust-native GitLab API bindings.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →