2017-10-13 16:50:36 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module GithubImport
|
|
|
|
module Importer
|
|
|
|
class MilestonesImporter
|
|
|
|
include BulkImporting
|
|
|
|
|
|
|
|
attr_reader :project, :client, :existing_milestones
|
|
|
|
|
|
|
|
# project - An instance of `Project`
|
|
|
|
# client - An instance of `Gitlab::GithubImport::Client`
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-10-13 16:50:36 +00:00
|
|
|
def initialize(project, client)
|
|
|
|
@project = project
|
|
|
|
@client = client
|
|
|
|
@existing_milestones = project.milestones.pluck(:iid).to_set
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-10-13 16:50:36 +00:00
|
|
|
|
|
|
|
def execute
|
2019-01-02 15:05:40 +00:00
|
|
|
bulk_insert(Milestone, build_milestones)
|
2017-10-13 16:50:36 +00:00
|
|
|
build_milestones_cache
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_milestones
|
|
|
|
build_database_rows(each_milestone)
|
|
|
|
end
|
|
|
|
|
|
|
|
def already_imported?(milestone)
|
|
|
|
existing_milestones.include?(milestone.number)
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_milestones_cache
|
|
|
|
MilestoneFinder.new(project).build_cache
|
|
|
|
end
|
|
|
|
|
|
|
|
def build(milestone)
|
|
|
|
{
|
|
|
|
iid: milestone.number,
|
|
|
|
title: milestone.title,
|
|
|
|
description: milestone.description,
|
|
|
|
project_id: project.id,
|
|
|
|
state: state_for(milestone),
|
2019-02-26 20:04:12 +00:00
|
|
|
due_date: milestone.due_on&.to_date,
|
2017-10-13 16:50:36 +00:00
|
|
|
created_at: milestone.created_at,
|
|
|
|
updated_at: milestone.updated_at
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def state_for(milestone)
|
|
|
|
milestone.state == 'open' ? :active : :closed
|
|
|
|
end
|
|
|
|
|
|
|
|
def each_milestone
|
|
|
|
client.milestones(project.import_source, state: 'all')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|