summaryrefslogtreecommitdiff
path: root/lib/gitlab/legacy_github_import/base_formatter.rb
blob: 0b19cf742ed16c94e0f266b72d069876b41c244f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

module Gitlab
  module LegacyGithubImport
    class BaseFormatter
      attr_reader :client, :formatter, :project, :raw_data

      def initialize(project, raw_data, client = nil)
        @project = project
        @raw_data = raw_data
        @client = client
        @formatter = Gitlab::ImportFormatter.new
      end

      # rubocop: disable CodeReuse/ActiveRecord
      def create!
        association = project.public_send(project_association) # rubocop:disable GitlabSecurity/PublicSend

        association.find_or_create_by!(find_condition) do |record|
          record.attributes = attributes
        end
      end
      # rubocop: enable CodeReuse/ActiveRecord

      def url
        raw_data.url || ''
      end
    end
  end
end