Commit 70dfb37e authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '10270-milestones-should-not-be-set-on-epics-issue-promotion' into 'master'

Resolve "Milestones should not be set on epics (issue promotion)"

Closes #10270

See merge request gitlab-org/gitlab-ee!14532
parents 21bab0e2 9728d2b2
...@@ -427,6 +427,13 @@ module Issuable ...@@ -427,6 +427,13 @@ module Issuable
def wipless_title_changed(old_title) def wipless_title_changed(old_title)
old_title != title old_title != title
end end
##
# Overridden on EE module
#
def supports_milestone?
respond_to?(:milestone_id)
end
end end
Issuable.prepend(EE::Issuable) # rubocop: disable Cop/InjectEnterpriseEditionModule Issuable.prepend(EE::Issuable) # rubocop: disable Cop/InjectEnterpriseEditionModule
......
...@@ -17,6 +17,8 @@ module Issuable ...@@ -17,6 +17,8 @@ module Issuable
private private
def cloneable_milestone def cloneable_milestone
return unless new_entity.supports_milestone?
title = original_entity.milestone&.title title = original_entity.milestone&.title
return unless title return unless title
......
...@@ -25,6 +25,11 @@ module EE ...@@ -25,6 +25,11 @@ module EE
super super
end end
override :supports_milestone?
def supports_milestone?
super && !is_a?(Epic)
end
def supports_epic? def supports_epic?
is_a?(Issue) && project.group is_a?(Issue) && project.group
end end
......
---
title: Do not include milestone attribute when promoting issue to epic
merge_request: 14532
author:
type: fixed
...@@ -37,4 +37,17 @@ describe EE::Issuable do ...@@ -37,4 +37,17 @@ describe EE::Issuable do
end end
end end
end end
describe '#supports_milestone?' do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
context "for epics" do
let(:epic) { build(:epic) }
it 'returns false' do
expect(epic.supports_milestone?).to be_falsy
end
end
end
end end
...@@ -9,33 +9,35 @@ describe Issuable::Clone::AttributesRewriter do ...@@ -9,33 +9,35 @@ describe Issuable::Clone::AttributesRewriter do
let(:original_issue) { create(:issue, project: project) } let(:original_issue) { create(:issue, project: project) }
context 'when a new object is a group entity' do context 'when a new object is a group entity' do
let(:new_epic) { create(:epic, group: group) } context 'when entity is an epic' do
let(:new_epic) { create(:epic, group: group) }
subject { described_class.new(user, original_issue, new_epic) } subject { described_class.new(user, original_issue, new_epic) }
context 'setting labels' do context 'setting labels' do
let!(:project_label1) { create(:label, title: 'label1', project: project) } let(:project_label1) { create(:label, title: 'label1', project: project) }
let!(:project_label2) { create(:label, title: 'label2', project: project) } let!(:project_label2) { create(:label, title: 'label2', project: project) }
let!(:group_label1) { create(:group_label, title: 'group_label', group: group) } let(:group_label1) { create(:group_label, title: 'group_label', group: group) }
let!(:group_label2) { create(:group_label, title: 'label2', group: group) } let!(:group_label2) { create(:group_label, title: 'label2', group: group) }
it 'keeps group labels and merges project labels where possible' do it 'keeps group labels and merges project labels where possible' do
original_issue.update(labels: [project_label1, project_label2, group_label1]) original_issue.update(labels: [project_label1, project_label2, group_label1])
subject.execute subject.execute
expect(new_epic.reload.labels).to match_array([group_label1, group_label2]) expect(new_epic.reload.labels).to match_array([group_label1, group_label2])
end
end end
end
context 'setting milestones' do context 'setting milestones' do
it 'sets milestone to nil when old issue milestone is not a group milestone' do it 'sets milestone attribute as nil' do
milestone = create(:milestone, title: 'milestone', project: project) milestone = create(:milestone, title: 'milestone', group: group)
original_issue.update(milestone: milestone) original_issue.update(milestone: milestone)
subject.execute expect(new_epic).to receive(:update).with(labels: [], milestone: nil)
expect(new_epic.reload.milestone).to be_nil subject.execute
end
end end
end end
end end
......
...@@ -774,4 +774,25 @@ describe Issuable do ...@@ -774,4 +774,25 @@ describe Issuable do
end end
end end
end end
describe '#supports_milestone?' do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
context "for issues" do
let(:issue) { build(:issue, project: project) }
it 'returns true' do
expect(issue.supports_milestone?).to be_truthy
end
end
context "for merge requests" do
let(:merge_request) { build(:merge_request, target_project: project, source_project: project) }
it 'returns true' do
expect(merge_request.supports_milestone?).to be_truthy
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