gitlab-org--gitlab-foss/lib/gitlab/github_import/label_formatter.rb

38 lines
700 B
Ruby
Raw Normal View History

2016-04-17 22:52:34 -04:00
module Gitlab
module GithubImport
class LabelFormatter < BaseFormatter
def attributes
{
project: project,
title: title,
color: color
}
end
2016-10-19 14:42:31 -04:00
def project_association
:labels
end
def create!
params = attributes.except(:project)
service = ::Labels::FindOrCreateService.new(nil, project, params)
label = service.execute(skip_authorization: true)
2016-10-18 04:26:16 -04:00
raise ActiveRecord::RecordInvalid.new(label) unless label.persisted?
label
end
2016-04-17 22:52:34 -04:00
private
def color
"##{raw_data.color}"
end
def title
raw_data.name
end
end
end
end