blob: 1754f27137cf39b230ee66e46658d09daaba853b (
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# frozen_string_literal: true
module BulkImports
module Projects
module Pipelines
class ProjectAttributesPipeline
include Pipeline
file_extraction_pipeline!
relation_name BulkImports::FileTransfer::BaseConfig::SELF_RELATION
transformer ::BulkImports::Common::Transformers::ProhibitedAttributesTransformer
def extract(_context)
download_service.execute
decompression_service.execute
project_attributes = json_decode(json_attributes)
BulkImports::Pipeline::ExtractedData.new(data: project_attributes)
end
def transform(_context, data)
subrelations = config.portable_relations_tree.keys.map(&:to_s)
Gitlab::ImportExport::AttributeCleaner.clean(
relation_hash: data,
relation_class: Project,
excluded_keys: config.relation_excluded_keys(:project)
).except(*subrelations)
end
def load(_context, data)
portable.assign_attributes(data)
portable.reconcile_shared_runners_setting!
portable.drop_visibility_level!
portable.save!
end
def after_run(_context)
FileUtils.remove_entry(tmpdir) if Dir.exist?(tmpdir)
end
def json_attributes
@json_attributes ||= File.read(File.join(tmpdir, filename))
end
private
def tmpdir
@tmpdir ||= Dir.mktmpdir('bulk_imports')
end
def config
@config ||= BulkImports::FileTransfer.config_for(portable)
end
def download_service
@download_service ||= BulkImports::FileDownloadService.new(
configuration: context.configuration,
relative_url: context.entity.relation_download_url_path(self.class.relation),
tmpdir: tmpdir,
filename: compressed_filename
)
end
def decompression_service
@decompression_service ||= BulkImports::FileDecompressionService.new(tmpdir: tmpdir, filename: compressed_filename)
end
def compressed_filename
"#{filename}.gz"
end
def filename
"#{self.class.relation}.json"
end
def json_decode(string)
Gitlab::Json.parse(string)
rescue JSON::ParserError => e
Gitlab::ErrorTracking.log_exception(e)
raise BulkImports::Error, 'Incorrect JSON format'
end
end
end
end
end
|