2015-12-23 22:02:59 +00:00
|
|
|
module Gitlab
|
|
|
|
module GithubImport
|
|
|
|
class BaseFormatter
|
|
|
|
attr_reader :formatter, :project, :raw_data
|
|
|
|
|
|
|
|
def initialize(project, raw_data)
|
|
|
|
@project = project
|
|
|
|
@raw_data = raw_data
|
|
|
|
@formatter = Gitlab::ImportFormatter.new
|
|
|
|
end
|
|
|
|
|
2016-06-06 17:00:44 +00:00
|
|
|
def create!
|
2016-10-19 18:42:31 +00:00
|
|
|
project.send(project_association).find_or_create_by!(find_condition) do |record|
|
|
|
|
record.attributes = attributes
|
|
|
|
end
|
2016-06-06 17:00:44 +00:00
|
|
|
end
|
|
|
|
|
2015-12-23 22:02:59 +00:00
|
|
|
private
|
|
|
|
|
2016-09-08 00:44:58 +00:00
|
|
|
def gitlab_user_id(github_id)
|
2015-12-23 22:02:59 +00:00
|
|
|
User.joins(:identities).
|
|
|
|
find_by("identities.extern_uid = ? AND identities.provider = 'github'", github_id.to_s).
|
|
|
|
try(:id)
|
|
|
|
end
|
2016-08-29 09:48:36 +00:00
|
|
|
|
|
|
|
def gitlab_author_id
|
|
|
|
return @gitlab_author_id if defined?(@gitlab_author_id)
|
|
|
|
@gitlab_author_id = gitlab_user_id(raw_data.user.id)
|
|
|
|
end
|
2015-12-23 22:02:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|