Skip to content

feat: Implement glab-setup-git-identity - GitLab CLI based git identity setup#2

Merged
konard merged 6 commits intomainfrom
issue-1-c860950de9b1
Jan 13, 2026
Merged

feat: Implement glab-setup-git-identity - GitLab CLI based git identity setup#2
konard merged 6 commits intomainfrom
issue-1-c860950de9b1

Conversation

@konard
Copy link
Member

@konard konard commented Jan 13, 2026

Summary

This PR implements glab-setup-git-identity, a library for setting up git identity using GitLab CLI (glab) - similar to gh-setup-git-identity but for GitLab.

Features

  • Authentication management

    • isGlabAuthenticated() - Check if GitLab CLI is authenticated
    • runGlabAuthLogin() - Run interactive or token-based authentication
    • runGlabAuthSetupGit() - Configure git to use glab as credential helper (NEW)
    • getGlabPath() - Detect glab installation path dynamically (NEW)
  • User information retrieval

    • getGitLabUsername() - Get GitLab username
    • getGitLabEmail() - Get GitLab primary email
    • getGitLabUserInfo() - Get both username and email
  • Git configuration

    • setGitConfig() - Set git config values
    • getGitConfig() - Get git config values
    • setupGitIdentity() - Configure git identity from GitLab account
    • verifyGitIdentity() - Verify current git identity
  • Additional features

    • Support for global and local git config scopes
    • Dry-run mode for previewing changes
    • Support for self-hosted GitLab instances via hostname option
    • Full TypeScript type definitions included
    • Automatic glab path detection - works regardless of installation method (Homebrew, apt, npm, etc.)

Git Credential Helper Setup

The new runGlabAuthSetupGit() function configures git to use glab for HTTPS authentication:

import {
  isGlabAuthenticated,
  runGlabAuthLogin,
  runGlabAuthSetupGit,
  setupGitIdentity,
} from 'glab-setup-git-identity';

// Check if authenticated
const authenticated = await isGlabAuthenticated();
if (!authenticated) {
  await runGlabAuthLogin();
}

// Configure git credential helper for GitLab HTTPS operations
await runGlabAuthSetupGit();

// Setup git identity from GitLab account
const { username, email } = await setupGitIdentity();
console.log(`Configured git as: ${username} <${email}>`);

This is equivalent to setting up:

git config --global credential."https://gitlab.com".helper ""
git config --global --add credential."https://gitlab.com".helper "!/path/to/glab auth git-credential"

The path to glab is detected automatically, so it works regardless of how glab was installed.

Issue Reference

Fixes #1

Test Plan

  • Unit tests for defaultAuthOptions verify correct defaults
  • Unit tests for getGitConfig verify null return for non-existent keys
  • Unit tests for setGitConfig verify setting and retrieving values
  • Unit tests for verifyGitIdentity verify returned object structure
  • Unit tests for getGlabPath verify function exists and returns promise
  • Unit tests for runGlabAuthSetupGit verify function exists and returns promise
  • All ESLint checks passing
  • All Prettier formatting checks passing
  • No code duplication detected (jscpd)

Note: Integration tests for GitLab API functions require authenticated glab CLI environment.


🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #1
@konard konard self-assigned this Jan 13, 2026
…ty setup

This is the initial implementation similar to gh-setup-git-identity but for GitLab.

Features:
- Check GitLab CLI authentication status (isGlabAuthenticated)
- Run interactive or token-based authentication (runGlabAuthLogin)
- Get GitLab user information (getGitLabUsername, getGitLabEmail, getGitLabUserInfo)
- Configure git user.name and user.email from GitLab account (setupGitIdentity)
- Support for global and local git config scopes
- Dry-run mode for previewing changes
- Support for self-hosted GitLab instances via hostname option
- Full TypeScript type definitions included

Fixes #1

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] Make an implementation similar to https://github.com/link-foundation/gh-setup-git-identity but for GitLab feat: Implement glab-setup-git-identity - GitLab CLI based git identity setup Jan 13, 2026
@konard konard marked this pull request as ready for review January 13, 2026 10:06
konard and others added 2 commits January 13, 2026 11:08
The glab-setup-git-identity library needs to spawn git and glab commands,
which requires the --allow-run flag for Deno. It also needs access to
environment variables which requires --allow-env.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard
Copy link
Member Author

konard commented Jan 13, 2026

⚠️ Solution Draft Finished with Errors

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $6.610612 USD
  • Calculated by Anthropic: $0.000000 USD
  • Difference: $-6.610612 (-100.00%)

Note: The session encountered errors during execution, but some work may have been completed. Please review the changes carefully.

📎 Log file uploaded as Gist (778KB)
🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Member Author

