debian-mirror-gitlab/lib/bulk_imports/common/pipelines/badges_pipeline.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.1 KiB
Ruby
Raw Normal View History

2022-01-26 12:08:38 +05:30
# 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