Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
a23f0e8c
Commit
a23f0e8c
authored
Mar 15, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reuse existing issue services when moving issue
parent
93812f25
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
52 deletions
+26
-52
app/services/issues/close_service.rb
app/services/issues/close_service.rb
+3
-3
app/services/issues/create_service.rb
app/services/issues/create_service.rb
+2
-2
app/services/issues/move_service.rb
app/services/issues/move_service.rb
+20
-38
app/services/notification_service.rb
app/services/notification_service.rb
+0
-8
spec/services/issues/move_service_spec.rb
spec/services/issues/move_service_spec.rb
+1
-1
No files found.
app/services/issues/close_service.rb
View file @
a23f0e8c
module
Issues
module
Issues
class
CloseService
<
Issues
::
BaseService
class
CloseService
<
Issues
::
BaseService
def
execute
(
issue
,
commit
=
nil
)
def
execute
(
issue
,
commit
=
nil
,
notifications:
true
,
system_note:
true
)
if
project
.
jira_tracker?
&&
project
.
jira_service
.
active
if
project
.
jira_tracker?
&&
project
.
jira_service
.
active
project
.
jira_service
.
execute
(
commit
,
issue
)
project
.
jira_service
.
execute
(
commit
,
issue
)
todo_service
.
close_issue
(
issue
,
current_user
)
todo_service
.
close_issue
(
issue
,
current_user
)
...
@@ -9,8 +9,8 @@ module Issues
...
@@ -9,8 +9,8 @@ module Issues
if
project
.
default_issues_tracker?
&&
issue
.
close
if
project
.
default_issues_tracker?
&&
issue
.
close
event_service
.
close_issue
(
issue
,
current_user
)
event_service
.
close_issue
(
issue
,
current_user
)
create_note
(
issue
,
commit
)
create_note
(
issue
,
commit
)
if
system_note
notification_service
.
close_issue
(
issue
,
current_user
)
notification_service
.
close_issue
(
issue
,
current_user
)
if
notifications
todo_service
.
close_issue
(
issue
,
current_user
)
todo_service
.
close_issue
(
issue
,
current_user
)
execute_hooks
(
issue
,
'close'
)
execute_hooks
(
issue
,
'close'
)
end
end
...
...
app/services/issues/create_service.rb
View file @
a23f0e8c
module
Issues
module
Issues
class
CreateService
<
Issues
::
BaseService
class
CreateService
<
Issues
::
BaseService
def
execute
def
execute
(
set_author:
true
)
filter_params
filter_params
label_params
=
params
[
:label_ids
]
label_params
=
params
[
:label_ids
]
issue
=
project
.
issues
.
new
(
params
.
except
(
:label_ids
))
issue
=
project
.
issues
.
new
(
params
.
except
(
:label_ids
))
issue
.
author
=
current_user
issue
.
author
=
current_user
if
set_author
if
issue
.
save
if
issue
.
save
issue
.
update_attributes
(
label_ids:
label_params
)
issue
.
update_attributes
(
label_ids:
label_params
)
...
...
app/services/issues/move_service.rb
View file @
a23f0e8c
...
@@ -4,14 +4,20 @@ module Issues
...
@@ -4,14 +4,20 @@ module Issues
super
(
project
,
current_user
,
params
)
super
(
project
,
current_user
,
params
)
@issue_old
=
issue
@issue_old
=
issue
@issue_new
=
issue
.
dup
@issue_new
=
nil
@project_old
=
@project
@project_old
=
@project
if
new_project_id
@project_new
=
Project
.
find
(
new_project_id
)
@project_new
=
Project
.
find
(
new_project_id
)
end
end
end
def
execute
def
execute
return
unless
move?
return
unless
move?
# Using trasaction because of a high footprint on
# rewriting notes (unfolding references)
#
ActiveRecord
::
Base
.
transaction
do
ActiveRecord
::
Base
.
transaction
do
# New issue tasks
# New issue tasks
#
#
...
@@ -25,10 +31,7 @@ module Issues
...
@@ -25,10 +31,7 @@ module Issues
close_old_issue
close_old_issue
end
end
# Notifications and hooks
notify_participants
#
# notify_participants
# trigger_hooks_and_events
@issue_new
@issue_new
end
end
...
@@ -45,20 +48,14 @@ module Issues
...
@@ -45,20 +48,14 @@ module Issues
end
end
def
create_new_issue
def
create_new_issue
@issue_new
.
project
=
@project_new
new_params
=
{
id:
nil
,
iid:
nil
,
milestone:
nil
,
label_ids:
[],
project:
@project_new
,
author:
@issue_old
.
author
,
# Reset internal ID, will be regenerated before save
description:
rewrite_references
(
@issue_old
)
}
#
@issue_new
.
iid
=
nil
# Reset labels and milestones, as those are not valid in context
create_service
=
CreateService
.
new
(
@project_new
,
@current_user
,
# of a new project
params
.
merge
(
new_params
))
#
@issue_new
.
labels
=
[]
@issue_new
.
milestone
=
nil
@issue_new
.
description
=
rewrite_references
(
@issue_old
)
@issue_new
=
create_service
.
execute
(
set_author:
false
)
@issue_new
.
save!
end
end
def
rewrite_notes
def
rewrite_notes
...
@@ -72,7 +69,8 @@ module Issues
...
@@ -72,7 +69,8 @@ module Issues
end
end
def
close_old_issue
def
close_old_issue
@issue_old
.
update
(
state: :closed
)
close_service
=
CloseService
.
new
(
@project_new
,
@current_user
)
close_service
.
execute
(
@issue_old
,
notifications:
false
,
system_note:
false
)
end
end
def
add_moved_from_note
def
add_moved_from_note
...
@@ -93,30 +91,14 @@ module Issues
...
@@ -93,30 +91,14 @@ module Issues
def
noteable_content
(
noteable
)
def
noteable_content
(
noteable
)
case
noteable
case
noteable
when
Issue
when
Issue
then
noteable
.
description
noteable
.
description
when
Note
then
noteable
.
note
when
Note
noteable
.
note
else
else
raise
'Unexpected noteable while moving an issue'
raise
'Unexpected noteable while moving an issue!'
end
end
end
def
trigger_hooks_and_events
event_service
.
close_issue
(
@issue_old
,
@current_user
)
event_service
.
open_issue
(
@issue_new
,
@current_user
)
@issue_new
.
create_cross_references!
(
@current_user
)
execute_hooks
(
@issue_old
,
'close'
)
execute_hooks
(
@issue_new
,
'open'
)
end
end
def
notify_participants
def
notify_participants
todo_service
.
close_issue
(
@issue_old
,
@current_user
)
todo_service
.
open_issue
(
@issue_new
,
@current_user
)
notification_service
.
issue_moved
(
@issue_old
,
@issue_new
,
@current_user
)
end
end
end
end
end
end
app/services/notification_service.rb
View file @
a23f0e8c
...
@@ -236,14 +236,6 @@ class NotificationService
...
@@ -236,14 +236,6 @@ class NotificationService
end
end
end
end
def
issue_moved
(
issue
,
old_project
,
new_project
,
current_user
)
recipients
=
build_recipients
(
issue
,
old_project
,
current_user
)
recipients
.
each
do
|
recipient
|
mailer
.
send
(
'issue_moved'
,
recipient
.
id
,
issue
.
id
,
current_user
.
id
).
deliver_later
end
end
protected
protected
# Get project users with WATCH notification level
# Get project users with WATCH notification level
...
...
spec/services/issues/move_service_spec.rb
View file @
a23f0e8c
...
@@ -76,7 +76,7 @@ describe Issues::MoveService, services: true do
...
@@ -76,7 +76,7 @@ describe Issues::MoveService, services: true do
it
'persists all changes'
do
it
'persists all changes'
do
expect
(
old_issue
.
changed?
).
to
be
false
expect
(
old_issue
.
changed?
).
to
be
false
expect
(
new_issue
.
persisted?
).
to
be
tru
e
expect
(
new_issue
.
changed?
).
to
be
fals
e
end
end
it
'preserves author'
do
it
'preserves author'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment