Commit b93bd460 authored by Jarka Košanová's avatar Jarka Košanová

Add information about epic to the csv export

- only include when the epics feature is available
parent 07dadce8
......@@ -69,6 +69,8 @@ Data will be encoded with a comma as the column delimiter, with `"` used to quot
| Labels | Title of any labels joined with a `,` |
| Time Estimate | [Time estimate](../time_tracking.md#estimates) in seconds |
| Time Spent | [Time spent](../time_tracking.md#time-spent) in seconds |
| Epic ID | Id of the parent epic **(ULTIMATE)**, introduced in 12.7 |
| Epic Title | Title of the parent epic **(ULTIMATE)**, introduced in 12.7 |
## Limitations
......
......@@ -8,23 +8,26 @@ module Issues
# Target attachment size before base64 encoding
TARGET_FILESIZE = 15000000
def initialize(issues_relation)
attr_reader :project
def initialize(issues_relation, project)
@issues = issues_relation
@labels = @issues.labels_hash
@project = project
end
def csv_data
csv_builder.render(TARGET_FILESIZE)
end
def email(user, project)
def email(user)
Notify.issues_csv_email(user, project, csv_data, csv_builder.status).deliver_now
end
# rubocop: disable CodeReuse/ActiveRecord
def csv_builder
@csv_builder ||=
CsvBuilder.new(@issues.preload(:author, :assignees, :timelogs), header_to_value_hash)
CsvBuilder.new(@issues.preload(:author, :assignees, :timelogs, :epic), header_to_value_hash)
end
# rubocop: enable CodeReuse/ActiveRecord
......@@ -49,10 +52,25 @@ module Issues
'Closed At (UTC)' => -> (issue) { issue.closed_at&.to_s(:csv) },
'Milestone' => -> (issue) { issue.milestone&.title },
'Weight' => -> (issue) { issue.weight },
'Labels' => -> (issue) { @labels[issue.id].sort.join(',').presence },
'Labels' => -> (issue) { issue_labels(issue) },
'Time Estimate' => ->(issue) { issue.time_estimate.to_s(:csv) },
'Time Spent' => -> (issue) { issue.timelogs.map(&:time_spent).inject(0, :+)}
}
'Time Spent' => -> (issue) { issue_time_spent(issue) }
}.tap do |hash|
if project.group&.feature_available?(:epics)
hash['Epic ID'] = -> (issue) { issue.epic&.id }
hash['Epic Title'] = -> (issue) { issue.epic&.title }
end
end
end
def issue_labels(issue)
@labels[issue.id].sort.join(',').presence
end
# rubocop: disable CodeReuse/ActiveRecord
def issue_time_spent(issue)
issue.timelogs.map(&:time_spent).sum
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -16,6 +16,6 @@ class ExportCsvWorker
issues = IssuesFinder.new(@current_user, params).execute
Issues::ExportCsvService.new(issues).email(@current_user, @project)
Issues::ExportCsvService.new(issues, @project).email(@current_user)
end
end
---
title: Add information about epic to Issue list csv export
merge_request: 22662
author:
type: added
......@@ -3,11 +3,12 @@
require 'spec_helper'
describe Issues::ExportCsvService do
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let!(:issue) { create(:issue, project: project, author: user) }
let_it_be(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, :public, group: group) }
let!(:issue) { create(:issue, project: project, author: user) }
let!(:bad_issue) { create(:issue, project: project, author: user) }
let(:subject) { described_class.new(Issue.all) }
let(:subject) { described_class.new(Issue.all, project) }
it 'renders csv to string' do
expect(subject.csv_data).to be_a String
......@@ -15,13 +16,13 @@ describe Issues::ExportCsvService do
describe '#email' do
it 'emails csv' do
expect { subject.email(user, project) }.to change(ActionMailer::Base.deliveries, :count)
expect { subject.email(user) }.to change(ActionMailer::Base.deliveries, :count)
end
it 'renders with a target filesize' do
expect(subject.csv_builder).to receive(:render).with(described_class::TARGET_FILESIZE)
subject.email(user, project)
subject.email(user)
end
end
......@@ -142,12 +143,42 @@ describe Issues::ExportCsvService do
expect(csv[1]['Time Spent']).to eq '0'
end
context 'handling epics' do
let(:epic) { create(:epic, group: group) }
before do
create(:epic_issue, issue: issue, epic: epic)
end
context 'with epics disabled' do
it 'does not include epics information' do
expect(csv[0]).not_to have_key('Epic ID')
end
end
context 'with epics enabled' do
before do
stub_licensed_features(epics: true)
end
specify 'epic ID' do
expect(csv[0]['Epic ID']).to eq(epic.id.to_s)
expect(csv[1]['Epic ID']).to be_nil
end
specify 'epic Title' do
expect(csv[0]['Epic Title']).to eq(epic.title)
expect(csv[1]['Epic Title']).to be_nil
end
end
end
context 'with issues filtered by labels and project' do
let(:subject) do
described_class.new(
IssuesFinder.new(user,
project_id: project.id,
label_name: %w(Idea Feature)).execute)
label_name: %w(Idea Feature)).execute, project)
end
it 'returns only filtered objects' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment