diff options
Diffstat (limited to 'lib/gitlab/legacy_github_import/label_formatter.rb')
-rw-r--r-- | lib/gitlab/legacy_github_import/label_formatter.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/gitlab/legacy_github_import/label_formatter.rb b/lib/gitlab/legacy_github_import/label_formatter.rb new file mode 100644 index 00000000000..c3eed12e739 --- /dev/null +++ b/lib/gitlab/legacy_github_import/label_formatter.rb @@ -0,0 +1,37 @@ +module Gitlab + module LegacyGithubImport + class LabelFormatter < BaseFormatter + def attributes + { + project: project, + title: title, + color: color + } + end + + def project_association + :labels + end + + def create! + params = attributes.except(:project) + service = ::Labels::FindOrCreateService.new(nil, project, params) + label = service.execute(skip_authorization: true) + + raise ActiveRecord::RecordInvalid.new(label) unless label.persisted? + + label + end + + private + + def color + "##{raw_data.color}" + end + + def title + raw_data.name + end + end + end +end |