Commit 764100e1 authored by Jan Provaznik's avatar Jan Provaznik

Use only 'blocks' relation

For any newly created issue relations, `blocked_by` is replaced with
`blocks` and source/target is swapped.
parent 64239221
...@@ -14,8 +14,17 @@ module EE ...@@ -14,8 +14,17 @@ module EE
private private
def set_link_type(link) def set_link_type(link)
if params[:link_type].present? return unless params[:link_type].present?
link.link_type = params[:link_type]
link.link_type = params[:link_type]
# `blocked_by` links are treated as `blocks` links where
# source and target is swapped. This is the first step toward
# removing `blocked_by` link type
# https://gitlab.com/gitlab-org/gitlab/-/issues/225919
if link.is_blocked_by?
link.source, link.target = link.target, link.source
link.link_type = ::IssueLink::TYPE_BLOCKS
end end
end end
......
...@@ -29,7 +29,7 @@ RSpec.describe IssueLinks::CreateService do ...@@ -29,7 +29,7 @@ RSpec.describe IssueLinks::CreateService do
let(:another_project_issue_ref) { another_project_issue.to_reference(project) } let(:another_project_issue_ref) { another_project_issue.to_reference(project) }
let(:params) do let(:params) do
{ issuable_references: [issue_a_ref, another_project_issue_ref], link_type: 'is_blocked_by' } { issuable_references: [issue_a_ref, another_project_issue_ref], link_type: 'blocks' }
end end
before do before do
...@@ -53,13 +53,25 @@ RSpec.describe IssueLinks::CreateService do ...@@ -53,13 +53,25 @@ RSpec.describe IssueLinks::CreateService do
it 'creates relationships' do it 'creates relationships' do
expect { subject }.to change(IssueLink, :count).from(0).to(2) expect { subject }.to change(IssueLink, :count).from(0).to(2)
expect(IssueLink.find_by!(target: issue_a)).to have_attributes(source: issue, link_type: 'is_blocked_by') expect(IssueLink.find_by!(target: issue_a)).to have_attributes(source: issue, link_type: 'blocks')
expect(IssueLink.find_by!(target: another_project_issue)).to have_attributes(source: issue, link_type: 'is_blocked_by') expect(IssueLink.find_by!(target: another_project_issue)).to have_attributes(source: issue, link_type: 'blocks')
end end
it 'returns success status' do it 'returns success status' do
is_expected.to eq(status: :success) is_expected.to eq(status: :success)
end end
context 'when blocked_by relation is used' do
let(:params) do
{ issuable_references: [issue_a_ref], link_type: 'is_blocked_by' }
end
it 'creates creates `blocks` relation with swapped source and target' do
expect { subject }.to change(IssueLink, :count).from(0).to(1)
expect(IssueLink.find_by!(source: issue_a)).to have_attributes(target: issue, link_type: 'blocks')
end
end
end end
context 'when reference of any already related issue is present' do context 'when reference of any already related issue is present' do
...@@ -69,7 +81,7 @@ RSpec.describe IssueLinks::CreateService do ...@@ -69,7 +81,7 @@ RSpec.describe IssueLinks::CreateService do
before do before do
create :issue_link, source: issue, target: issue_b, link_type: IssueLink::TYPE_RELATES_TO create :issue_link, source: issue, target: issue_b, link_type: IssueLink::TYPE_RELATES_TO
create :issue_link, source: issue, target: issue_c, link_type: IssueLink::TYPE_IS_BLOCKED_BY create :issue_link, source: issue, target: issue_c, link_type: IssueLink::TYPE_BLOCKS
end end
let(:params) do let(:params) do
...@@ -79,7 +91,7 @@ RSpec.describe IssueLinks::CreateService do ...@@ -79,7 +91,7 @@ RSpec.describe IssueLinks::CreateService do
issue_b.to_reference, issue_b.to_reference,
issue_c.to_reference issue_c.to_reference
], ],
link_type: IssueLink::TYPE_IS_BLOCKED_BY link_type: IssueLink::TYPE_BLOCKS
} }
end end
...@@ -87,7 +99,7 @@ RSpec.describe IssueLinks::CreateService do ...@@ -87,7 +99,7 @@ RSpec.describe IssueLinks::CreateService do
expect(subject).to eq(status: :success) expect(subject).to eq(status: :success)
expect(IssueLink.where(target: [issue_a, issue_b, issue_c]).pluck(:link_type)) expect(IssueLink.where(target: [issue_a, issue_b, issue_c]).pluck(:link_type))
.to eq([IssueLink::TYPE_IS_BLOCKED_BY, IssueLink::TYPE_IS_BLOCKED_BY, IssueLink::TYPE_IS_BLOCKED_BY]) .to eq([IssueLink::TYPE_BLOCKS, IssueLink::TYPE_BLOCKS, IssueLink::TYPE_BLOCKS])
end end
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