Class: Gitlab::LegacyGithubImport::UserFormatter

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/legacy_github_import/user_formatter.rb

Constant Summary collapse

GITEA_GHOST_EMAIL =
'ghost_user@gitea_import_dummy_email.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, raw, project, source_user_mapper) ⇒ UserFormatter

Returns a new instance of UserFormatter.



12
13
14
15
16
17
# File 'lib/gitlab/legacy_github_import/user_formatter.rb', line 12

def initialize(client, raw, project, source_user_mapper)
  @client = client
  @raw = raw
  @project = project
  @source_user_mapper = source_user_mapper
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



8
9
10
# File 'lib/gitlab/legacy_github_import/user_formatter.rb', line 8

def client
  @client
end

#projectObject (readonly)

Returns the value of attribute project.



8
9
10
# File 'lib/gitlab/legacy_github_import/user_formatter.rb', line 8

def project
  @project
end

#rawObject (readonly)

Returns the value of attribute raw.



8
9
10
# File 'lib/gitlab/legacy_github_import/user_formatter.rb', line 8

def raw
  @raw
end

#source_user_mapperObject (readonly)

Returns the value of attribute source_user_mapper.



8
9
10
# File 'lib/gitlab/legacy_github_import/user_formatter.rb', line 8

def source_user_mapper
  @source_user_mapper
end

Instance Method Details

#gitlab_idObject



27
28
29
30
31
32
33
# File 'lib/gitlab/legacy_github_import/user_formatter.rb', line 27

def gitlab_id
  return find_by_email unless user_mapping_enabled?
  return GithubImport.ghost_user_id(project.organization_id) if ghost_user?
  return project.root_ancestor.owner_id if map_to_personal_namespace_owner?

  gitlab_user&.id
end

#idObject



19
20
21
# File 'lib/gitlab/legacy_github_import/user_formatter.rb', line 19

def id
  raw[:id]
end

#loginObject



23
24
25
# File 'lib/gitlab/legacy_github_import/user_formatter.rb', line 23

def 
  raw[:login]
end

#source_userObject



36
37
38
39
40
41
42
43
44
# File 'lib/gitlab/legacy_github_import/user_formatter.rb', line 36

def source_user
  return if !user_mapping_enabled? || map_to_personal_namespace_owner? || ghost_user?

  source_user_mapper.find_or_create_source_user(
    source_name: gitea_user[:full_name].presence || gitea_user[:login],
    source_username: gitea_user[:login],
    source_user_identifier: raw[:id]
  )
end