MCPcopy Index your code
hub / github.com/git-bug/git-bug / promptToken

Function promptToken

bridge/github/config.go:355–391  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

353}
354
355func promptToken() (*auth.Token, error) {
356 fmt.Println("You can generate a new token by visiting https://github.com/settings/tokens.")
357 fmt.Println("Choose 'Generate new token' and set the necessary access scope for your repository.")
358 fmt.Println()
359 fmt.Println("The access scope depend on the type of repository.")
360 fmt.Println("Public:")
361 fmt.Println(" - 'public_repo': to be able to read public repositories")
362 fmt.Println("Private:")
363 fmt.Println(" - 'repo' : to be able to read private repositories")
364 fmt.Println()
365
366 legacyRe := regexp.MustCompile(`^[a-zA-Z0-9]{40}$`)
367 re := regexp.MustCompile(`^(?:ghp|gho|ghu|ghs|ghr)_[a-zA-Z0-9]{36,255}$`)
368
369 var login string
370
371 validator := func(name string, value string) (complaint string, err error) {
372 if !re.MatchString(value) && !legacyRe.MatchString(value) {
373 return "token has incorrect format", nil
374 }
375 login, err = getLoginFromToken(auth.NewToken(target, value))
376 if err != nil {
377 return fmt.Sprintf("token is invalid: %v", err), nil
378 }
379 return "", nil
380 }
381
382 rawToken, err := input.Prompt("Enter token", "token", input.Required, validator)
383 if err != nil {
384 return nil, err
385 }
386
387 token := auth.NewToken(target, rawToken)
388 token.SetMetadata(auth.MetaKeyLogin, login)
389
390 return token, nil
391}
392
393func promptURL(repo repository.RepoCommon) (string, string, error) {
394 validRemotes, err := getValidGithubRemoteURLs(repo)

Callers 1

promptTokenOptionsFunction · 0.70

Calls 5

NewTokenFunction · 0.92
PromptFunction · 0.92
getLoginFromTokenFunction · 0.70
PrintlnMethod · 0.65
SetMetadataMethod · 0.65

Tested by

no test coverage detected