Commit e4424496 authored by Sean McGivern's avatar Sean McGivern

Merge branch '1406-new-export-fields' into 'master'

Resolve "Export issue time tracking information"

Closes #1406

See merge request !2627
parents fa09edcf dd198bcb
...@@ -21,7 +21,7 @@ module Issues ...@@ -21,7 +21,7 @@ module Issues
def csv_builder def csv_builder
@csv_builder ||= @csv_builder ||=
CsvBuilder.new(@issues.includes(:author, :assignees), header_to_value_hash) CsvBuilder.new(@issues.includes(:author, :assignees, :timelogs), header_to_value_hash)
end end
private private
...@@ -43,7 +43,9 @@ module Issues ...@@ -43,7 +43,9 @@ module Issues
'Updated At (UTC)' => -> (issue) { issue.updated_at&.to_s(:csv) }, 'Updated At (UTC)' => -> (issue) { issue.updated_at&.to_s(:csv) },
'Closed At (UTC)' => -> (issue) { issue.closed_at&.to_s(:csv) }, 'Closed At (UTC)' => -> (issue) { issue.closed_at&.to_s(:csv) },
'Milestone' => -> (issue) { issue.milestone&.title }, 'Milestone' => -> (issue) { issue.milestone&.title },
'Labels' => -> (issue) { @labels[issue.id].sort.join(',').presence } 'Labels' => -> (issue) { @labels[issue.id].sort.join(',').presence },
'Time Estimate' => ->(issue) { issue.time_estimate.to_s(:csv) },
'Time Spent' => -> (issue) { issue.timelogs.map(&:time_spent).inject(0, :+)}
} }
end end
end end
......
---
title: Add Time estimate and Time spend fields in csv export
merge_request: 2627
author: g3dinua, LockiStrike
type: changed
...@@ -4,6 +4,7 @@ describe Issues::ExportCsvService do ...@@ -4,6 +4,7 @@ describe Issues::ExportCsvService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
let!(:issue) { create(:issue, project: project, author: user) } 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) }
it 'renders csv to string' do it 'renders csv to string' do
...@@ -40,7 +41,10 @@ describe Issues::ExportCsvService do ...@@ -40,7 +41,10 @@ describe Issues::ExportCsvService do
created_at: DateTime.new(2015, 4, 3, 2, 1, 0), created_at: DateTime.new(2015, 4, 3, 2, 1, 0),
updated_at: DateTime.new(2016, 5, 4, 3, 2, 1), updated_at: DateTime.new(2016, 5, 4, 3, 2, 1),
closed_at: DateTime.new(2017, 6, 5, 4, 3, 2), closed_at: DateTime.new(2017, 6, 5, 4, 3, 2),
labels: [feature_label, idea_label]) labels: [feature_label, idea_label],
time_estimate: 72000)
issue.timelogs.create(time_spent: 360, user: user)
issue.timelogs.create(time_spent: 200, user: user)
end end
specify 'iid' do specify 'iid' do
...@@ -61,6 +65,7 @@ describe Issues::ExportCsvService do ...@@ -61,6 +65,7 @@ describe Issues::ExportCsvService do
specify 'description' do specify 'description' do
expect(csv[0]['Description']).to eq issue.description expect(csv[0]['Description']).to eq issue.description
expect(csv[1]['Description']).to eq nil
end end
specify 'author name' do specify 'author name' do
...@@ -73,10 +78,12 @@ describe Issues::ExportCsvService do ...@@ -73,10 +78,12 @@ describe Issues::ExportCsvService do
specify 'assignee name' do specify 'assignee name' do
expect(csv[0]['Assignee']).to eq user.name expect(csv[0]['Assignee']).to eq user.name
expect(csv[1]['Assignee']).to eq ''
end end
specify 'assignee username' do specify 'assignee username' do
expect(csv[0]['Assignee Username']).to eq user.username expect(csv[0]['Assignee Username']).to eq user.username
expect(csv[1]['Assignee Username']).to eq ''
end end
specify 'confidential' do specify 'confidential' do
...@@ -85,14 +92,17 @@ describe Issues::ExportCsvService do ...@@ -85,14 +92,17 @@ describe Issues::ExportCsvService do
specify 'milestone' do specify 'milestone' do
expect(csv[0]['Milestone']).to eq issue.milestone.title expect(csv[0]['Milestone']).to eq issue.milestone.title
expect(csv[1]['Milestone']).to eq nil
end end
specify 'labels' do specify 'labels' do
expect(csv[0]['Labels']).to eq 'Feature,Idea' expect(csv[0]['Labels']).to eq 'Feature,Idea'
expect(csv[1]['Labels']).to eq nil
end end
specify 'due_date' do specify 'due_date' do
expect(csv[0]['Due Date']).to eq '2014-03-02' expect(csv[0]['Due Date']).to eq '2014-03-02'
expect(csv[1]['Due Date']).to eq nil
end end
specify 'created_at' do specify 'created_at' do
...@@ -105,6 +115,17 @@ describe Issues::ExportCsvService do ...@@ -105,6 +115,17 @@ describe Issues::ExportCsvService do
specify 'closed_at' do specify 'closed_at' do
expect(csv[0]['Closed At (UTC)']).to eq '2017-06-05 04:03:02' expect(csv[0]['Closed At (UTC)']).to eq '2017-06-05 04:03:02'
expect(csv[1]['Closed At (UTC)']).to eq nil
end
specify 'time estimate' do
expect(csv[0]['Time Estimate']).to eq '72000'
expect(csv[1]['Time Estimate']).to eq '0'
end
specify 'time spent' do
expect(csv[0]['Time Spent']).to eq '560'
expect(csv[1]['Time Spent']).to eq '0'
end end
end end
......
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