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
|
2016-05-18 17:14:20 -04:00
|
|
|
end
|
|
|
|
|
2016-09-01 15:37:58 -04:00
|
|
|
def create!
|
2016-10-17 22:27:10 -04:00
|
|
|
params = attributes.except(:project)
|
2016-10-28 05:31:45 -04:00
|
|
|
service = ::Labels::FindOrCreateService.new(nil, project, params)
|
|
|
|
label = service.execute(skip_authorization: true)
|
2016-10-17 22:27:10 -04:00
|
|
|
|
2016-10-18 04:26:16 -04:00
|
|
|
raise ActiveRecord::RecordInvalid.new(label) unless label.persisted?
|
|
|
|
|
|
|
|
label
|
2016-09-01 15:37:58 -04:00
|
|
|
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
|