Commit 9a2f9220 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '299247-second-iteration-of-exporting-requirements' into 'master'

Modify requirements export CSV file columns

See merge request gitlab-org/gitlab!52118
parents cb4316d3 4948a15e
......@@ -260,7 +260,8 @@ For GitLab.com, it is set to 10 MB.
## Export requirements to a CSV file
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/290813) in GitLab 13.8.
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/290813) in GitLab 13.8.
> - Revised CSV column headers [introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/299247) in GitLab 13.9.
You can export GitLab requirements to a
[CSV file](https://en.wikipedia.org/wiki/Comma-separated_values) sent to your default notification
......@@ -285,11 +286,24 @@ You can preview the exported CSV file in a spreadsheet editor, such as Microsoft
OpenOffice Calc, or Google Sheets.
<!-- vale gitlab.Spelling = YES -->
The exported CSV file contains the following columns:
The exported CSV file contains the following headers:
- Requirement ID
- Title
- Description
- Author Username
- Latest Test Report State
- Latest Test Report Created At (UTC)
- In GitLab 13.8:
- Requirement ID
- Title
- Description
- Author Username
- Latest Test Report State
- Latest Test Report Created At (UTC)
- In GitLab 13.9 and later:
- Requirement ID
- Title
- Description
- Author
- Author Username
- Created At (UTC)
- State
- State Updated At (UTC)
......@@ -60,12 +60,16 @@ module RequirementsManagement
project
end
def latest_report
test_reports.last
end
def last_test_report_state
test_reports.last&.state
latest_report&.state
end
def last_test_report_manually_created?
test_reports.last&.build.nil?
latest_report&.build.nil?
end
end
end
......@@ -17,14 +17,12 @@ module RequirementsManagement
'Requirement ID' => 'iid',
'Title' => 'title',
'Description' => 'description',
'Author' => -> (requirement) { requirement.author&.name },
'Author Username' => -> (requirement) { requirement.author&.username },
'Latest Test Report State' => -> (requirement) { requirement.last_test_report_state&.capitalize },
'Latest Test Report Created At (UTC)' => -> (requirement) { latest_test_report_time(requirement) }
'Created At (UTC)' => -> (requirement) { requirement.created_at.utc },
'State' => -> (requirement) { requirement.last_test_report_state == 'passed' ? 'Satisfied' : '' },
'State Updated At (UTC)' => -> (requirement) { requirement.latest_report&.created_at&.utc }
}
end
def latest_test_report_time(requirement)
requirement.test_reports.last&.created_at
end
end
end
---
title: Modify herders in exported requirements CSV file
merge_request: 52118
author:
type: changed
......@@ -4,9 +4,9 @@ require 'spec_helper'
RSpec.describe RequirementsManagement::ExportCsvService do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :public, group: group) }
let_it_be(:requirement) { create(:requirement, state: :opened, project: project) }
let_it_be(:group) { create_default(:group) }
let_it_be(:project) { create_default(:project, :public) }
let_it_be_with_reload(:requirement) { create(:requirement, state: :opened, author: user) }
subject { described_class.new(RequirementsManagement::Requirement.all, project) }
......@@ -37,18 +37,8 @@ RSpec.describe RequirementsManagement::ExportCsvService do
end
context 'includes' do
before do
create(
:test_report, requirement: requirement,
state: :failed, build: nil,
created_at: DateTime.new(2015, 4, 2, 2, 1, 0)
)
create(
:test_report, requirement: requirement,
state: :passed, build: nil,
created_at: DateTime.new(2015, 4, 3, 2, 1, 0)
)
end
let_it_be(:report) { create(:test_report, requirement: requirement, state: :failed, build: nil, author: user) }
let(:time_format) { '%Y-%m-%d %H:%M:%S %Z' }
it 'includes the columns required for import' do
expect(csv.headers).to include('Title', 'Description')
......@@ -66,16 +56,44 @@ RSpec.describe RequirementsManagement::ExportCsvService do
expect(csv[0]['Description']).to eq requirement.description
end
specify 'author' do
expect(csv[0]['Author']).to eq requirement.author.name
end
specify 'author username' do
expect(csv[0]['Author Username']).to eq requirement.author.username
end
specify 'latest test report state' do
expect(csv[0]['Latest Test Report State']).to eq "Passed"
specify 'created date' do
expect(csv[0]['Created At (UTC)']).to eq requirement.created_at.utc.strftime(time_format)
end
specify 'latest test report created at' do
expect(csv[0]['Latest Test Report Created At (UTC)']).to eq '2015-04-03 02:01:00 UTC'
context 'when last test report failed' do
before do
report.update!(state: :failed)
end
specify 'latest test report state' do
expect(csv[0]['State']).to eq ''
end
specify 'latest test report created at' do
expect(csv[0]['State Updated At (UTC)']).to eq report.created_at.utc.strftime(time_format)
end
end
context 'when last test report passed' do
before do
report.update!(state: :passed)
end
specify 'latest test report state' do
expect(csv[0]['State']).to eq 'Satisfied'
end
specify 'latest test report created at' do
expect(csv[0]['State Updated At (UTC)']).to eq report.created_at.utc.strftime(time_format)
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