Commit 46d22192 authored by Alexandru Croitor's avatar Alexandru Croitor

Create close issue event on issue move

When an issue is moved to a different project we create a
copy of current issue and close current issue. We need to also
create a close issue resource event so that that issue being
closed is also reflected in burndown/burnup charts that rely
on resource state events.

Changelog: fixed
EE: true
parent d2580206
...@@ -66,7 +66,7 @@ module Issuable ...@@ -66,7 +66,7 @@ module Issuable
def close_issue def close_issue
close_service = Issues::CloseService.new(project: old_project, current_user: current_user) close_service = Issues::CloseService.new(project: old_project, current_user: current_user)
close_service.execute(original_entity, notifications: false, system_note: false) close_service.execute(original_entity, notifications: false, system_note: true)
end end
def new_parent def new_parent
......
...@@ -48,6 +48,10 @@ RSpec.describe 'Setting the epic of an issue' do ...@@ -48,6 +48,10 @@ RSpec.describe 'Setting the epic of an issue' do
before do before do
stub_licensed_features(epics: true) stub_licensed_features(epics: true)
# todo: investigate too many qeuries issue as part of Project Management Database and Query Performance
# epic: https://gitlab.com/groups/gitlab-org/-/epics/5804
# specific issue: https://gitlab.com/gitlab-org/gitlab/-/issues/333845
stub_const('Gitlab::QueryLimiting::Transaction::THRESHOLD', 110)
end end
it 'returns an error if the user is not allowed to update the issue' do it 'returns an error if the user is not allowed to update the issue' do
...@@ -95,7 +99,7 @@ RSpec.describe 'Setting the epic of an issue' do ...@@ -95,7 +99,7 @@ RSpec.describe 'Setting the epic of an issue' do
new_epic_group.add_developer(current_user) new_epic_group.add_developer(current_user)
end end
it 'promotes the issue to epic', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/333845' do it 'promotes the issue to epic' do
post_graphql_mutation(mutation, current_user: current_user) post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success) expect(response).to have_gitlab_http_status(:success)
......
...@@ -137,6 +137,15 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do ...@@ -137,6 +137,15 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
expect { subject.execute(issue) }.not_to raise_error expect { subject.execute(issue) }.not_to raise_error
end end
it 'creates a close state event for promoted issue' do
# promote issue to epic also copies over existing issue state resource events to the epic
# so in this case we have an existing resource event defined above and one that we create
# for issue close event, which we are not copying over
expect { subject.execute(issue) }.to change(ResourceStateEvent, :count).by(2).and(
change(ResourceStateEvent.where(issue_id: issue), :count).by(1)
)
end
it 'promotes issue successfully' do it 'promotes issue successfully' do
epic = subject.execute(issue) epic = subject.execute(issue)
......
...@@ -38,6 +38,10 @@ RSpec.describe Issues::MoveService do ...@@ -38,6 +38,10 @@ RSpec.describe Issues::MoveService do
context 'issue movable' do context 'issue movable' do
include_context 'user can move issue' include_context 'user can move issue'
it 'creates resource state event' do
expect { move_service.execute(old_issue, new_project) }.to change(ResourceStateEvent.where(issue_id: old_issue), :count).by(1)
end
context 'generic issue' do context 'generic issue' do
include_context 'issue move executed' include_context 'issue move executed'
...@@ -87,6 +91,10 @@ RSpec.describe Issues::MoveService do ...@@ -87,6 +91,10 @@ RSpec.describe Issues::MoveService do
expect(old_issue.moved_to).to eq new_issue expect(old_issue.moved_to).to eq new_issue
end end
it 'marks issue as closed' do
expect(old_issue.closed?).to eq true
end
it 'preserves create time' do it 'preserves create time' do
expect(old_issue.created_at).to eq new_issue.created_at expect(old_issue.created_at).to eq new_issue.created_at
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