From fc346f4537070feba80615a3f7bb39147b7ce29c Mon Sep 17 00:00:00 2001 From: Howard Dong Date: Wed, 25 Feb 2026 17:17:51 +0800 Subject: [PATCH] fix(copilot): add username fallback and consistent file name prefix - Add 'github-user' fallback in WaitForAuthorization when FetchUserInfo returns empty Login (fixes malformed 'github-copilot-.json' filenames) - Standardize Web API file name to 'github-copilot-.json' to match CLI path convention (was 'github-.json') Addresses Gemini Code Assist review comments on PR #291. --- internal/api/handlers/management/auth_files.go | 2 +- internal/auth/copilot/copilot_auth.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/api/handlers/management/auth_files.go b/internal/api/handlers/management/auth_files.go index 342868bc..3794793c 100644 --- a/internal/api/handlers/management/auth_files.go +++ b/internal/api/handlers/management/auth_files.go @@ -1974,7 +1974,7 @@ func (h *Handler) RequestGitHubToken(c *gin.Context) { Type: "github-copilot", } - fileName := fmt.Sprintf("github-%s.json", username) + fileName := fmt.Sprintf("github-copilot-%s.json", username) label := userInfo.Email if label == "" { label = username diff --git a/internal/auth/copilot/copilot_auth.go b/internal/auth/copilot/copilot_auth.go index d702583e..5776648c 100644 --- a/internal/auth/copilot/copilot_auth.go +++ b/internal/auth/copilot/copilot_auth.go @@ -87,9 +87,14 @@ func (c *CopilotAuth) WaitForAuthorization(ctx context.Context, deviceCode *Devi log.Warnf("copilot: failed to fetch user info: %v", err) } + username := userInfo.Login + if username == "" { + username = "github-user" + } + return &CopilotAuthBundle{ TokenData: tokenData, - Username: userInfo.Login, + Username: username, Email: userInfo.Email, Name: userInfo.Name, }, nil