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

Function validateUsername

bridge/github/config.go:477–516  ·  view source on GitHub ↗
(username string)

Source from the content-addressed store, hash-verified

475}
476
477func validateUsername(username string) (bool, string, error) {
478 url := fmt.Sprintf("%s/users/%s", githubV3Url, username)
479
480 client := &http.Client{
481 Timeout: defaultTimeout,
482 }
483
484 resp, err := client.Get(url)
485 if err != nil {
486 return false, "", err
487 }
488
489 if resp.StatusCode != http.StatusOK {
490 return false, "", nil
491 }
492
493 data, err := io.ReadAll(resp.Body)
494 if err != nil {
495 return false, "", err
496 }
497
498 err = resp.Body.Close()
499 if err != nil {
500 return false, "", err
501 }
502
503 var decoded struct {
504 Login string `json:"login"`
505 }
506 err = json.Unmarshal(data, &decoded)
507 if err != nil {
508 return false, "", err
509 }
510
511 if decoded.Login == "" {
512 return false, "", fmt.Errorf("validateUsername: missing login in the response")
513 }
514
515 return true, decoded.Login, nil
516}
517
518func validateProject(owner, project string, token *auth.Token) (bool, error) {
519 url := fmt.Sprintf("%s/repos/%s/%s", githubV3Url, owner, project)

Callers 3

TestValidateUsernameFunction · 0.85
ConfigureMethod · 0.85
promptLoginFunction · 0.85

Calls 4

GetMethod · 0.80
ErrorfMethod · 0.80
ReadAllMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestValidateUsernameFunction · 0.68