2020-04-22 19:07:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Issues
|
2023-04-23 21:23:45 +05:30
|
|
|
class ExportCsvService < ExportCsv::BaseService
|
2020-04-22 19:07:51 +05:30
|
|
|
include Gitlab::Routing.url_helpers
|
|
|
|
include GitlabRoutingHelper
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
def initialize(relation, resource_parent, user = nil)
|
|
|
|
super(relation, resource_parent)
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
@labels = objects.labels_hash.transform_values { |labels| labels.sort.join(',').presence }
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
def email(mail_to_user)
|
2023-04-23 21:23:45 +05:30
|
|
|
Notify.issues_csv_email(mail_to_user, resource_parent, csv_data, csv_builder.status).deliver_now
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def associations_to_preload
|
2023-07-09 08:55:56 +05:30
|
|
|
[:work_item_type, :author, :assignees, :timelogs, :milestone, { project: { namespace: :route } }]
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def header_to_value_hash
|
|
|
|
{
|
2022-05-07 20:08:51 +05:30
|
|
|
'Title' => 'title',
|
|
|
|
'Description' => 'description',
|
2022-08-27 11:52:29 +05:30
|
|
|
'Issue ID' => 'iid',
|
|
|
|
'URL' => -> (issue) { issue_url(issue) },
|
|
|
|
'State' => -> (issue) { issue.closed? ? 'Closed' : 'Open' },
|
|
|
|
'Author' => 'author_name',
|
|
|
|
'Author Username' => -> (issue) { issue.author&.username },
|
|
|
|
'Assignee' => -> (issue) { issue.assignees.map(&:name).join(', ') },
|
|
|
|
'Assignee Username' => -> (issue) { issue.assignees.map(&:username).join(', ') },
|
|
|
|
'Confidential' => -> (issue) { issue.confidential? ? 'Yes' : 'No' },
|
|
|
|
'Locked' => -> (issue) { issue.discussion_locked? ? 'Yes' : 'No' },
|
|
|
|
'Due Date' => -> (issue) { issue.due_date&.to_s(:csv) },
|
|
|
|
'Created At (UTC)' => -> (issue) { issue.created_at&.to_s(:csv) },
|
|
|
|
'Updated At (UTC)' => -> (issue) { issue.updated_at&.to_s(:csv) },
|
|
|
|
'Closed At (UTC)' => -> (issue) { issue.closed_at&.to_s(:csv) },
|
|
|
|
'Milestone' => -> (issue) { issue.milestone&.title },
|
|
|
|
'Weight' => -> (issue) { issue.weight },
|
|
|
|
'Labels' => -> (issue) { issue_labels(issue) },
|
|
|
|
'Time Estimate' => ->(issue) { issue.time_estimate.to_s(:csv) },
|
|
|
|
'Time Spent' => -> (issue) { issue_time_spent(issue) }
|
2020-04-22 19:07:51 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def issue_labels(issue)
|
2021-03-11 19:13:27 +05:30
|
|
|
@labels[issue.id]
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def issue_time_spent(issue)
|
2022-05-07 20:08:51 +05:30
|
|
|
issue.timelogs.sum(&:time_spent)
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2023-04-23 21:23:45 +05:30
|
|
|
|
|
|
|
def preload_associations_in_batches?
|
|
|
|
Feature.enabled?(:export_csv_preload_in_batches, resource_parent)
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Issues::ExportCsvService.prepend_mod_with('Issues::ExportCsvService')
|