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
c2d4060f
Commit
c2d4060f
authored
Feb 24, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite references in notes when moving issue
parent
8d3f072e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
17 deletions
+49
-17
app/services/issues/move_service.rb
app/services/issues/move_service.rb
+7
-2
spec/services/issues/move_service_spec.rb
spec/services/issues/move_service_spec.rb
+42
-15
No files found.
app/services/issues/move_service.rb
View file @
c2d4060f
...
@@ -57,7 +57,10 @@ module Issues
...
@@ -57,7 +57,10 @@ module Issues
def
rewrite_notes
def
rewrite_notes
@issue_old
.
notes
.
find_each
do
|
note
|
@issue_old
.
notes
.
find_each
do
|
note
|
new_note
=
note
.
dup
new_note
=
note
.
dup
new_note
.
update
(
project:
@project_new
,
noteable:
@issue_new
)
new_params
=
{
project:
@project_new
,
noteable:
@issue_new
,
note:
rewrite_references
(
new_note
)
}
new_note
.
update
(
new_params
)
end
end
end
end
...
@@ -79,8 +82,10 @@ module Issues
...
@@ -79,8 +82,10 @@ module Issues
def
rewrite_references
(
mentionable
)
def
rewrite_references
(
mentionable
)
references
=
mentionable
.
all_references
references
=
mentionable
.
all_references
new_content
=
mentionable_content
(
mentionable
).
dup
new_content
=
mentionable_content
(
mentionable
).
dup
cross_project_refs
=
[
:issues
,
:merge_requests
,
:milestones
,
:snippets
,
:commits
,
:commit_ranges
]
[
:issues
,
:merge_requests
,
:milestones
]
.
each
do
|
type
|
cross_project_refs
.
each
do
|
type
|
references
.
public_send
(
type
).
each
do
|
mentioned
|
references
.
public_send
(
type
).
each
do
|
mentioned
|
new_content
.
gsub!
(
mentioned
.
to_reference
,
new_content
.
gsub!
(
mentioned
.
to_reference
,
mentioned
.
to_reference
(
@project_new
))
mentioned
.
to_reference
(
@project_new
))
...
...
spec/services/issues/move_service_spec.rb
View file @
c2d4060f
...
@@ -94,27 +94,54 @@ describe Issues::MoveService, services: true do
...
@@ -94,27 +94,54 @@ describe Issues::MoveService, services: true do
end
end
context
'issue with notes'
do
context
'issue with notes'
do
let
(
:note_contents
)
do
context
'notes without references'
do
[
'Some system note 1'
,
'Some comment'
,
'Some system note 2'
]
let
(
:notes_params
)
do
end
[{
system:
false
,
note:
'Some comment 1'
},
{
system:
true
,
note:
'Some system note'
},
{
system:
false
,
note:
'Some comment 2'
}]
end
before
do
before
do
note_params
=
{
noteable:
old_issue
,
project:
old_project
,
author:
use
r
}
note_params
=
{
noteable:
old_issue
,
project:
old_project
,
author:
autho
r
}
create
(
:system_note
,
note_params
.
merge
(
note:
note_contents
.
first
))
notes_params
.
each
do
|
note
|
create
(
:note
,
note_params
.
merge
(
note:
note_contents
.
second
))
create
(
:note
,
note_params
.
merge
(
note
))
create
(
:system_note
,
note_params
.
merge
(
note:
note_contents
.
third
))
end
end
end
include_context
'issue move executed'
include_context
'issue move executed'
let
(
:new_notes
)
{
new_issue
.
notes
.
order
(
'id ASC'
).
pluck
(
:note
)
}
let
(
:all_notes
)
{
new_issue
.
notes
.
order
(
'id ASC'
)
}
let
(
:system_notes
)
{
all_notes
.
system
}
let
(
:user_notes
)
{
all_notes
.
user
}
it
'rewrites existing notes in valid order'
do
expect
(
all_notes
.
pluck
(
:note
).
first
(
3
))
.
to
eq
notes_params
.
map
{
|
n
|
n
[
:note
]
}
end
it
'rewrites existing system notes in valid order'
do
it
'adds a system note about move after rewritten notes'
do
expect
(
new_notes
.
first
(
3
)).
to
eq
note_contents
expect
(
system_notes
.
last
.
note
).
to
match
/^Moved from/
end
it
'preserves orignal author of comment'
do
expect
(
user_notes
.
pluck
(
:author_id
)).
to
all
(
eq
(
author
.
id
))
end
end
end
it
'adds a system note about move after rewritten notes'
do
context
'notes with references'
do
expect
(
new_notes
.
last
).
to
match
/^Moved from/
before
do
create
(
:merge_request
,
source_project:
old_project
)
create
(
:note
,
noteable:
old_issue
,
project:
old_project
,
author:
author
,
note:
'Note with reference to merge request !1'
)
end
include_context
'issue move executed'
let
(
:new_note
)
{
new_issue
.
notes
.
first
}
it
'rewrites references using a cross reference to old project'
do
expect
(
new_note
.
note
)
.
to
eq
"Note with reference to merge request
#{
old_project
.
to_reference
}
!1"
end
end
end
end
end
...
...
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