Class: Gitlab::GithubImport::Importer::LabelLinksImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/github_import/importer/label_links_importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(issue, project, client) ⇒ LabelLinksImporter

issue - An instance of `Gitlab::GithubImport::Representation::Issue` project - An instance of `Project` client - An instance of `Gitlab::GithubImport::Client`


12
13
14
15
16
17
# File 'lib/gitlab/github_import/importer/label_links_importer.rb', line 12

def initialize(issue, project, client)
  @issue = issue
  @project = project
  @client = client
  @label_finder = LabelFinder.new(project)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client


7
8
9
# File 'lib/gitlab/github_import/importer/label_links_importer.rb', line 7

def client
  @client
end

#issueObject (readonly)

Returns the value of attribute issue


7
8
9
# File 'lib/gitlab/github_import/importer/label_links_importer.rb', line 7

def issue
  @issue
end

#label_finderObject (readonly)

Returns the value of attribute label_finder


7
8
9
# File 'lib/gitlab/github_import/importer/label_links_importer.rb', line 7

def label_finder
  @label_finder
end

#projectObject (readonly)

Returns the value of attribute project


7
8
9
# File 'lib/gitlab/github_import/importer/label_links_importer.rb', line 7

def project
  @project
end

Instance Method Details

#create_labelsObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gitlab/github_import/importer/label_links_importer.rb', line 23

def create_labels
  time = Time.zone.now
  rows = []
  target_id = find_target_id

  issue.label_names.each do |label_name|
    # Although unlikely it's technically possible for an issue to be
    # given a label that was created and assigned after we imported all
    # the project's labels.
    next unless (label_id = label_finder.id_for(label_name))

    rows << {
      label_id: label_id,
      target_id: target_id,
      target_type: issue.issuable_type,
      created_at: time,
      updated_at: time
    }
  end

  Gitlab::Database.bulk_insert(LabelLink.table_name, rows) # rubocop:disable Gitlab/BulkInsert
end

#executeObject


19
20
21
# File 'lib/gitlab/github_import/importer/label_links_importer.rb', line 19

def execute
  create_labels
end

#find_target_idObject


46
47
48
# File 'lib/gitlab/github_import/importer/label_links_importer.rb', line 46

def find_target_id
  GithubImport::IssuableFinder.new(project, issue).database_id
end