label_formatter.rb 668 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
module Gitlab
  module GithubImport
    class LabelFormatter < BaseFormatter
      def attributes
        {
          project: project,
          title: title,
          color: color
        }
      end

12
13
      def klass
        Label
14
15
      end

16
      def create!
17
        params  = attributes.except(:project)
18
        service = ::Labels::FindOrCreateService.new(project.owner, project, params)
19
        label   = service.execute
20

21
22
23
        raise ActiveRecord::RecordInvalid.new(label) unless label.persisted?

        label
24
25
      end

26
27
28
29
30
31
32
33
34
35
36
37
      private

      def color
        "##{raw_data.color}"
      end

      def title
        raw_data.name
      end
    end
  end
end