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, #bulk_insert_failures, #initialize

Instance Method Details

#already_imported?(label) ⇒ Boolean

Returns:

  • (Boolean)


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

def already_imported?(label)
  existing_labels.include?(label[:name])
end

#build_attributes(label) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gitlab/github_import/importer/labels_importer.rb', line 35

def build_attributes(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



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

def build_labels
  build_database_rows(each_label)
end

#build_labels_cacheObject



31
32
33
# File 'lib/gitlab/github_import/importer/labels_importer.rb', line 31

def build_labels_cache
  LabelFinder.new(project).build_cache
end

#each_labelObject



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

def each_label
  client.labels(project.import_source)
end

#executeObject

rubocop: enable CodeReuse/ActiveRecord



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

def execute
  rows, validation_errors = build_labels

  bulk_insert(rows)
  bulk_insert_failures(validation_errors) if validation_errors.any?
  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



52
53
54
# File 'lib/gitlab/github_import/importer/labels_importer.rb', line 52

def object_type
  :label
end