From c196bab82ad2bb96d39e9726efe95f4cd7eb8fb3 Mon Sep 17 00:00:00 2001 From: Fabio Date: Tue, 3 Mar 2026 15:19:55 +0100 Subject: [PATCH] fix: support glab OAuth2 token in GitLab auth fallback GlabCLIToken() now tries `glab auth status -t` first, which correctly exposes the active token for both OAuth2 and PAT auth. Falls back to `glab config get token` for older glab versions. Co-Authored-By: Claude Opus 4.6 --- internal/auth/gitlab.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/auth/gitlab.go b/internal/auth/gitlab.go index 23b532b..ff44efa 100644 --- a/internal/auth/gitlab.go +++ b/internal/auth/gitlab.go @@ -9,7 +9,24 @@ import ( // GlabCLIToken attempts to get a GitLab token from the glab CLI tool. // Returns the token and true if successful, or empty string and false otherwise. func GlabCLIToken() (string, bool) { - out, err := exec.Command("glab", "config", "get", "token", "--host", "gitlab.com").Output() + // Try "glab auth status -t" first — works with OAuth2 and PAT auth. + out, err := exec.Command("glab", "auth", "status", "-t").CombinedOutput() + if err == nil { + for _, line := range strings.Split(string(out), "\n") { + line = strings.TrimSpace(line) + if strings.Contains(line, "Token found:") { + parts := strings.SplitN(line, "Token found:", 2) + if len(parts) == 2 { + token := strings.TrimSpace(parts[1]) + if token != "" && !strings.Contains(token, "***") { + return token, true + } + } + } + } + } + // Fall back to "glab config get token" for older glab versions. + out, err = exec.Command("glab", "config", "get", "token", "--host", "gitlab.com").Output() if err != nil { return "", false }