Class: Gitlab::LegacyGithubImport::BaseFormatter
- Inherits:
-
Object
- Object
- Gitlab::LegacyGithubImport::BaseFormatter
- Defined in:
- lib/gitlab/legacy_github_import/base_formatter.rb
Direct Known Subclasses
BranchFormatter, CommentFormatter, IssuableFormatter, LabelFormatter, MilestoneFormatter, ReleaseFormatter
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
-
#source_user_mapper ⇒ Object
readonly
Returns the value of attribute source_user_mapper.
Instance Method Summary collapse
-
#contributing_user_formatters ⇒ Object
A hash of user_reference_columns and its corresponding UserFormatter objects must be defined on each formatter in order to save it using #create!.
- #create! ⇒ Object
-
#create_record ⇒ Object
rubocop: disable CodeReuse/ActiveRecord – Existing legacy code.
- #imported_from ⇒ Object
-
#initialize(project, raw_data, client = nil, source_user_mapper = nil) ⇒ BaseFormatter
constructor
A new instance of BaseFormatter.
- #push_placeholder_reference(record, user_reference_column, source_user) ⇒ Object
-
#push_placeholder_references(record, contributing_users: nil) ⇒ Object
rubocop: enable CodeReuse/ActiveRecord.
- #url ⇒ Object
Constructor Details
#initialize(project, raw_data, client = nil, source_user_mapper = nil) ⇒ BaseFormatter
Returns a new instance of BaseFormatter.
8 9 10 11 12 13 14 |
# File 'lib/gitlab/legacy_github_import/base_formatter.rb', line 8 def initialize(project, raw_data, client = nil, source_user_mapper = nil) @project = project @raw_data = raw_data @client = client @formatter = Gitlab::ImportFormatter.new @source_user_mapper = source_user_mapper end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/gitlab/legacy_github_import/base_formatter.rb', line 6 def client @client end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
6 7 8 |
# File 'lib/gitlab/legacy_github_import/base_formatter.rb', line 6 def formatter @formatter end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
6 7 8 |
# File 'lib/gitlab/legacy_github_import/base_formatter.rb', line 6 def project @project end |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
6 7 8 |
# File 'lib/gitlab/legacy_github_import/base_formatter.rb', line 6 def raw_data @raw_data end |
#source_user_mapper ⇒ Object (readonly)
Returns the value of attribute source_user_mapper.
6 7 8 |
# File 'lib/gitlab/legacy_github_import/base_formatter.rb', line 6 def source_user_mapper @source_user_mapper end |
Instance Method Details
#contributing_user_formatters ⇒ Object
A hash of user_reference_columns and its corresponding UserFormatter objects must be defined on each formatter in order to save it using #create!
76 77 78 |
# File 'lib/gitlab/legacy_github_import/base_formatter.rb', line 76 def contributing_user_formatters raise NotImplementedError end |
#create! ⇒ Object
16 17 18 19 20 21 |
# File 'lib/gitlab/legacy_github_import/base_formatter.rb', line 16 def create! record = create_record push_placeholder_references(record) record end |
#create_record ⇒ Object
rubocop: disable CodeReuse/ActiveRecord – Existing legacy code
24 25 26 27 28 29 30 |
# File 'lib/gitlab/legacy_github_import/base_formatter.rb', line 24 def create_record association = project.public_send(project_association) # rubocop:disable GitlabSecurity/PublicSend association.find_or_create_by!(find_condition) do |record| record.attributes = attributes end end |
#imported_from ⇒ Object
67 68 69 70 71 72 |
# File 'lib/gitlab/legacy_github_import/base_formatter.rb', line 67 def imported_from return ::Import::SOURCE_GITEA if project.gitea_import? return ::Import::SOURCE_GITHUB if project.github_import? ::Import::SOURCE_NONE end |
#push_placeholder_reference(record, user_reference_column, source_user) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gitlab/legacy_github_import/base_formatter.rb', line 41 def push_placeholder_reference(record, user_reference_column, source_user) return unless project.import_data.user_mapping_enabled? return if project.root_ancestor.user_namespace? user_id = record[user_reference_column] return if user_id.nil? || source_user.nil? return if source_user.accepted_status? && user_id == source_user.reassign_to_user_id # Do not create a reference for reference-free reassignment return if ::Import::DirectReassignService.supported?(record.class, user_reference_column, source_user) ::Import::PlaceholderReferences::PushService.from_record( import_source: imported_from, import_uid: project.import_state.id, record: record, source_user: source_user, user_reference_column: user_reference_column ).execute end |
#push_placeholder_references(record, contributing_users: nil) ⇒ Object
rubocop: enable CodeReuse/ActiveRecord
33 34 35 36 37 38 39 |
# File 'lib/gitlab/legacy_github_import/base_formatter.rb', line 33 def push_placeholder_references(record, contributing_users: nil) contributing_users ||= contributing_user_formatters contributing_users.each do |user_reference_column, user_formatter| push_placeholder_reference(record, user_reference_column, user_formatter.source_user) end end |
#url ⇒ Object
63 64 65 |
# File 'lib/gitlab/legacy_github_import/base_formatter.rb', line 63 def url raw_data[:url] || '' end |