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

Method ensurePerson

bridge/github/import.go:492–550  ·  view source on GitHub ↗

ensurePerson create a bug.Person from the Github data

(ctx context.Context, repo *cache.RepoCache, actor *actor)

Source from the content-addressed store, hash-verified

490
491// ensurePerson create a bug.Person from the Github data
492func (gi *githubImporter) ensurePerson(ctx context.Context, repo *cache.RepoCache, actor *actor) (*cache.IdentityCache, error) {
493 // When a user has been deleted, Github return a null actor, while displaying a profile named "ghost"
494 // in it's UI. So we need a special case to get it.
495 if actor == nil {
496 return gi.getGhost(ctx, repo)
497 }
498
499 // Look first in the cache
500 i, err := repo.Identities().ResolveIdentityImmutableMetadata(metaKeyGithubLogin, string(actor.Login))
501 if err == nil {
502 return i, nil
503 }
504 if entity.IsErrMultipleMatch(err) {
505 return nil, err
506 }
507
508 // importing a new identity
509 var name string
510 var email string
511
512 switch actor.Typename {
513 case "User":
514 if actor.User.Name != nil {
515 name = string(*(actor.User.Name))
516 }
517 email = string(actor.User.Email)
518 case "Organization":
519 if actor.Organization.Name != nil {
520 name = string(*(actor.Organization.Name))
521 }
522 if actor.Organization.Email != nil {
523 email = string(*(actor.Organization.Email))
524 }
525 case "Bot":
526 }
527
528 // Name is not necessarily set, fallback to login as a name is required in the identity
529 if name == "" {
530 name = string(actor.Login)
531 }
532
533 i, err = repo.Identities().NewRaw(
534 name,
535 email,
536 string(actor.Login),
537 string(actor.AvatarUrl),
538 nil,
539 map[string]string{
540 metaKeyGithubLogin: string(actor.Login),
541 },
542 )
543
544 if err != nil {
545 return nil, err
546 }
547
548 gi.out <- core.NewImportIdentity(i.Id())
549 return i, nil

Callers 4

ensureIssueMethod · 0.95
ensureTimelineItemMethod · 0.95
ensureCommentEditMethod · 0.95
ensureCommentMethod · 0.95

Calls 7

getGhostMethod · 0.95
IsErrMultipleMatchFunction · 0.92
NewImportIdentityFunction · 0.92
IdentitiesMethod · 0.80
IdMethod · 0.65
NewRawMethod · 0.45

Tested by

no test coverage detected