Class: Gitlab::GithubImport::Importer::LabelsImporter

Inherits:
Object
  • Object
show all
Includes:
BulkImporting
Defined in:
lib/gitlab/github_import/importer/labels_importer.rb

Instance Attribute Summary

Attributes included from BulkImporting

#client, #project

Instance Method Summary collapse

Methods included from BulkImporting

#build_database_rows, #bulk_insert, #initialize

Instance Method Details

#already_imported?(label) ⇒ Boolean

Returns:

  • (Boolean)

24
25
26
# File 'lib/gitlab/github_import/importer/labels_importer.rb', line 24

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

#build(label) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gitlab/github_import/importer/labels_importer.rb', line 32

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

#build_labelsObject


20
21
22
# File 'lib/gitlab/github_import/importer/labels_importer.rb', line 20

def build_labels
  build_database_rows(each_label)
end

#build_labels_cacheObject


28
29
30
# File 'lib/gitlab/github_import/importer/labels_importer.rb', line 28

def build_labels_cache
  LabelFinder.new(project).build_cache
end

#each_labelObject


45
46
47
# File 'lib/gitlab/github_import/importer/labels_importer.rb', line 45

def each_label
  client.labels(project.import_source)
end

#executeObject

rubocop: enable CodeReuse/ActiveRecord


15
16
17
18
# File 'lib/gitlab/github_import/importer/labels_importer.rb', line 15

def execute
  bulk_insert(Label, build_labels)
  build_labels_cache
end

#existing_labelsObject

rubocop: disable CodeReuse/ActiveRecord


10
11
12
# File 'lib/gitlab/github_import/importer/labels_importer.rb', line 10

def existing_labels
  @existing_labels ||= project.labels.pluck(:title).to_set
end

#object_typeObject


49
50
51
# File 'lib/gitlab/github_import/importer/labels_importer.rb', line 49

def object_type
  :label
end