func (m *GormIdentityRepository) Lookup(ctx context.Context, username, profileURL, providerType string) (*Identity, error) {
	if username == "" || profileURL == "" || providerType == "" {
		return nil, errors.New("Cannot lookup identity with empty username, profile URL or provider type")
	}
	log.Debug(nil, nil, "Looking for identity of user with profile URL=%s\n", profileURL)
	// bind the assignee to an existing identity, or create a new one
	identity, err := m.First(IdentityFilterByProfileURL(profileURL))
	if err != nil {
		return nil, errors.Wrapf(err, "failed to lookup identity by profileURL '%s'", profileURL)
	}
	if identity == nil {
		// create the identity if it does not exist yet
		log.Debug(nil, nil, "Creating an identity for username '%s' with profile '%s' on '%s'\n", username, profileURL, providerType)
		identity = &Identity{
			ProviderType: providerType,
			Username:     username,
			ProfileURL:   &profileURL,
		}
		err = m.Create(context.Background(), identity)
		if err != nil {
			return nil, errors.Wrap(err, "failed to create identity during lookup")
		}
	} else {
		// use existing identity
		log.Debug(nil, nil, "Using existing identity with ID: %v", identity.ID.String())
	}
	log.Debug(nil, nil, "Found identity of user with profile URL=%s: %s", profileURL, identity.ID)
	return identity, nil
}
// Lookup looks for an existing identity with the given `profileURL` or creates a new one
Lookup looks for an existing identity with the given `profileURL` or creates a new one
// Lookup looks for an existing identity with the given ` profileURL ` or creates a new one
func (m *GormIdentityRepository) Lookup(ctx context.Context, username, profileURL, providerType string) (*Identity, error) {
	if username == "" || profileURL == "" || providerType == "" {
		return nil, errors.New("Cannot lookup identity with empty username, profile URL or provider type")
	}
	log.Debug(nil, nil, "Looking for identity of user with profile URL=%s\n", profileURL)
	identity, err := m.First(IdentityFilterByProfileURL(profileURL))
	if err != nil {
		return nil, errors.Wrapf(err, "failed to lookup identity by profileURL '%s'", profileURL)
	}
	if identity == nil {
		log.Debug(nil, nil, "Creating an identity for username '%s' with profile '%s' on '%s'\n", username, profileURL, providerType)
		identity = &Identity{
			ProviderType: providerType,
			Username:     username,
			ProfileURL:   &profileURL,
		}
		err = m.Create(context.Background(), identity)
		if err != nil {
			return nil, errors.Wrap(err, "failed to create identity during lookup")
		}
	} else {
		log.Debug(nil, nil, "Using existing identity with ID: %v", identity.ID.String())
	}
	log.Debug(nil, nil, "Found identity of user with profile URL=%s: %s", profileURL, identity.ID)
	return identity, nil
}
func ( m * GormIdentityRepository ) Lookup ( ctx context . Context , username , profileURL , providerType string ) ( * Identity , error ) { if username == " " || profileURL == " " || providerType == " " { return nil , errors . New ( " " ) } log . Debug ( nil , nil , " \n " , profileURL ) identity , err := m . First ( IdentityFilterByProfileURL ( profileURL ) ) if err != nil { return nil , errors . Wrapf ( err , " " , profileURL ) } if identity == nil { log . Debug ( nil , nil , " \n " , username , profileURL , providerType ) identity = & Identity { ProviderType : providerType , Username : username , ProfileURL : & profileURL , } err = m . Create ( context . Background ( ) , identity ) if err != nil { return nil , errors . Wrap ( err , " " ) } } else { log . Debug ( nil , nil , " " , identity . ID . String ( ) ) } log . Debug ( nil , nil , " " , profileURL , identity . ID ) return identity , nil }
Lookup looks for an existing identity with the given `profileURL` or creates a new one
Lookup looks for an existing identity with the given ` profileURL ` or creates a new one
// bind the assignee to an existing identity, or create a new one // create the identity if it does not exist yet // use existing identity