Welcome to mirror list, hosted at ThFree Co, Russian Federation.

label_formatter.rb « github_import « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 211ccdc51bb09bb34c0c22b5c10f92105b05d9b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Gitlab
  module GithubImport
    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