Class: Gitlab::GithubImport::Importer::MilestonesImporter

Inherits:
Object
  • Object
show all
Includes:
BulkImporting
Defined in:
lib/gitlab/github_import/importer/milestones_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?(milestone) ⇒ Boolean

Returns:

  • (Boolean)

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

def already_imported?(milestone)
  existing_milestones.include?(milestone.number)
end

#build(milestone) ⇒ Object


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

def build(milestone)
  {
    iid: milestone.number,
    title: milestone.title,
    description: milestone.description,
    project_id: project.id,
    state: state_for(milestone),
    due_date: milestone.due_on&.to_date,
    created_at: milestone.created_at,
    updated_at: milestone.updated_at
  }
end

#build_milestonesObject


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

def build_milestones
  build_database_rows(each_milestone)
end

#build_milestones_cacheObject


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

def build_milestones_cache
  MilestoneFinder.new(project).build_cache
end

#each_milestoneObject


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

def each_milestone
  client.milestones(project.import_source, state: 'all')
end

#executeObject

rubocop: enable CodeReuse/ActiveRecord


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

def execute
  bulk_insert(Milestone, build_milestones)
  build_milestones_cache
end

#existing_milestonesObject

rubocop: disable CodeReuse/ActiveRecord


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

def existing_milestones
  @existing_milestones ||= project.milestones.pluck(:iid).to_set
end

#object_typeObject


53
54
55
# File 'lib/gitlab/github_import/importer/milestones_importer.rb', line 53

def object_type
  :milestone
end

#state_for(milestone) ⇒ Object


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

def state_for(milestone)
  milestone.state == 'open' ? :active : :closed
end