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 collapse

Instance Method Summary collapse

Methods included from BulkImporting

#build_database_rows, #bulk_insert

Constructor Details

#initialize(project, client) ⇒ LabelsImporter

project - An instance of `Project`. client - An instance of `Gitlab::GithubImport::Client`. rubocop: disable CodeReuse/ActiveRecord


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

def initialize(project, client)
  @project = project
  @client = client
  @existing_labels = project.labels.pluck(:title).to_set
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client


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

def client
  @client
end

#existing_labelsObject (readonly)

Returns the value of attribute existing_labels


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

def existing_labels
  @existing_labels
end

#projectObject (readonly)

Returns the value of attribute project


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

def project
  @project
end

Instance Method Details

#already_imported?(label) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#build(label) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gitlab/github_import/importer/labels_importer.rb', line 38

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


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

def build_labels
  build_database_rows(each_label)
end

#build_labels_cacheObject


34
35
36
# File 'lib/gitlab/github_import/importer/labels_importer.rb', line 34

def build_labels_cache
  LabelFinder.new(project).build_cache
end

#each_labelObject


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

def each_label
  client.labels(project.import_source)
end

#executeObject

rubocop: enable CodeReuse/ActiveRecord


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

def execute
  bulk_insert(Label, build_labels)
  build_labels_cache
end