mach10 icon indicating copy to clipboard operation
mach10 copied to clipboard

Add GitLab support alongside GitHub

Open LeanAndMean opened this issue 7 months ago • 1 comments

Summary

Mach10 currently assumes GitHub as the sole git hosting platform, with all 15 commands using the gh CLI directly. To serve teams using GitLab, the plugin should support GitLab as an alternative platform -- ideally auto-detected from the repository remote, requiring no manual configuration.

Current Behavior

All commands hardcode gh CLI calls for issue management, PR operations, CI status checks, and comment posting. Users on GitLab-hosted repositories cannot use any of the issue or PR workflow commands.

Proposed Behavior

Mach10 should detect the git hosting platform from the repository remote and adapt its commands accordingly. The goal is a "just works" experience -- no manual configuration required for the common case.

Open Questions

The right approach needs further investigation before committing to a solution. Key questions include:

  • Abstraction level: Should commands branch internally (e.g., "if GitLab, use glab; if GitHub, use gh"), or should there be a shared abstraction layer?
  • CLI parity: GitLab's glab CLI has similar commands to gh but different flags, JSON field names, and API paths. How deep do the differences go across all 15 commands?
  • CI differences: GitHub Actions vs GitLab CI have very different log structures and status APIs. Commands like pr-ci-fix may need significant platform-specific logic.
  • Terminology mapping: GitHub "pull requests" vs GitLab "merge requests", "checks" vs "pipelines", etc. How should this be handled in command output and GitHub/GitLab comment formatting?
  • Naming: An environment variable for the detected platform should avoid implying GitHub is Mach10's "provider" -- something like MACH10_GIT_HOST or MACH10_PLATFORM rather than MACH10_PROVIDER.

One Possible Approach (Not Prescriptive)

One direction explored in early discussion:

  1. A SessionStart hook detects the platform from git remote get-url origin and exports an environment variable (e.g., MACH10_GIT_HOST=github or MACH10_GIT_HOST=gitlab)
  2. The same hook validates the appropriate CLI is installed (gh or glab)
  3. Each command's natural language body includes branching instructions for platform-specific CLI calls

This is one option among several. MCP server abstraction, wrapper scripts in bin/, and other approaches should also be evaluated during planning.

Acceptance Criteria

  • Mach10 auto-detects whether the repository is hosted on GitHub or GitLab from the git remote
  • No manual configuration is required for the common case (public GitHub/GitLab remotes)
  • All issue workflow commands work with GitLab issues
  • All PR workflow commands work with GitLab merge requests
  • CI-related commands work with GitLab CI pipelines
  • Existing GitHub workflows continue to work without regression
  • The solution handles self-hosted instances (e.g., gitlab.company.com) in addition to github.com and gitlab.com

Technical Notes

  • GitLab CLI (glab) is the GitLab equivalent of gh: https://gitlab.com/gitlab-org/cli
  • Commands with the deepest GitHub integration: pr-review (comment posting, feature-completeness-checker), pr-ci-fix (CI log parsing), issue-plan (plan comment with HTML markers)
  • The <!-- mach10-plan --> and <!-- mach10-decisions --> HTML markers used in GitHub comments should work identically in GitLab markdown
  • This is a large scope change that will likely need staged implementation across multiple PRs

LeanAndMean avatar Apr 07 '26 16:04 LeanAndMean

Research Findings and Proposed Approach

How gh and glab compare

Analysis of the gh and glab CLIs shows significant command overlap. Most issue commands are syntactically identical (gh issue view / glab issue view). The major divergences are:

  • PR vs MR: All gh pr subcommands become glab mr subcommands
  • CI: gh run becomes glab ci, with different log access patterns
  • JSON output: --json field1,field2 (gh) vs -F json / --output json (glab)
  • API paths: gh api repos/OWNER/REPO/... vs glab api projects/OWNER%2FREPO/...
  • Comments: gh issue comment / gh pr comment vs glab issue note / glab mr note
  • GitHub-only extensions: gh-sub-issue (no GitLab equivalent -- use milestones), gh-pm (use labels), gh-pr-review (use glab mr note + mr note resolve)

Proposed approach

After evaluating several options (MCP server abstraction, per-topic reference files, per-command inline crosswalks, full dual-provider reference files), the recommended approach is "differences only" with GitHub as baseline:

1. SessionStart hook (hooks/detect-provider.sh)

  • Detects platform from git remote get-url origin (matching github.com, gitlab.com, self-hosted patterns)
  • Writes MACH10_GIT_HOST=github|gitlab to $CLAUDE_ENV_FILE
  • Validates the appropriate CLI (gh or glab) is installed and authenticated

2. One GitLab differences reference file (references/gitlab.md, ~30-40 lines)

  • Documents only where glab diverges from gh: command renames (gh pr -> glab mr, gh run -> glab ci), flag differences, API path changes, and features without GitLab equivalents (gh-sub-issue -> milestones, gh-pm -> labels)
  • NOT a full CLI reference -- just the exceptions

3. One conditional line per command

  • Each command gets: "If $MACH10_GIT_HOST is gitlab, read ${CLAUDE_PLUGIN_ROOT}/references/gitlab.md and apply its substitutions to all gh commands below."
  • Commands keep their existing gh syntax as the baseline
  • On GitHub repos, no reference file is read (zero overhead). On GitLab repos, one small file read per command.

Why this approach

  • Minimal change surface: Commands stay written in gh syntax. No structural rewrites.
  • Zero overhead for existing users: GitHub repos work exactly as before with no extra file reads.
  • One source of truth for GitLab differences: A single ~30-40 line file vs. crosswalk sections duplicated across 15 commands.
  • SessionStart hook pulls double duty: Also validates prerequisites (gh/glab installed and authenticated), addressing first-session setup failures.
  • Self-hosted support: The hook can match gitlab.company.com patterns, not just gitlab.com.

Key divergences to document in the reference file

GitHub (gh) GitLab (glab) Notes
gh pr subcommands glab mr subcommands All PR operations become MR operations
gh run (CI) glab ci Different log access: glab ci trace vs gh run view --log
gh issue comment glab issue note
gh pr comment glab mr note
--json field1,field2 -F json / --output json Different JSON output flags
gh api repos/OWNER/REPO/... glab api projects/OWNER%2FREPO/... Different API path structure
gh-sub-issue (extension) Milestones Group stage issues under a milestone
gh-pm (extension) Label updates glab issue update --label for workflow state
gh-pr-review (extension) glab mr note + mr note resolve No pending review thread equivalent

LeanAndMean avatar Apr 07 '26 17:04 LeanAndMean