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

labels_importer.rb « importer « github_import « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7293de56a9a4bbd00048e3a4232d7d044730f66f (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

module Gitlab
  module GithubImport
    module Importer
      class LabelsImporter
        include BulkImporting

        # rubocop: disable CodeReuse/ActiveRecord
        def existing_labels
          @existing_labels ||= project.labels.pluck(:title).to_set
        end
        # rubocop: enable CodeReuse/ActiveRecord

        def execute
          bulk_insert(Label, build_labels)
          build_labels_cache
        end

        def build_labels
          build_database_rows(each_label)
        end

        def already_imported?(label)
          existing_labels.include?(label.name)
        end

        def build_labels_cache
          LabelFinder.new(project).build_cache
        end

        def build(label)
          time = Time.zone.now

          {
            title: label.name,
            color: '#' + label.color,
            project_id: project.id,
            type: 'ProjectLabel',
            created_at: time,
            updated_at: time
          }
        end

        def each_label
          client.labels(project.import_source)
        end

        def object_type
          :label
        end
      end
    end
  end
end