How to Integrate Tuicr with GitLab: Complete Setup and Configuration Guide
Tuicr integrates with GitLab automatically when the glab CLI is installed and authenticated, using the GitLabGlabBackend type in src/forge/gitlab/glab.rs to execute merge request operations via shell commands.
Tuicr is an open-source terminal UI code review tool that provides native GitLab support through a dedicated backend implementation. When you integrate Tuicr with GitLab, the application detects GitLab remotes in src/vcs/git/mod.rs and instantiates a GitLabGlabBackend that delegates all merge request operations—listing, diffing, and reviewing—to the official GitLab CLI (glab).
Prerequisites
Before using Tuicr with GitLab, ensure you have the following:
- Glab CLI: A working
glabexecutable available in your$PATH - Authentication: A valid
glabauthentication token with at leastread_apiandwrite_repositoryscopes obtained viaglab auth login - Repository Access: Clone access to the GitLab repository you intend to review
If glab is missing or authentication fails, the backend returns a clear TuicrError::Forge error (see map_glab_error in src/forge/gitlab/glab.rs).
How the GitLab Integration Works
Tuicr’s GitLab integration relies on a trait-based architecture that abstracts forge operations behind a common interface.
Core Components
The integration centers on several key types defined in src/forge/gitlab/glab.rs:
GitLabGlabBackend: Implements theForgeBackendtrait (defined insrc/forge/traits.rs) to provide GitLab-specific MR operations includinglist_pull_requests,get_pull_request_diff, andcreate_reviewGlabCommandRunner: Executesglabshell commands and captures stdout/stderr, converting non-zero exit codes into structuredTuicrErrorinstances- Parser Functions:
parse_gitlab_remote_urlandparse_pull_request_target_gitlabconvert remote URLs and MR identifiers (such asowner/repo#42, full URLs, or numeric IIDs) intoPullRequestTargetstructs - Data Models:
src/forge/gitlab/models.rsdefines Rust structs likeGlabMrSummary,GlabMrDetails, andGlabDiscussionthat deserialize JSON responses fromglab
Execution Flow
When you execute a Tuicr command targeting a GitLab merge request, the following occurs:
- Remote Detection:
src/vcs/git/mod.rsparses the repository’s remote URL to identify GitLab hosts (including self-managed instances recognized byglab config get host) - Backend Selection: Tuicr constructs a
GitLabGlabBackendinstance when a GitLab remote is detected - Command Execution: Backend methods build
glabCLI arguments (e.g.,glab mr view 42 --repo owner/repo --output json) and execute them viarun_glab - Diff Processing:
get_pull_request_diffcallsinject_git_diff_headersto add Git-stylediff --githeaders thatglab mr diffomits, ensuring compatibility with Tuicr’s diff parser - Review Submission:
create_reviewposts general MR notes and converts inline comments into GitLab "position" objects, sending them viaglab apior GraphQL mutations for "request changes" actions
Step-by-Step Configuration
Install the GitLab CLI
Install glab using your package manager:
# macOS (Homebrew)
brew install glab
# Linux (check glab documentation for distribution-specific methods)
Authenticate with GitLab
Generate a personal access token with read_api and write_repository scopes, then run:
glab auth login --hostname gitlab.com
The first time you run a Tuicr command without proper authentication, you’ll see: "GitLab integration requires glab. Install GitLab CLI and run glab auth login".
Verify the Integration
Navigate to a GitLab repository clone and test the connection:
tuicr pr list
This triggers GitLabGlabBackend::list_pull_requests, which executes glab mr list --repo owner/repo --output json --per-page 2.
Working with Merge Requests
Opening Specific MRs
You can open merge requests using numeric IDs, full URLs, or the shorthand syntax:
# By MR number
tuicr pr 123
# By full URL
tuicr pr https://gitlab.com/owner/myproj/-/merge_requests/123
# By shorthand notation
tuicr pr owner/myproj#123
Tuicr resolves these via parse_pull_request_target_gitlab and calls GitLabGlabBackend::get_pull_request to fetch MR details.
Listing and Filtering MRs
View open merge requests with optional filters:
# Show first page of all open MRs
tuicr pr list
# Show only MRs requesting your review
tuicr pr list --review-requested
The backend constructs the appropriate glab mr list command, adding --reviewer=@me when filtering for review requests.
Submitting Reviews and Inline Comments
To add inline comments:
- Navigate to a line in the diff view
- Press
Ctrl-Cto open the comment dialog - Type your comment and press
Ctrl-Sto save
When ready to submit, use the command palette (:):
:submit comment # Post comments without approval
:submit approve # Approve the MR
:submit request-changes # Request changes via GraphQL mutation
:submit draft # Save as draft notes using the draft_notes endpoint
The create_review method constructs JSON payloads like:
{
"body": "Looks good!",
"position": {
"position_type": "text",
"base_sha": "...",
"start_sha": "...",
"head_sha": "...",
"old_path": "src/lib.rs",
"new_path": "src/lib.rs",
"new_line": 42
}
}
It sends these via glab api projects/owner%2Frepo/merge_requests/123/discussions --method POST.
Key Implementation Files
The GitLab integration spans these source files in the agavra/tuicr repository:
src/forge/gitlab/glab.rs: Core backend implementation (GitLabGlabBackend,GlabCommandRunner,parse_gitlab_remote_url)src/forge/gitlab/models.rs: JSON deserialization structs (GlabMrSummary,GlabDiscussion)src/forge/traits.rs:ForgeBackendtrait definition common to all forge backendssrc/forge/selector.rs: UI state machine for the "Pull Requests" tab that paginates vialist_pull_requestssrc/forge/remote_comments.rs: Converts GitLab discussion objects intoRemoteReviewThreadstructs for the comment navigatorsrc/vcs/git/mod.rs: Remote URL detection and forge backend selection logic
Summary
- Tuicr integrates with GitLab through the
GitLabGlabBackendtype, which implements theForgeBackendtrait to provide unified MR operations. - The integration requires the
glabCLI tool to be installed and authenticated with appropriate GitLab token scopes (read_api,write_repository). - Remote detection occurs automatically in
src/vcs/git/mod.rs, selecting the GitLab backend forgitlab.comand recognized self-hosted instances. - All MR operations—including listing, diffing, and reviewing—execute via
glabshell commands managed byGlabCommandRunner. - Review submissions support multiple states (comment, approve, request changes, draft) using both REST and GraphQL endpoints.
Frequently Asked Questions
What happens if glab is not installed?
Tuicr displays a clear error message: "GitLab integration requires glab. Install GitLab CLI and run glab auth login". The error originates from GitLabGlabBackend initialization in src/forge/gitlab/glab.rs when the executable is not found in $PATH.
Does Tuicr support self-hosted GitLab instances?
Yes. Tuicr detects self-hosted GitLab instances when they are configured in your glab configuration (glab config get host). The parse_gitlab_remote_url function in src/forge/gitlab/glab.rs handles various GitLab URL formats, and the backend uses the standard glab CLI which supports multiple hosts.
How does Tuicr handle GitLab's diff format?
Since glab mr diff omits Git-style diff --git headers that Tuicr’s parser requires, the get_pull_request_diff method in GitLabGlabBackend calls inject_git_diff_headers to reconstruct proper diff headers before processing. This ensures compatibility with the diff parsing logic used across all forge backends.
Can I use draft reviews with GitLab?
Yes. When you submit with :submit draft, Tuicr calls the draft_notes endpoint instead of posting directly to the MR discussions. This requires appropriate permissions on the GitLab project. The backend distinguishes draft submissions from final reviews through the SubmitEvent type and routes them to the appropriate glab api endpoints.
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:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →