MCPcopy Create free account
hub / github.com/github/gh-aw / promptForCopilotPATUnified

Function promptForCopilotPATUnified

pkg/cli/engine_secrets.go:294–339  ·  view source on GitHub ↗

promptForCopilotPATUnified prompts the user for a Copilot PAT with detailed instructions

(req SecretRequirement, config EngineSecretConfig)

Source from the content-addressed store, hash-verified

292
293// promptForCopilotPATUnified prompts the user for a Copilot PAT with detailed instructions
294func promptForCopilotPATUnified(req SecretRequirement, config EngineSecretConfig) error {
295 fmt.Fprintln(os.Stderr, "")
296 fmt.Fprintln(os.Stderr, "GitHub Copilot requires a fine-grained Personal Access Token (PAT) with 'Copilot requests' permissions.")
297 fmt.Fprintln(os.Stderr, "")
298 fmt.Fprintln(os.Stderr, "Please create a token at:")
299 fmt.Fprintln(os.Stderr, console.FormatCommandMessage(" "+req.KeyURL))
300 fmt.Fprintln(os.Stderr, "")
301 fmt.Fprintln(os.Stderr, "Configure the token with:")
302 fmt.Fprintln(os.Stderr, " • Token name: Agentic Workflows Copilot")
303 fmt.Fprintln(os.Stderr, " • Expiration: 90 days (recommended for testing)")
304 fmt.Fprintln(os.Stderr, " • Resource owner: Your personal account")
305 fmt.Fprintln(os.Stderr, " • Repository access: \"Public repositories\" (you must use this setting for Copilot Requests permission to appear)")
306 fmt.Fprintln(os.Stderr, " • Add permissions → Copilot Requests: Read-only")
307 fmt.Fprintln(os.Stderr, "")
308 fmt.Fprintln(os.Stderr, "If you run into trouble see https://github.github.com/gh-aw/reference/auth/#copilot_github_token.")
309
310 var token string
311 form := huh.NewForm(
312 huh.NewGroup(
313 huh.NewInput().
314 Title("After creating, please paste your fine-grained Copilot PAT:").
315 Description("Must start with 'github_pat_'. Classic PATs (ghp_...) are not supported.").
316 EchoMode(huh.EchoModePassword).
317 Value(&token).
318 Validate(func(s string) error {
319 if len(s) < 10 {
320 return errors.New("token appears to be too short")
321 }
322 return stringutil.ValidateCopilotPAT(s)
323 }),
324 ),
325 ).WithTheme(styles.HuhTheme).WithAccessible(console.IsAccessibleMode())
326
327 if err := form.RunWithContext(config.ctx()); err != nil {
328 return fmt.Errorf("failed to get Copilot token: %w", err)
329 }
330
331 fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Valid fine-grained Copilot token received"))
332
333 // Upload to repository if we have a repo slug
334 if config.RepoSlug != "" {
335 return uploadSecretToRepo(req.Name, token, config.RepoSlug, config.Verbose)
336 }
337
338 return nil
339}
340
341// promptForSystemTokenUnified prompts the user for a system-level GitHub token (PAT)
342// This uses PAT-specific wording instead of "API key" since system secrets are GitHub tokens

Callers 1

promptForSecretFunction · 0.85

Calls 8

FormatCommandMessageFunction · 0.92
ValidateCopilotPATFunction · 0.92
IsAccessibleModeFunction · 0.92
FormatSuccessMessageFunction · 0.92
uploadSecretToRepoFunction · 0.85
ctxMethod · 0.80
ValidateMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected