2020-04-21 11:21:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Issues
|
2021-01-11 04:10:46 -05:00
|
|
|
class ExportCsvService < Issuable::ExportCsv::BaseService
|
2020-04-21 11:21:10 -04:00
|
|
|
include Gitlab::Routing.url_helpers
|
|
|
|
include GitlabRoutingHelper
|
|
|
|
|
2021-02-18 07:09:34 -05:00
|
|
|
def initialize(issuables_relation, project)
|
|
|
|
super
|
|
|
|
|
|
|
|
@labels = @issuables.labels_hash.transform_values { |labels| labels.sort.join(',').presence }
|
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
def email(user)
|
|
|
|
Notify.issues_csv_email(user, project, csv_data, csv_builder.status).deliver_now
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def associations_to_preload
|
2021-02-18 07:09:34 -05:00
|
|
|
%i(author assignees timelogs milestone project)
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def header_to_value_hash
|
|
|
|
{
|
2022-03-08 07:20:17 -05:00
|
|
|
'Title' => 'title',
|
|
|
|
'Description' => 'description',
|
2020-04-21 11:21:10 -04:00
|
|
|
'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) }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def issue_labels(issue)
|
2021-02-18 07:09:34 -05:00
|
|
|
@labels[issue.id]
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def issue_time_spent(issue)
|
2022-02-24 07:12:57 -05:00
|
|
|
issue.timelogs.sum(&:time_spent)
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Issues::ExportCsvService.prepend_mod_with('Issues::ExportCsvService')
|