2020-03-13 08:09:22 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class JiraImportData < ProjectImportData
|
|
|
|
JiraProjectDetails = Struct.new(:key, :scheduled_at, :scheduled_by)
|
|
|
|
|
2020-03-18 08:09:13 -04:00
|
|
|
FORCE_IMPORT_KEY = 'force-import'
|
|
|
|
|
2020-03-13 08:09:22 -04:00
|
|
|
def projects
|
|
|
|
return [] unless data
|
|
|
|
|
2020-03-18 08:09:13 -04:00
|
|
|
projects = data.dig('jira', 'projects')&.map do |p|
|
2020-03-13 08:09:22 -04:00
|
|
|
JiraProjectDetails.new(p['key'], p['scheduled_at'], p['scheduled_by'])
|
|
|
|
end
|
2020-03-18 08:09:13 -04:00
|
|
|
|
|
|
|
projects&.sort_by { |jp| jp.scheduled_at } || []
|
2020-03-13 08:09:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def <<(project)
|
2020-03-18 08:09:13 -04:00
|
|
|
self.data ||= { 'jira' => { 'projects' => [] } }
|
|
|
|
self.data['jira'] ||= { 'projects' => [] }
|
|
|
|
self.data['jira']['projects'] = [] if data['jira']['projects'].blank? || !data['jira']['projects'].is_a?(Array)
|
|
|
|
|
|
|
|
self.data['jira']['projects'] << project.to_h
|
|
|
|
self.data.deep_stringify_keys!
|
|
|
|
end
|
|
|
|
|
|
|
|
def force_import!
|
|
|
|
self.data ||= {}
|
|
|
|
self.data.deep_merge!({ 'jira' => { FORCE_IMPORT_KEY => true } })
|
|
|
|
self.data.deep_stringify_keys!
|
|
|
|
end
|
|
|
|
|
|
|
|
def force_import?
|
|
|
|
!!data&.dig('jira', FORCE_IMPORT_KEY) && !projects.blank?
|
|
|
|
end
|
|
|
|
|
|
|
|
def finish_import!
|
|
|
|
return if data&.dig('jira', FORCE_IMPORT_KEY).nil?
|
|
|
|
|
|
|
|
data['jira'].delete(FORCE_IMPORT_KEY)
|
2020-03-13 08:09:22 -04:00
|
|
|
end
|
2020-03-26 08:07:48 -04:00
|
|
|
|
|
|
|
def current_project
|
|
|
|
projects.last
|
|
|
|
end
|
2020-03-13 08:09:22 -04:00
|
|
|
end
|