Commit 786805c9 authored by charlieablett's avatar charlieablett

Apply reviewer feedback

- Use requirement iids as keys
- Improve method namings
- Update docs
parent 6405b943
......@@ -76,7 +76,7 @@ As soon as a requirement is reopened, it no longer appears in the **Archived** t
## Search for a requirement from the requirements list page
> - Introduced in [GitLab Ultimate](https://about.gitlab.com/pricing/) 13.1.
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/212543) in [GitLab Ultimate](https://about.gitlab.com/pricing/) 13.1.
You can search for a requirement from the list of requirements using filtered search bar (similar to
that of Issues and Merge Requests) based on following parameters:
......@@ -96,7 +96,8 @@ You can also sort requirements list by:
## Allow requirements to be satisfied from a CI job
> [Introduced](https://gitlab.com/groups/gitlab-org/-/epics/2859) in [GitLab Ultimate](https://about.gitlab.com/pricing/) 13.1.
> - [Introduced](https://gitlab.com/groups/gitlab-org/-/epics/2859) in [GitLab Ultimate](https://about.gitlab.com/pricing/) 13.1.
> - [Added](https://gitlab.com/gitlab-org/gitlab/-/issues/215514) ability to specify individual requirements and their statuses in [GitLab Ultimate](https://about.gitlab.com/pricing/) 13.2.
GitLab supports [requirements test
reports](../../../ci/pipelines/job_artifacts.md#artifactsreportsrequirements-ultimate) now.
......@@ -132,6 +133,32 @@ the requirement report is checked for the "all passed" record
(`{"*":"passed"}`), and on success, it marks all existing open requirements as
Satisfied.
#### Specifying individual requirements
It is possible to specify individual requirements and their statuses.
If the following requirements exist:
- `REQ-1` (with IID `1`)
- `REQ-2` (with IID `2`)
- `REQ-3` (with IID `3`)
It is possible to specify that the first requirement passed, and the second failed.
Valid values are "passed" and "failed".
By omitting a requirement IID (in this case `REQ-3`'s IID `3`), no result is noted.
```yaml
requirements_confirmation:
when: manual
allow_failure: false
script:
- mkdir tmp
- echo "{\"1\":\"passed\", \"2\":\"failed\"}" > tmp/requirements.json
artifacts:
reports:
requirements: tmp/requirements.json
```
### Add the manual job to CI conditionally
To configure your CI to include the manual job only when there are some open
......
......@@ -21,16 +21,18 @@ module RequirementsManagement
def persist_requirement_reports(build, ci_report)
timestamp = Time.current
if ci_report.all_passed?
bulk_insert!(persist_all_requirement_reports_as_passed(build, timestamp))
else
bulk_insert!(persist_individual_reports(build, ci_report, timestamp))
end
reports = if ci_report.all_passed?
passed_reports_for_all_requirements(build, timestamp)
else
individual_reports(build, ci_report, timestamp)
end
bulk_insert!(reports)
end
private
def persist_all_requirement_reports_as_passed(build, timestamp)
def passed_reports_for_all_requirements(build, timestamp)
[].tap do |reports|
build.project.requirements.opened.select(:id).find_each do |requirement|
reports << build_report(state: :passed, requirement: requirement, build: build, timestamp: timestamp)
......@@ -38,7 +40,7 @@ module RequirementsManagement
end
end
def persist_individual_reports(build, ci_report, timestamp)
def individual_reports(build, ci_report, timestamp)
[].tap do |reports|
iids = ci_report.requirements.keys
break [] if iids.empty?
......@@ -67,6 +69,8 @@ module RequirementsManagement
end
end
private
def validate_pipeline_reference
if pipeline_id != build&.pipeline_id
errors.add(:build, _('build pipeline reference mismatch'))
......
......@@ -12,7 +12,7 @@ module Gitlab
end
def add_requirement(key, value)
@requirements[key.remove('requirement_iid')] = value
@requirements[key] = value
end
def all_passed?
......
{
"requirement_iid1": "passed",
"requirement_iid2": "failed",
"requirement_iid3": "passed"
"1": "passed",
"2": "failed",
"3": "passed"
}
......@@ -68,9 +68,9 @@ RSpec.describe RequirementsManagement::TestReport do
context 'and the entries are valid' do
let(:ci_report) do
Gitlab::Ci::Reports::RequirementsManagement::Report.new.tap do |report|
report.add_requirement('requirement_iid1', 'passed')
report.add_requirement('requirement_iid2', 'failed')
report.add_requirement('requirement_iid3', 'passed')
report.add_requirement('1', 'passed')
report.add_requirement('2', 'failed')
report.add_requirement('3', 'passed')
end
end
......@@ -84,13 +84,13 @@ RSpec.describe RequirementsManagement::TestReport do
reports = RequirementsManagement::TestReport.where(pipeline: build.pipeline)
expect(reports).to match_array([
have_attributes(
requirement: requirement1,
author: build.user,
state: 'passed'),
have_attributes(requirement: requirement1,
author: build.user,
state: 'passed'),
have_attributes(requirement: requirement2,
author: build.user,
state: 'failed')
author: build.user,
state: 'failed')
])
end
end
......@@ -98,9 +98,9 @@ RSpec.describe RequirementsManagement::TestReport do
context 'and the entries are not valid' do
let(:ci_report) do
Gitlab::Ci::Reports::RequirementsManagement::Report.new.tap do |report|
report.add_requirement('requirement_iid0', 'passed')
report.add_requirement('requirement_iid1', 'nonsense')
report.add_requirement('requirement_iid2', nil)
report.add_requirement('0', 'passed')
report.add_requirement('1', 'nonsense')
report.add_requirement('2', nil)
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