konard commented Jan 13, 2026

Make sure we do something like this:

Here's the correct sequence of commands to set up GitLab HTTPS authentication with glab:

  # 1. Login to GitLab (if not already logged in)
  glab auth login

  # 2. Configure glab as the git credential helper for GitLab
  git config --global credential."https://gitlab.com".helper ""
  git config --global --add credential."https://gitlab.com".helper "!/opt/homebrew/bin/glab auth git-credential"

  # 3. Now you can clone/push/pull without password prompts
  git clone https://gitlab.com/capico/rustbot.git rustbot-original

  That's it. The key is step 2 - it tells git to use glab auth git-credential as the credential helper for GitLab URLs, just like you have gh auth git-credential for GitHub.
!/opt/homebrew/bin/

But we should not depend on specific way of installation of glab tool.

And do support exactly all features of https://github.com/link-foundation/gh-setup-git-identity

So it should do login or check of status:

konard@MacBook-Pro-Konstantin capico % glab auth status
gitlab.com
  ✓ Logged in to gitlab.com as Konard (/Users/konard/Library/Application Support/glab-cli/config.yml)
  ✓ Git operations for gitlab.com configured to use https protocol.
  ✓ API calls for gitlab.com are made over https protocol.
  ✓ REST API Endpoint: https://gitlab.com/api/v4/
  ✓ GraphQL Endpoint: https://gitlab.com/api/graphql/
  ✓ Token found: **************************
konard@MacBook-Pro-Konstantin capico % 

If possible we should also be able to configure login permissions.

And we surely need to end with actual identity setup, based on user details from glab tool.

@konard konard marked this pull request as draft January 13, 2026 21:07
@konard
Copy link
Member Author

konard commented Jan 13, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-13T21:07:39.546Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

konard and others added 2 commits January 13, 2026 22:13
Add git credential helper configuration functionality equivalent to
`gh auth setup-git` for GitHub CLI. This allows seamless HTTPS
authentication when pushing/pulling to GitLab repositories.

Features:
- getGlabPath() - Dynamically detect glab installation path
- runGlabAuthSetupGit() - Configure git credential helper for GitLab

The implementation automatically detects the glab executable location
(works with any installation method: Homebrew, apt, npm, etc.) and
configures git to use `glab auth git-credential` as the credential
helper for GitLab HTTPS URLs.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fix Deno test failures caused by resource leaks. The tests for
getGlabPath and runGlabAuthSetupGit were creating promises that
weren't properly awaited, causing Deno's leak detection to fail.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review January 13, 2026 21:19
@konard
Copy link
Member Author

konard commented Jan 13, 2026

✅ Implementation Complete

Based on the feedback, I've added the following features to match gh-setup-git-identity for GitLab:

New Functions

  1. getGlabPath() - Dynamically detects the glab installation path without depending on any specific installation method (works with Homebrew, apt, npm, etc.)

  2. runGlabAuthSetupGit(options?) - Configures git to use glab as the credential helper for GitLab HTTPS operations. This is equivalent to gh auth setup-git for GitHub CLI.

How It Works

The runGlabAuthSetupGit() function:

  1. Detects the glab executable path automatically
  2. Configures git to use glab auth git-credential as the credential helper for the specified GitLab hostname
  3. Sets up the credential helper URL-pattern matching (e.g., https://gitlab.com)

This allows seamless HTTPS authentication when pushing/pulling to GitLab repositories, just like the GitHub version.

Usage Example

import {
  isGlabAuthenticated,
  runGlabAuthLogin,
  runGlabAuthSetupGit,
  setupGitIdentity,
} from 'glab-setup-git-identity';

// 1. Check/run authentication
const authenticated = await isGlabAuthenticated();
if (!authenticated) {
  await runGlabAuthLogin();
}

// 2. Configure git credential helper
await runGlabAuthSetupGit();
// Now git will use glab for authentication when pushing/pulling

// 3. Setup git identity
const { username, email } = await setupGitIdentity();

CI Status

  • All tests passing (Node.js, Bun, Deno)
  • ESLint checks passing
  • Prettier formatting checks passing
  • No code duplication detected

🤖 Generated with Claude Code

@konard
Copy link
Member Author

konard commented Jan 13, 2026

⚠️ Solution Draft Finished with Errors

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $5.156135 USD
  • Calculated by Anthropic: $0.000000 USD
  • Difference: $-5.156135 (-100.00%)

Note: The session encountered errors during execution, but some work may have been completed. Please review the changes carefully.

📎 Log file uploaded as Gist (658KB)
🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard merged commit 2018405 into main Jan 13, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make an implementation similar to https://github.com/link-foundation/gh-setup-git-identity but for GitLab

1 participant