Skip to content

Add GitLab support for git gtr clean --merged #98

@echarrod

Description

@echarrod

Summary

The clean --merged command currently only supports GitHub repositories via the gh CLI. It should also support GitLab repositories using the glab CLI.

Current Behavior

  • clean --merged requires the GitHub CLI (gh) and uses gh pr list --head <branch> --state merged to detect merged PRs
  • Running against a GitLab-hosted repo fails with: "Not authenticated with GitHub or not a GitHub repository"

Proposed Behavior

Auto-detect the remote hosting provider and use the appropriate CLI:

  • GitHubgh pr list --head <branch> --state merged ...
  • GitLabglab mr list --source-branch <branch> --merged ... (or equivalent)

Detection approach

Inspect the origin remote URL to determine the provider:

  • URLs containing github.com → use gh
  • URLs containing gitlab.com (or self-hosted GitLab instances) → use glab

Implementation notes

  • The glab CLI equivalent for checking merged MRs would be something like:
    glab mr list --source-branch "$branch" --merged --output json
  • glab auth check: glab auth status
  • Should fail gracefully if neither gh nor glab is installed, with a clear error message
  • Consider supporting self-hosted GitLab instances (glab handles this via glab auth login --hostname)
  • Could be extended to other providers (e.g., Bitbucket) in the future

Affected Code

  • bin/gtr lines ~1114-1210 (cmd_clean merged mode)

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions