feat: add subfolder and ssh_host support for GitLab instances

Description

This MR adds support for GitLab instances hosted in subfolders (e.g., example.com/gitlab) and alternate SSH hostnames (e.g., ssh.example.com).

Key Changes

  • New Config Fields:

    • subfolder: For HTTP/API subfolder paths (e.g., gitlab in example.com/gitlab)
    • ssh_host: For alternate SSH hostnames (e.g., ssh.example.com or git.example.com)
    • Both fields support environment variables: GITLAB_SUBFOLDER, GITLAB_SSH_HOST
  • Auth Login Enhancement:

    • Automatically splits --hostname example.com/gitlab into hostname + subfolder
    • Auto-detects SSH hostname from git remotes and prompts user
    • Stores config with bare hostname as key
  • Remote Resolution:

    • Maps SSH hosts to config entries for proper remote recognition
    • Allows git remotes with different SSH hostnames to be recognized
  • URL Construction:

    • Simplified URL parsing in FromURL() with cleaner logic
    • Fixed GraphQL endpoint to support api_host and subfolder (was previously broken)
    • Updated all APIEndpoint/GraphQLEndpoint call sites
  • Backward Compatibility:

    • Existing api_host with paths continues working
    • Subfolder extracted from api_host automatically if subfolder field is empty

Root Cause

When users ran glab auth login --hostname example.com/gitlab, it created a config key example.com/gitlab. However, git remote URLs extract bare hostname example.com, causing a mismatch in remote resolution where the knownHosts check would fail.

Solution

Now stores config with bare hostname as key and subfolder separately, allowing git remotes to be correctly recognized as authenticated hosts.

How has this been tested?

Automated Tests:

  • All existing tests pass
  • glinstance tests (URL construction with subfolder)
  • glrepo tests (simplified URL parsing)
  • auth login tests (hostname splitting)
  • auth status tests (display new fields)
  • cmdutils tests (remote resolution with SSH mapping)
  • API client tests (client initialization)
  • Build compiles successfully

Testing Scenarios:

  1. Auth login with subfolder input
  2. Git remotes with subfolder paths are recognized
  3. SSH host detection and configuration
  4. Mixed remotes (HTTP + SSH) both resolve correctly
  5. Backward compatibility with existing api_host configurations
  6. GraphQL commands work with subfolders (bug fix)
Edited by Kai Armstrong

Merge request reports

Loading