blob: 33a24e61a3ffc955ca2d2ac99ea6734bef40b7fa (
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
|
# frozen_string_literal: true
module BulkImports
module Common
module Pipelines
class BadgesPipeline
include Pipeline
extractor BulkImports::Common::Extractors::RestExtractor,
query: BulkImports::Common::Rest::GetBadgesQuery
transformer Common::Transformers::ProhibitedAttributesTransformer
def transform(context, data)
return if data.blank?
# Project badges API returns badges of both group and project kind. To avoid creation of duplicates for the group we skip group badges when it's a project.
return if context.entity.project? && group_badge?(data)
{
name: data['name'],
link_url: data['link_url'],
image_url: data['image_url']
}
end
def load(context, data)
return if data.blank?
if context.entity.project?
context.portable.project_badges.create!(data)
else
context.portable.badges.create!(data)
end
end
private
def group_badge?(data)
data['kind'] == 'group'
end
end
end
end
end
|