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 collapse

Instance Method Summary collapse

Methods included from BulkImporting

#build_database_rows, #bulk_insert

Constructor Details

#initialize(project, client) ⇒ MilestonesImporter

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/milestones_importer.rb', line 14

def initialize(project, client)
  @project = project
  @client = client
  @existing_milestones = project.milestones.pluck(:iid).to_set
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client


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

def client
  @client
end

#existing_milestonesObject (readonly)

Returns the value of attribute existing_milestones


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

def existing_milestones
  @existing_milestones
end

#projectObject (readonly)

Returns the value of attribute project


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

def project
  @project
end

Instance Method Details

#already_imported?(milestone) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#build(milestone) ⇒ Object


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

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


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

def build_milestones
  build_database_rows(each_milestone)
end

#build_milestones_cacheObject


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

def build_milestones_cache
  MilestoneFinder.new(project).build_cache
end

#each_milestoneObject


55
56
57
# File 'lib/gitlab/github_import/importer/milestones_importer.rb', line 55

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

#executeObject

rubocop: enable CodeReuse/ActiveRecord


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

def execute
  bulk_insert(Milestone, build_milestones)
  build_milestones_cache
end

#state_for(milestone) ⇒ Object


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

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