Commit f7851baf authored by Jan Provaznik's avatar Jan Provaznik

Remove pipeline reference

Requirement test reports are associated with CI builds directly,
there is no need to associate them with pipelines too.
parent d594d490
......@@ -7,6 +7,9 @@ module RequirementsManagement
include AtomicInternalId
include Sortable
include Gitlab::SQL::Pattern
include IgnorableColumns
ignore_column :pipeline_id, remove_with: '13.4', remove_after: '2020-08-22'
# the expected name for this table is `requirements_management_requirements`,
# but to avoid downtime and deployment issues `requirements` is still used
......
......@@ -7,11 +7,9 @@ module RequirementsManagement
belongs_to :requirement, inverse_of: :test_reports
belongs_to :author, inverse_of: :test_reports, class_name: 'User'
belongs_to :pipeline, class_name: 'Ci::Pipeline'
belongs_to :build, class_name: 'Ci::Build'
validates :requirement, :state, presence: true
validate :validate_pipeline_reference
enum state: { passed: 1, failed: 2 }
......@@ -58,9 +56,6 @@ module RequirementsManagement
def build_report(state:, requirement:, build:, timestamp:)
new(
requirement_id: requirement.id,
# pipeline_reference will be removed:
# https://gitlab.com/gitlab-org/gitlab/-/issues/219999
pipeline_id: build.pipeline_id,
build_id: build.id,
author_id: build.user_id,
created_at: timestamp,
......@@ -68,13 +63,5 @@ module RequirementsManagement
)
end
end
private
def validate_pipeline_reference
if pipeline_id != build&.pipeline_id
errors.add(:build, _('build pipeline reference mismatch'))
end
end
end
end
......@@ -5,9 +5,6 @@ FactoryBot.define do
author
requirement
build factory: :ci_build
after(:build) do |report|
report.pipeline = report.build&.pipeline
end
state { :passed }
end
end
......@@ -8,7 +8,6 @@ RSpec.describe RequirementsManagement::TestReport do
it { is_expected.to belong_to(:author).class_name('User') }
it { is_expected.to belong_to(:requirement) }
it { is_expected.to belong_to(:pipeline) }
it { is_expected.to belong_to(:build) }
end
......@@ -17,23 +16,6 @@ RSpec.describe RequirementsManagement::TestReport do
it { is_expected.to validate_presence_of(:requirement) }
it { is_expected.to validate_presence_of(:state) }
describe 'pipeline reference' do
it { is_expected.to be_valid }
it 'is valid to if both build and pipeline are nil' do
subject.build = nil
subject.pipeline_id = nil
expect(subject).to be_valid
end
it 'is invalid if build references a different pipeline' do
subject.pipeline_id = nil
expect(subject).to be_invalid
end
end
end
describe 'scopes' do
......@@ -82,7 +64,7 @@ RSpec.describe RequirementsManagement::TestReport do
expect { subject }.to change { RequirementsManagement::TestReport.count }.by(2)
reports = RequirementsManagement::TestReport.where(pipeline: build.pipeline)
reports = RequirementsManagement::TestReport.where(build: build)
expect(reports).to match_array([
have_attributes(requirement: requirement1,
author: build.user,
......
......@@ -26746,9 +26746,6 @@ msgstr ""
msgid "branch name"
msgstr ""
msgid "build pipeline reference mismatch"
msgstr ""
msgid "by"
msgstr ""
......
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